## THistogram series bottom axis cannot change axis increment

epidata
Newbie
Posts: 10
Joined: Wed Mar 31, 2004 5:00 am
Location: Denmark
Contact:

### THistogram series bottom axis cannot change axis increment

When drawing histograms to see a distribution, say count of age for a number of persons. The histogram will draw for each age a column at the value of that age. The axis will per default show as label the value of age.

Using Delphi 7 Pro and Teechart 7.07:
Values are added to a histogram by these lines (simplified here):

Code: Select all

``````function TGraph.HistogramSeries(DataVector, LabelVector; ColorFunc: TSeriesColorFunction): THistogramSeries;
var
i: integer;
begin
result := THistogramSeries.create(nil);
// Values are added like this:
for i := 1 to DataVector.Length do
end;``````
[/color]

The function correctly adds the value points, but the problem is that the axis in this form is not drawn nicely with regular intervals. The histogram demands as the labelvector a string, such that if we try to define a proper tick mark separation by calling a function with the desired tick mark distance (increment), then
.... call function with "Value", e.g. 5:

Code: Select all

``````    // Force calculation of min and max!
min := Axis.Minimum;
max := Axis.Maximum;
Axis.Automatic := false;
Axis.SetMinMax(Axis.Minimum, Axis.Maximum);      //
Axis.SetMinMax(Min, Max);      // Axis.SetMinMax(min, max);
Axis.Increment := Value;``````
[/color]

What happens then is that the bottom axis goes from 0 to number of bins, and with tick marks at 0 5 10 15 etc., whereas the data were e.g. 17, 19,22, 24 etc.

In short:
How can I draw a histogram where the bottom axis is considered numerical and not categorical. Keeping it numerical is essential for drawing the correct distance btw. points in the histogram.

Regards
JL/EpiData

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

You can achieve what you request using this:

Code: Select all

``  Chart1.Axes.Bottom.LabelStyle:=talValue;``
Best Regards,
 Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com Instructions - How to post in this forum

epidata
Newbie
Posts: 10
Joined: Wed Mar 31, 2004 5:00 am
Location: Denmark
Contact:

### Unfortunately not so - talvalue does not solve the problem

The "talValue" does not make it neither by setting this as:

Code: Select all

``````  Axis.Increment := Value;
Axis.LabelStyle := talValue;
``````
nor invoking the ChartEditor and in this change axis to 5 increment and Labelstyle to talValue. In both cases the axis will go from 0 to number of bins (within what fits divided by 5).

Try:
create an empty chart based on histogram. Enter as manual data source for a series the numbers:
# text Y
0 17 1
1 21 10
2 51 15
if you set for the bottom axis:
labelstyle=auto. The bottom axis shows 17 21 and 51
labelstyle=talvalue: the bottom axis tick marks are: 0 1 2

In contrast to when the series is defined as a point series. Then the min and max values from the bottom axis are by default the same values as the value at minimum (e.g.17), obviously because the point series has an X value defined.

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

Ok, I see you are adding the values you want in the bottom axis as text instead of X values. In that case you should try using:

Code: Select all

``  Chart1.Axes.Bottom.LabelStyle := talText;``
Best Regards,
 Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com Instructions - How to post in this forum

epidata
Newbie
Posts: 10
Joined: Wed Mar 31, 2004 5:00 am
Location: Denmark
Contact:

### Still not fully described

We are not getting closer to a solution - unfortunately. The basic Teechart series histogram is defined as a series with three columns as you can see during the discussions above.

However in the v7 Teechart documentation I found in a "strange corner", since the keyword histogram cannot be found a suggestion:
"How to create charts with manually inserted values" a suggestion:
If you have X (Horizontal) Coordinates:
Series2.AddXY( 15.2 , 25.4 , 'Barcelona' , clBlue );

So in short: The question could have been:
"How do I make an x-axis behave with numerical attributes in a histogram, since the standard behaviour of THistogramseries is to have it as a text".

And the answer most likely is: the quote above.

thanks for the quick answers anyway Narcis.

regards Jens lauritsen

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

Could you please send us a simple example project we can run "as-is" to reproduce the problem here and let us know what would you exactly expect from it? We will try to modify it so that you get what you expect.

You can post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

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

epidata
Newbie
Posts: 10
Joined: Wed Mar 31, 2004 5:00 am
Location: Denmark
Contact:

### Problem solved

Following the previous entry (see above) we implemented the histogram by using the addxY( ) method which in teechart results in a dataseries with an x as well as y value. In contrast to the add( ) method, which has only one count series and an x axis.

Unfortunately it was not easy to take the source code out to send you since it is wowen into many other modular units.

Regards
Jens Lauritsen