HistoGram Bin Width

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
RSpence
Newbie
Newbie
Posts: 33
Joined: Fri Apr 02, 2004 5:00 am
Location: UK / Florida
Contact:

HistoGram Bin Width

Post by RSpence » Thu Mar 31, 2005 12:59 am

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;

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Mar 31, 2005 8:42 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

RSpence
Newbie
Newbie
Posts: 33
Joined: Fri Apr 02, 2004 5:00 am
Location: UK / Florida
Contact:

Post by RSpence » Thu Mar 31, 2005 3:54 pm

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

RSpence
Newbie
Newbie
Posts: 33
Joined: Fri Apr 02, 2004 5:00 am
Location: UK / Florida
Contact:

Post by RSpence » Thu Mar 31, 2005 6:48 pm

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

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Tue Apr 12, 2005 8:48 am

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.
Marjan Slatinek,
http://www.steema.com

RSpence
Newbie
Newbie
Posts: 33
Joined: Fri Apr 02, 2004 5:00 am
Location: UK / Florida
Contact:

Post by RSpence » Tue Apr 12, 2005 3:29 pm

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

Post Reply