Recent

Author Topic: [Solved] I set VertAxis.Range.Min:=0 and UseMax:=true but still see data below 0  (Read 256 times)

dvhx

  • New Member
  • *
  • Posts: 19
I'm using TChart. My data y is from 0 to 5 but I want to see y axis from 0, to 10, so I use this Min:=0, Max=10, UseMin:=true, UsaMax:=true. This works, but if I have data that goes below zero, chart ignores Min:=0,UseMin:=true and increases y axis range to -1 fit the chart on screen. I don't want to modify data, I just want initial view to be from 0 to 10, not from -1 to 10.

Code: Pascal  [Select][+][-]
  1. var s : TLineSeries;
  2. begin
  3.   s := TLineSeries.Create(Chart1);
  4.   s.AddXY(0,0);
  5.   s.AddXY(1,5);
  6.   s.AddXY(2,0);
  7.   s.AddXY(3,5);
  8.   s.AddXY(4,0);
  9.   s.AddXY(4.1,-1); // random noise in data I'm not interested in
  10.   s.AddXY(4.2,0);
  11.   s.AddXY(5,5);
  12.   s.AddXY(6,0);
  13.   Chart1.AddSeries(s);
  14.   Chart1.VertAxis.Range.Min := 0;
  15.   Chart1.VertAxis.Range.Max := 10;
  16.   Chart1.VertAxis.Range.UseMax := true;
  17.   Chart1.VertAxis.Range.UseMin := true;
  18. end;
  19.  

Lazarus 2.2.0+dfsg1-5ubuntu1 (rev Unversioned directory) FPC 3.2.2 x86_64-linux-gtk2 Ubuntu 22.04.5 LTS
« Last Edit: February 19, 2025, 07:14:04 am by dvhx »

wp

  • Hero Member
  • *****
  • Posts: 12696
Use the Chart.Extent to freeze the axis limits.
Code: Pascal  [Select][+][-]
  1. Chart.Extent.YMin := 0;
  2. Chart.Extent.YMax := 10
  3. Chart.Extent.UseYMin := true;
  4. Chart.Extent.UseYMax := true;
But note that the Chart.Extent is given in "graph coordinates" (see https://wiki.lazarus.freepascal.org/TAChart_documentation#Coordinates_and_axes for an explanation), so when you have a logarithmic axis and want it to range between 0.1 and 1000 you must set Chart.Extent.YMin = -1 and Chart.Extent.YMax = 3 (these are the logarithms of 0.1 and 1000, respectively).

dvhx

  • New Member
  • *
  • Posts: 19
This solved it, thanks

 

TinyPortal © 2005-2018