Histogram BottomAxis issue

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 BottomAxis issue

Post by RSpence » Fri Mar 18, 2005 2:29 am

Hi,

Another one for you guys. I have two charts in a panel - one aligned alTop, the othe alClient. The top chart is a histogram, the bottom chart a box plot. Two different views of the same data. I want the bottom Axis on the bottom chart - the box plot - to be the same as the bottom axis on the top chart - the histogram.

For the top chart, I leave all the axis things automatic, so T-Chart generates the min, max etc for me. If I leave the bottom chart Axis on automatic, because it is a box plot, the values are slightly different - in this case just the maximum value. So I try to set the bottom axis in code.

I have this:

// chrtBoxPlot is the bottom chart, chrtFreq the top one
With ChrtBoxPlot Do
begin
BottomAxis.AutomaticMaximum := false;
BottomAxis.AutomaticMinimum := false;
BottomAxis.Maximum := self.chrtFrequency.BottomAxis.Maximum;
BottomAxis.Minimum := self.chrtFrequency.BottomAxis.Minimum;

It almost works, except, the maximum value returned by the histogram appears to be the start position of the last bin. This is noticable if each bin takes 50 pixels or so - if each bin is say 5 pixles the error is still there, but you can't see it as easily.

Is this an error? I am trying to work around it by adding onto the maximum the width of a bin - which I thought would be given by:

BottomAxis.Maximum := self.chrtFrequency.BottomAxis.Maximum +
self.chrtFrequency.BottomAxis.Increment;

but in this case bottomAxis.increment is 0 - probably because I set it to auto. How can I determine the width of a histogram bin? Or is there an easier way to do what I am trying to do?

Regards,

Rick

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

Post by Pep » Fri Mar 18, 2005 12:05 pm

Hi Rick,

to do this you can use the following code :

Code: Select all

Chart2.Axes.Bottom.SetMinMax(Chart1.Axes.Bottom.Minimum,Chart1.Axes.bottom.Maximum);
Chart2.Axes.Bottom.Increment := Chart1.Axes.Bottom.Increment;
Chart2.Axes.Bottom.MinimumOffset := 50;
Chart2.Axes.Bottom.MaximumOffset := 50;

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

Post by RSpence » Fri Mar 18, 2005 4:41 pm

Hi Pep,

This doesn't work, I;'m afraid. In the example I just tried it on, the histogram bottom axies goes from 0 to 835, let's say, but when the code at the top graphcs bottom axis maximum it is 758. This top chat is the histogram - it appears to return the maximum as the start of the last bin.

Also, increment is always zero. Shall I post a sample project to look at?

Regards,

Rick

SteveP
Advanced
Posts: 132
Joined: Sun Sep 07, 2003 4:00 am

Post by SteveP » Fri Mar 18, 2005 5:18 pm

Perhaps try making sure the chart's properties have really been set before accessing them. Try Chart1.Update before setting any of the chart2 bottom axis properties (which are based on chart1). Or try chart2.update after each setting of its properties.

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

Post by RSpence » Fri Mar 18, 2005 10:49 pm

Hi,

I've narrowed this down. It appears that witha histogram, the bottomAxis.maximum always returns the value of last bin, not the highest value on the axis. Self contained code below shows this, I think:

self.SeriesHist.Clear;
self.chrtHistogram.BottomAxis.Automatic := false;
self.chrtHistogram.BottomAxis.AutomaticMinimum := false;
self.chrtHistogram.BottomAxis.Minimum := 0;

self.chrHistogram.BottomAxis.AutomaticMaximum := true;

self.SeriesHist.AddXY(10, 1);
self.SeriesHist.AddXY(20, 1);
self.SeriesHist.AddXY(30, 1);
self.SeriesHist.AddXY(40, 1);
self.SeriesHist.AddXY(43, 1);

self.chrHistogram.update;
// It draws the bottom axis from 0 to 47
// but bottomAxis.maximum always returns 43 - the value of the hightest bin

showMessage( FloatToStr(self.chrHistogram.BottomAxis.Maximum)); // Always 43
ShowMessage( FloatToStr(self.chrHistogram.BottomAxis.Increment )); // Always 0

So what to do? Let me know if u want a project, but the above is all you need.

Regards,

Rick

Post Reply