Page 1 of 1

TBarSeries with "double" values

Posted: Fri Apr 11, 2014 12:52 pm
by 16868859
We are using the TeeChartStandard2014 package.

I have a TBarSeries with some "double" values. I use this sample code:

Code: Select all

var
  i, j: Integer;
  tmpDates: array of TDateTime;
  doADoubleValue: Boolean;

   doADoubleValue := False;

   setLength(tmpDates, 2);

   for i:=0 to High(tmpDates) do
    if i mod 2 = 0 then
     tmpDates[i]:=IncDay(Today, i*2)
    else
     tmpDates[i]:=IncDay(Today, (i*2)+1);

    for i:=0 to 1 do
      with frmChart.ChartAccounting.AddSeries(TBarSeries) as TBarSeries do
       begin
        //MultiBar:=mbStacked;
        MarksOnBar:=False;
        MarksLocation:=mlCenter;
        CustomBarWidth:=40;

        XValues.DateTime:=true;

        for j:=0 to High(tmpDates) do
         begin
          if j mod 2 = 0 then
           begin
            AddXY(tmpDates[j]+i, 25+random*75, 'S' + inttoStr(i) + ' L' + IntToStr(j));
           end
          else
           begin
            AddXY(tmpDates[j], 25+random*75, 'S' + inttoStr(i) + ' L' + IntToStr(j));

            if not doADoubleValue then
             begin
              AddXY(tmpDates[j], 15+random*75, 'test - S' + inttoStr(i) + ' L' + IntToStr(j));
              doADoubleValue := True;
            end;            
          end;
        end;
      end;
I looks like this:
test.jpg
test.jpg (38.55 KiB) Viewed 5451 times
So the bars with the same values are "overlayed". The same with "mbStacked".

Any idea how to fix this?

Best Regards,

Kai

Re: TBarSeries with "double" values

Posted: Mon Apr 14, 2014 1:54 pm
by 16868859
I solved the problem with this solution:

Code: Select all

var
  i, j: Integer;
  tmpDates: array of TDateTime;
  doADoubleValue: Boolean;
  myColor: TColor;

   doADoubleValue := False;

   setLength(tmpDates, 2);

   for i:=0 to High(tmpDates) do
    if i mod 2 = 0 then
     tmpDates[i]:=IncDay(Today, i*2)
    else
     tmpDates[i]:=IncDay(Today, (i*2)+1);

    for i:=0 to 1 do
      with frmChart.ChartAccounting.AddSeries(TBarSeries) as TBarSeries do
       begin
        //MultiBar:=mbStacked;
        MarksOnBar:=False;
        MarksLocation:=mlCenter;
        CustomBarWidth:=40;

        XValues.DateTime:=true;

        myColor := Color;

        for j:=0 to High(tmpDates) do
         begin
          if j mod 2 = 0 then
           begin
            AddXY(tmpDates[j]+i, 25+random*75, 'S' + inttoStr(i) + ' L' + IntToStr(j));
           end
          else
           begin
            AddXY(tmpDates[j], 25+random*75, 'S' + inttoStr(i) + ' L' + IntToStr(j));

            if not doADoubleValue then
             begin
              with frmChart.ChartAccounting.AddSeries(TBarSeries) as TBarSeries do
              begin
               MultiBar:=mbStacked;
               MarksOnBar:=False;
               MarksLocation:=mlCenter;
               CustomBarWidth:=40;
               ShowInLegend := False;
               Color := myColor;

               AddXY(tmpDates[j], 15+random*75, 'test - S' + inttoStr(i) + ' L' + IntToStr(j), myColor);
              end;

              doADoubleValue := True;
            end;           
          end;
        end;
      end;
I create a "new" series with the color of the "current" one. Then it works.

Re: TBarSeries with "double" values

Posted: Mon Apr 14, 2014 1:57 pm
by yeray
Hello Kai,

With your code I get this, that is slightly different to your image:
2014-04-14_1547.png
2014-04-14_1547.png (16.51 KiB) Viewed 5397 times
So I guess you are also modifying the bottom axis, setting a bigger range, making the bars to be drawn more close to the other bars.

On the other hand, looking at the data I see you are adding two values at the same XValue in Series1:
data.png
data.png (2.79 KiB) Viewed 5403 times
Is that what you desired? If so, how would you expect the Bars to be drawn?

Re: TBarSeries with "double" values

Posted: Mon Apr 14, 2014 1:58 pm
by yeray
Hello,

I see you already found how to solve it. I'm glad to hear you found it! :)

Re: TBarSeries with "double" values

Posted: Mon Apr 14, 2014 2:07 pm
by 16868859
Hello Yeray,

we are posting at the same time :wink:
So I guess you are also modifying the bottom axis, setting a bigger range, making the bars to be drawn more close to the other bars.
Oh sorry ... i post only the code to add the bars.
On the other hand, looking at the data I see you are adding two values at the same XValue in Series1:
Is that what you desired?
Yes i have some values with the same XValue.

so the final looks like this:
screen.jpg
screen.jpg (17.43 KiB) Viewed 5392 times
So erverthing works fine. Thanx.