Page 1 of 1
HistoGram Bin Width
Posted: Thu Mar 31, 2005 12:59 am
by 9336985
Following code results in 2 bins of different widths. Shouldn't bins always be the same width? How to make them so?
Regards,
Rick
type
TForm1 = class(TForm)
Button1: TButton;
Chart1: TChart;
Series1: THistogramSeries;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
self.Series1.Clear;
self.Chart1.BottomAxis.AutomaticMinimum := false;
self.Chart1.BottomAxis.Minimum := 0;
self.Chart1.LeftAxis.AutomaticMinimum := false;
self.Series1.AddXY(100, 2);
self.Series1.AddXY(500, 4);
end;
Posted: Thu Mar 31, 2005 8:42 am
by narcis
Hi Rick,
Yes, the problem is in the axes settings. Using the code below works fine but the bins are different sized after scrolling the chart. If you uncomment the commented line then also works fine after scrolling.
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
self.Series1.Clear;
self.Chart1.LeftAxis.SetMinMax(0,6);
//self.Chart1.BottomAxis.SetMinMax(-100,700);
self.Series1.AddXY(100, 2);
self.Series1.AddXY(500, 4);
end;
Also notice that I've included this scrolling issue into our defect list to be fixed for future releases.
Posted: Thu Mar 31, 2005 3:54 pm
by 9336985
Hi Narcis,
In that specific case that does seem to fix the issue, but in the general case, there are still problems with the bin widths being different if I set the axis min / max myself. My goal is simple. I have two histograms showing different data, but I want the bottom axis scales to be the same to illustrate the differences between the two data sets. My code is:
self.framSampStatsGraphs.chrtFrequency.BottomAxis.SetMinMax(
self.framPopStatsGraphs.chrtFrequency.BottomAxis.Minimum,
self.framPopStatsGraphs.chrtFrequency.BottomAxis.Maximum);
self.framSampStatsGraphs.chrtFrequency.Update;
The frequency chart in the Pop (population) has already been draw, and it uses automatic. I want the Samp (sample) frequency chart to have the same bottom axis. I have scrolling and zooming turned off at design time.
Regards,
Rick
Posted: Thu Mar 31, 2005 6:48 pm
by 9336985
More Information on Histogram Bin Widths
The following code produces the first bin in series 1 as much wider thatn the other bins. Narcis' previous reply implied this had to do with scrolling -there is no scrolling or zooming on these charts.
There are two charts, and one histogram series in each chart. I'm really stuck on this.....
self.Chart2.LeftAxis.AutomaticMinimum := false;
self.Chart2.BottomAxis.AutomaticMinimum := false;
self.Series2.AddXY(10, 100);
self.Series2.AddXY(20, 200);
self.Series2.AddXY(30, 300);
self.Series2.AddXY(40, 400);
self.Series2.AddXY(50, 500);
self.Series2.AddXY(60, 600);
self.Chart2.Update;
self.Series1.Clear;
self.Chart1.LeftAxis.SetMinMax(0, 100);
self.Chart1.BottomAxis.SetMinMax( 0,
self.Chart2.BottomAxis.Maximum );
self.Series1.AddXY(1, 10);
self.Series1.AddXY(2, 20);
self.Series1.AddXY(3, 30);
self.Series1.AddXY(4, 40);
self.Series1.AddXY(5, 50);
self.Series1.AddXY(6, 60);
Regards,
Rick
Posted: Tue Apr 12, 2005 8:48 am
by Marjan
Hi, Rick.
Yes, I get the same results. It's a bug in histogram series drawing algorithm. To be more precise, histogram bin width is not calculated correctly. We'll log this to the bug list and try to improve/fix it for next maintenance release.
In the meantime the best workaround is to use the approach Narcis recomended.
Posted: Tue Apr 12, 2005 3:29 pm
by 9336985
Hi Marjan,
Narcis approach doesn't work either, I'm afraid. The solution is to replace the histogram with an area chart and do the maths ourselves...
Glad you've logged it.
Thanks,
Rick