SeriesGroups / TBarSeries label issue

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
ingmar79
Newbie
Newbie
Posts: 1
Joined: Wed Aug 29, 2018 12:00 am

SeriesGroups / TBarSeries label issue

Post by ingmar79 » Mon Sep 24, 2018 11:59 am

Greetings,

we have an issue with SeriesGroups option. X bar (Axis.Bottom) date time labels are located quite randomly.
How could we adjust your code so that group dates would appear correctly (centred) under group bars?

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
bar: TBarSeries;
begin
  chart1.ClearChart;
  chart1.Legend.Hide;

  (chart1.SeriesGroups.Add as TSeriesGroup).Name:='A';
  (chart1.SeriesGroups.Add as TSeriesGroup).Name:='B';
  (chart1.SeriesGroups.Add as TSeriesGroup).Name:='C';
 //   chart1.BottomAxis.Automatic := false;
//    chart1.BottomAxis.SetMinMax(strtodate('21.05.2018')-3,strtodate('30.05.2018')+3);
    chart1.Axes.Bottom.LabelStyle :=  talPointValue;
//    chart1.Axes.Bottom.LabelsSeparation := 0;
    chart1.BottomAxis.DateTimeFormat := 'dd.mm.yyyy';

    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.AddXY(strtodate('21.05.2018'), 85, 'test1');
    chart1.SeriesGroups.Items[0].Add(bar);

    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.AddXY(strtodate('21.05.2018'), 19, 'test2');
    chart1.SeriesGroups.Items[0].Add(bar);

    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.AddXY(strtodate('21.05.2018'), 15, 'test3');
    chart1.SeriesGroups.Items[0].Add(bar);



    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.AddXY(strtodate('29.05.2018'), 151, 'test 4');
    chart1.SeriesGroups.Items[1].Add(bar);

    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.AddXY(strtodate('29.05.2018'), 195, 'test 5');
    chart1.SeriesGroups.Items[1].Add(bar);

    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.AddXY(strtodate('29.05.2018'), 101, 'test 6');
    chart1.SeriesGroups.Items[1].Add(bar);



    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.AddXY(strtodate('30.05.2018'), 11, 'test 7');
    chart1.SeriesGroups.Items[2].Add(bar);

    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.AddXY(strtodate('30.05.2018'), 105, 'test 8');
    chart1.SeriesGroups.Items[2].Add(bar);

    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.AddXY(strtodate('30.05.2018'), 21, 'test 9');
    chart1.SeriesGroups.Items[2].Add(bar);
end;
Attachments
chart1.png
chart1.png (34.81 KiB) Viewed 5705 times

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: SeriesGroups / TBarSeries label issue

Post by Yeray » Thu Sep 27, 2018 7:48 am

Hello,

Having 9 TBarSeries, the axis label is placed giving space for all the 9 bars. I've edited your screenshot, moving the bars from the right to the left so they are all together, and you can see how the label is placed correctly:
projection.png
projection.png (13.89 KiB) Viewed 5677 times
I would create as many series as bars you want to be placed at the same date. In this case I would create 3 bar series. Ie:

Code: Select all

  chart1.ClearChart;
  chart1.Legend.Hide;

  (chart1.SeriesGroups.Add as TSeriesGroup).Name:='A';
  (chart1.SeriesGroups.Add as TSeriesGroup).Name:='B';
  (chart1.SeriesGroups.Add as TSeriesGroup).Name:='C';
 //   chart1.BottomAxis.Automatic := false;
//    chart1.BottomAxis.SetMinMax(strtodate('21.05.2018')-3,strtodate('30.05.2018')+3);
    chart1.Axes.Bottom.LabelStyle :=  talPointValue;
//    chart1.Axes.Bottom.LabelsSeparation := 0;
    chart1.BottomAxis.DateTimeFormat := 'dd.mm.yyyy';

    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.AddXY(strtodate('21.05.2018'), 85, 'test1');
    bar.AddXY(strtodate('29.05.2018'), 151, 'test 4');
    bar.AddXY(strtodate('30.05.2018'), 11, 'test 7');
    chart1.SeriesGroups.Items[0].Add(bar);

    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.AddXY(strtodate('21.05.2018'), 19, 'test2');
    bar.AddXY(strtodate('29.05.2018'), 195, 'test 5');
    bar.AddXY(strtodate('30.05.2018'), 105, 'test 8');
    chart1.SeriesGroups.Items[0].Add(bar);

    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.AddXY(strtodate('21.05.2018'), 15, 'test3');
    bar.AddXY(strtodate('29.05.2018'), 101, 'test 6');
    bar.AddXY(strtodate('30.05.2018'), 21, 'test 9');
    chart1.SeriesGroups.Items[0].Add(bar);
Project3_2018-09-27_09-40-01.png
Project3_2018-09-27_09-40-01.png (25.95 KiB) Viewed 5677 times
Now the problem is the distance between the days 21 and 29 is very different to the distance between the days 29 and 30. The result is correct but the bars overlap.
I see two options to solve this:
- You could make the 3 bar series thinner:

Code: Select all

bar.BarWidthPercent:=20;
Project3_2018-09-27_09-43-21.png
Project3_2018-09-27_09-43-21.png (25.47 KiB) Viewed 5677 times
- You could fake the xvalues and use the dates for the labels:

Code: Select all

    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.Add(85, 'test1');
    bar.Add(151, 'test 4');
    bar.Add(11, 'test 7');
    chart1.SeriesGroups.Items[0].Add(bar);

    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.Add(19, 'test2');
    bar.Add(195, 'test 5');
    bar.Add(105, 'test 8');
    chart1.SeriesGroups.Items[0].Add(bar);

    bar := chart1.AddSeries(TBarSeries) as TBarSeries;
    bar.XValues.DateTime := true;
    bar.Add(15, 'test3');
    bar.Add(101, 'test 6');
    bar.Add(21, 'test 9');
    chart1.SeriesGroups.Items[0].Add(bar);

    with Chart1.Axes.Bottom.Items do
    begin
      Clear;
      Add(0, '21.05.2018');
      Add(1, '29.05.2018');
      Add(2, '30.05.2018');
    end;
Project3_2018-09-27_09-46-54.png
Project3_2018-09-27_09-46-54.png (28.6 KiB) Viewed 5677 times
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply