TBarSeries and single X-Values

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
nisbus
Newbie
Newbie
Posts: 18
Joined: Wed Jan 18, 2006 12:00 am
Location: Iceland
Contact:

TBarSeries and single X-Values

Post by nisbus » Fri Apr 27, 2007 10:58 am

Hi,

I have a chart that has multiple bars and they all have the same date as the X-Value.

First I noticed that as I add more bars on that date they seem to group together in the middle of the chart and a lot of space is wasted.
I then found the SideMargins property of TBarSeries and set it to false on all bar series.
This kind of fixes the problem although when the bars are 10 or more there still seems to be a margin on the chart (max and min of the X-Axis are both set to the same date though).
What I would like to do is spread the bars out over the chart (with a small space in between) but this of course should only happen if there are single value bars on the chart and I don't want any margins.

How would I do that?

Pep
Site Admin
Site Admin
Posts: 3277
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Fri Apr 27, 2007 3:43 pm

Hi,

one way I can think of could be to use custom axis labels to show the DateTime values in the axis, setting the Series as "SideAll", something like the following code :

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i : integer;
begin
  Chart1.View3D:=false;
  // Add Series Values
  Series1.Add(10);
  Series2.Add(15);
  Series3.Add(20);

  Series1.MultiBar:=mbSideAll;

  // Add custom axis labels
  Chart1.axes.bottom.items.clear;
  for i := 0 to Chart1.SeriesCount - 1 do
    chart1.axes.bottom.items.add(i,'01/01/2007'); // Datetime as string
end;

nisbus
Newbie
Newbie
Posts: 18
Joined: Wed Jan 18, 2006 12:00 am
Location: Iceland
Contact:

Post by nisbus » Fri Apr 27, 2007 5:10 pm

I figured out another way to do it:

Code: Select all

  for i := 0 to Chart.DBChart1.SeriesCount -1 do
  begin
    //If any series has more than one date value
    if Chart.DBChart1[i].ClassName = 'THorizBarSeries' then
    begin
      if Chart.DBChart1[i].YValues.Count > 1 then
      begin
        SingleValue := False;
        THorizBarSeries(Chart.DBChart1[i]).BarWidthPercent := 70;
      end
      else
        THorizBarSeries(Chart.DBChart1[i]).BarWidthPercent := 100;
    end
    else if Chart.DBChart1[i].ClassName = 'TBarSeries' then
      if Chart.DBChart1[i].XValues.Count > 1 then
      begin
        SingleValue := False;
        TBarSeries(Chart.DBChart1[i]).BarWidthPercent := 70;
      end
      else
        TBarSeries(Chart.DBChart1[i]).BarWidthPercent := 100;
    else
      SingleValue := False;//In case of TLineSeries
  end;
  if SingleValue then
    Chart.DBChart1.MaxPointsPerPage := 1
  else
    Chart.DBChart1.MaxPointsPerPage := 0;  
This works so that the series utilize all of the chart but I still haven't found any way to separate the bars. I don't want to have a label on every bar since it's alway the same date. This solution doesn't display any date but that might be fixed with your custom label solution.


thanks,
nisbus

Pep
Site Admin
Site Admin
Posts: 3277
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Mon Apr 30, 2007 10:18 am

Hi,
This works so that the series utilize all of the chart but I still haven't found any way to separate the bars.
In that case there's an example which could help to accomplish that, it's in the Demo features project (included into the Teechart Pro installation) under :
All Features -> Welcme ! -> Chart Styles -> Standard -> Bar -> Bar Size Example
Could you please check it ?
I don't want to have a label on every bar since it's alway the same date. This solution doesn't display any date but that might be fixed with your custom label solution.
Yes, should be the trick.

Post Reply