Recent

Author Topic: AxisList[0].Range is not accepted  (Read 1304 times)

Firebird

  • Newbie
  • Posts: 4
AxisList[0].Range is not accepted
« on: February 03, 2022, 11:44:29 am »
Dear All,
I am using TAChart to generate a simple xy diagram (see image in the attachment).
When I try to reset Chart1.AxisList[0].Range.Min or
Chart1.AxisList[0].Range.Max in the program the
application automatically changes it to the extension
of the y-axis of the graph presented. However, if I do this for
the Chart1.AxisList[1].Range.Min or Chart1.AxisList[1].Range.Max
it works fine. I have added the code of the form (the setting takes place in function EditAxisScaling()), the corresponding Lazarus Form and a screenshot of form at runtime. I would be very grateful for a hint.

wp

  • Hero Member
  • *****
  • Posts: 9902
Re: AxisList[0].Range is not accepted
« Reply #1 on: February 03, 2022, 12:23:42 pm »
Sorry, I do not want to look at your code without compiler support - it would be much more difficult. Please remove everything from the form which is not needed and put it into a standalone project which I can compile after you uploaded it under "Attachments and other options". Put the .pas, .lfm, .lpr and .lpi files into a common zip archive which is accepted by the forum software. Do not add any compiler-generated files, otherwise the zip will become too large.

Firebird

  • Newbie
  • Posts: 4
Re: AxisList[0].Range is not accepted
« Reply #2 on: February 06, 2022, 04:09:37 pm »
Thank you for the feedback. I have attached a miniproject with the code as requested. Now, selecting the min and max values for the graph display automatically focuses on the graph extensions on both axis when min and max are selected (SpeedButton1 -> EditAxisScaling). It is probably a configuration issue on my side - but which one? Thank you for the help in advance.

wp

  • Hero Member
  • *****
  • Posts: 9902
Re: AxisList[0].Range is not accepted
« Reply #3 on: February 06, 2022, 04:40:47 pm »
There are several levels of priorities which affect the range of an axis. The TChartAxis.Range has a very low priority. Next higher priority is the range dictated by the series. This means that when the data range covered by the series exceeds the range of the axis the latter one is ignored.

The simplest way to achieve given axis limits is to assign them to the Extent subproperties of the chart:
Code: Pascal  [Select][+][-]
  1.   Chart.Extent.XMin := 0.7;
  2.   Chart.Extent.XMax := 1.1;
  3.   Chart.Extent.YMin := 3.0;
  4.   Chart.Extent.YMax := 5.0;
  5.   Chart.Extent.UseXMax := true;
  6.   Chart.Extent.UseXMin := true;
  7.   Chart.Extent.UseYMax := true;
  8.   Chart.Extent.UseYMin := true;

But be carefull to apply the Use* in the correct order. The minimum must never be greater than the maximum! To avoid this it is recommended to use an auxiliary variable and let the chart apply the limit at the same time in the FixTo method:
Code: Pascal  [Select][+][-]
  1. uses
  2.   TACharUtils;   // needed for TDoubleRect;
  3. ...
  4. var
  5.   extent: TDoubleRect;
  6. ...
  7.   extent.a.x := 0.7;   // min x value
  8.   extent.b.x := 1.1;   // max x value
  9.   extent.a.y := 3.0;   // min y value
  10.   extent.b.y := 5.0;   // max y value;
  11.   Chart1.Extent.FixTo(extent);


Firebird

  • Newbie
  • Posts: 4
Re: AxisList[0].Range is not accepted
« Reply #4 on: February 07, 2022, 10:37:40 am »
That really helped! Thank you very much, now everything is working as it should.

 

TinyPortal © 2005-2018