TBarSeries

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Horizon Behavioral Services
Newbie
Newbie
Posts: 3
Joined: Fri Nov 15, 2002 12:00 am

TBarSeries

Post by Horizon Behavioral Services » Fri Apr 23, 2004 3:07 pm

TDBTeeChart/ TBarSeries, under the condition when ALL of the bar VALUES in a series are set to ZERO, the chart displays the origin at the center of the left Y-Axis, with a line for each bar in the middle of the chart. How can I stop this behavior and make the zero bars display at the bottom of the chart (again this only happens when ALL of the bars are zero) as would be expected with the default origin set to zero, ie the bottom of the chart?

Thanks,
JT Taylor

Horizon Behavioral Services
Newbie
Newbie
Posts: 3
Joined: Fri Nov 15, 2002 12:00 am

Solution To TBarSeries ALL ZERO BARS Issue

Post by Horizon Behavioral Services » Fri Apr 23, 2004 4:10 pm

Well, I found my own solution. But I have not determined which event to tap into yet. Probably the OnPaint Event of the Chart to set these properties or in the OnGetData event of the datasource or something like that. Anyhow, this issue stems from the automatic axis settings. When all values are zero, you need to set the Automatic Axis to False and the Min and Max Auto settings to False and set the Min to Zero and the Max to some positive vaule such as 10 or whatever is reasonable for the dataset you are working with. Then the zero bars display at the bottom of the grid with zero height as expected.

Horizon Behavioral Services
Newbie
Newbie
Posts: 3
Joined: Fri Nov 15, 2002 12:00 am

Post by Horizon Behavioral Services » Tue Apr 27, 2004 1:32 pm

OnBeforeGenerate Event of the Report Builder Detail Band that contained the data-aware TeeChart component was the event to fire off my scale handling:

procedure Trpt_HBS0120.ppDetailBand5BeforeGenerate(Sender: TObject);
var
myVertAxis : TChartAxis;
minY, maxY: Double;
begin
inherited;
myVertAxis := ppDPTeeChart1.Chart[0].GetVertAxis;
minY := ppDPTeeChart1.Chart[0].MinYValue;
maxY := ppDPTeeChart1.Chart[0].MaxYValue;
AdjustScaleForAllZeroData(minY, maxY, myVertAxis);

myVertAxis := ppDPTeeChart1.Chart[1].GetVertAxis;
minY := ppDPTeeChart1.Chart[1].MinYValue;
maxY := ppDPTeeChart1.Chart[1].MaxYValue;
AdjustScaleForAllZeroData(minY, maxY, myVertAxis);
end;


procedure Trpt_HBS0120.AdjustScaleForAllZeroData(Min, Max : Double; VAxis : TChartAxis);
begin
if ((Min = 0) and (Max = 0)) then
begin
VAxis.Automatic := False;
VAxis.SetMinMax(0, 10);
end else
begin
VAxis.Automatic := True;
end;
end;

Post Reply