Page 1 of 1
TBarSeries and single X-Values
Posted: Fri Apr 27, 2007 10:58 am
by 9345006
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?
Posted: Fri Apr 27, 2007 3:43 pm
by Pep
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;
Posted: Fri Apr 27, 2007 5:10 pm
by 9345006
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
Posted: Mon Apr 30, 2007 10:18 am
by Pep
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.