Recent

Author Topic: TAChart newbie question - Bottom axis reverts to data based scaling  (Read 2654 times)

jbmckim

  • Full Member
  • ***
  • Posts: 144
I'm trying to hard code a display range for a data set.  I was able to set the Left (i.e. y) scale with:

Code: Pascal  [Select][+][-]
  1. Chart1.AxisList[0].Range.Max := 2500;
  2.   Chart1.AxisList[0].Range.Min := 2000;  

I tried something analogous (to me at least) for the Bottom (x) scale:

Code: Pascal  [Select][+][-]
  1.   Chart1.AxisList[1].Range.Max := 400;
  2.   Chart1.AxisList[1].Range.Min := 100;  


The resulting form designer display is in the Grid display (.jpg) attachment.  Clearly the Left marks are behaving differently than the bottom marks but as in the subject, I'm a newbie and have no idea why that might be.

The bottom and left axis values from the Object Inspector are also attached.

Thanks.

wp

  • Hero Member
  • *****
  • Posts: 11923
For the left axis, you do not provide values for Range.Max and Range.Min, you only set UseMax and UseMin to true.

BTW: For the bottom axis, you specify Range.max and Range.Min in the wrong order. It seems to be working here, but there are other cases, when this will lead to an error. Always enter these data such that Max > Min. If it was your intention to change the axis direction (to have the larger value at the left) use the axis property "Inverted".

Another remark: Your code is more readable if you use the identifiers Chart1.LeftAxis and Chart1.BottomAxis instead of Chart1.AxisList[0] and Chart1.AxisList[1]. The latter even is risky because you can drag the BottomAxis above the LeftAxis in the object inspector tree, or because you can change the Alignment of an axis.

jbmckim

  • Full Member
  • ***
  • Posts: 144
Great points all.  Thanks.  I put them in and they tested good but after doing so found there's something else that is at play. 

On the left axis, the data is contained with the sizes set in the code.  (i.e between 2000 and 2500).

On the bottom axis, the data exceeds the sizes set in the code.  That is, the display is 100-400 while the data is from 0 to 512.

Everything looks good when the form (and chart) loads.  When the data is run through the chart however, the L size holds while the B axis reverts to 512.  I'm looking to hold the display in place without truncating the incoming data if possible.

Thanks.

PS.  This problem was not clear (to me at least) before your other suggested fixes.

wp

  • Hero Member
  • *****
  • Posts: 11923
I am not sure if I understand the issue. Is it that you modify the x axis to be labelled from 100 to 400, then when you add data going up to 512 you see that the preset max of the x axis is lost and changes to 512?

This is intended behavior. The chart calculates the union of the range defined by the axis.Range and the range covered by the series and calculates the labels accordingly.

If you want the axis limits to be fixed independently of the data range given by the series, then you should not use axis.Range but Chart.Extent. See attached demo.

With Axis.Range you can make the axis limits fixed as long as the data range stays within the axis limits. But when data are added outside the axis range, the axis automatically expands to avoid hiding any data.

With Chart.Extent the axis limits are fixed, no matter of the range of the data. If data points fall outside the Chart.Extent then they are not shown.

jbmckim

  • Full Member
  • ***
  • Posts: 144
Yes.  Turns out I wanted Extents.  I'm "porting" from another environment where the xAxis/yAxis classes contains all such properties.  I was not aware of Extents.

I notice peculiar behavior in configuring though.  Setting up the Use... values before the XMin, YMin numerics in the Object Inspector crashes the UI.  (LP 1.6.4)  Is this intended or outstanding?  I'll report as a bug if it would be helpful.

wp

  • Hero Member
  • *****
  • Posts: 11923
It should report an exception, but should not crash Lazarus - i'll have to look.

Chart.Extent is one of the examples where min and max always must be in the correct order, i.e. min must be smaller than max. This does not only mean that the corresponding values are entered in the correct fields, additionally is is also important to enter the values and to activate the Use* switches in the correct order. The order of operations that I would recommend is (example for x axis)
  • enter XMax
  • enter XMin
  • check UseXMax
  • check UseXMin

 

TinyPortal © 2005-2018