Page 1 of 1

THistogram series bottom axis cannot change axis increment

Posted: Wed Feb 21, 2007 3:28 pm
by 9336948
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
    result.Add(DataVector[i],LabelVector.AsString[i]),Color[i]);
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!
    Axis.AdjustMaxMin;
    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

Posted: Wed Feb 21, 2007 3:37 pm
by narcis
Hi JL,

You can achieve what you request using this:

Code: Select all

  Chart1.Axes.Bottom.LabelStyle:=talValue;

Unfortunately not so - talvalue does not solve the problem

Posted: Wed Feb 21, 2007 5:12 pm
by 9336948
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.

Posted: Thu Feb 22, 2007 8:44 am
by narcis
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;

Still not fully described

Posted: Tue Feb 27, 2007 8:43 pm
by 9336948
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:
Replace the AddY method with AddXY:
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

Posted: Wed Feb 28, 2007 9:10 am
by narcis
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.

Thanks in advance.

Problem solved

Posted: Wed May 09, 2007 8:55 pm
by 9336948
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