Page 1 of 1

[Bug]TDBCrossTabSource manipulates for 0 instead of NULL

Posted: Wed Mar 14, 2012 6:11 am
by 16561241
Hello

Image a following table be manipulated by TDBCrossTabSource:

//---- Table Data----------
Year |Region |Sales
2000 |East | 1000
2000 |West |1500
2001 |East |1200
2002 |East |1700
2002 |West |2300


//------ TDBCrossTabSource settings---------
Group on "Region" to sum the "sales" with Label on "Year"

The for the series for region "West", it will have a 0 value on year 2001 instead of a NULL value, which is wrong. Since region "west" has no data on "year" 2001, it should skip it, or adding a NULL value instead of a 0 value.

Please kindly review and correct it.

Re: [Bug]TDBCrossTabSource manipulates for 0 instead of NULL

Posted: Wed Mar 14, 2012 12:30 pm
by yeray
Hi,

This was addressed here in the past:
http://www.teechart.net/support/viewtop ... ll*#p42614

Re: [Bug]TDBCrossTabSource manipulates for 0 instead of NULL

Posted: Thu Mar 15, 2012 1:00 am
by 16561241
Hi

It is a different case.

In my case, there is no record at all for region west in year 2001 in dataset, not a 0, or a NULL value. But when use DBCrossTabSource, a 0 value is assigned, which make the display wrong.

So in my case, more accurately, when DBCrossTabSource manipulates value for series "west", it should skip year 2001, or calling AddNULL for year 2001, not like currently adding a 0 value for year 2001.

Actually after two days try, I managed to achieve it by modify TeeDBCrossTab.pas, starting line 305

Code: Select all

            if tmpPoint=-1 then
            begin
              tmpSeries.Add(tmpValue,tmpLabel,clTeeColor);

              with Series.ParentChart do
              for t:=0 to SeriesCount-1 do
              if tmpSeries<>Series[t] then
                 if tmpSeries.Count>Series[t].Count then
                    for tt:=1 to (tmpSeries.Count-Series[t].Count) do
                    begin
                       Series[t].Add(0,tmpLabel);
                    end;
            end
            else
            begin
              With tmpSeries.MandatoryValueList do
              case Formula of
                gfCount,
                gfSum: Value[tmpPoint]:=Value[tmpPoint]+tmpValue;
                end;
              end;
            end;

into

Code: Select all

            if tmpPoint=-1 then
            begin
              tmpSeries.Add(tmpValue,tmpLabel,clTeeColor);

              with Series.ParentChart do
              for t:=0 to SeriesCount-1 do
              if tmpSeries<>Series[t] then
                 if tmpSeries.Count>Series[t].Count then
                    for tt:=1 to (tmpSeries.Count-Series[t].Count) do
                    begin
                       Series[t].AddNull(TmpLabel); // Occupy it with a NULL value
                    end;
            end
            else
            begin
              With tmpSeries.MandatoryValueList do
              case Formula of
                gfCount,
                gfSum:begin
                  Value[tmpPoint]:=Value[tmpPoint]+tmpValue;
                  tmpSeries.ValueColor[tmpPoint]:=clTeeColor;//now this should be a valid value 
                end;
              end;
            end;

Re: [Bug]TDBCrossTabSource manipulates for 0 instead of NULL

Posted: Fri Mar 16, 2012 2:03 pm
by 16561241
Hello

line 284 should also be change as following in case the series "west" is the master series

Code: Select all

                  for t:=0 to Series.Count-1 do
                      tmpSeries.AddNULL(Series.Labels[t]);

Re: [Bug]TDBCrossTabSource manipulates for 0 instead of NULL

Posted: Fri Mar 16, 2012 3:02 pm
by yeray
Hi,

Thanks for sharing the proposal. I've added it to the wish list to be investigated for inclusion asap (TV52016090).