Recent

Author Topic: [SOLVED] How to set the LeftAxisList.Range ?  (Read 2033 times)

senglit

  • Full Member
  • ***
  • Posts: 141
[SOLVED] How to set the LeftAxisList.Range ?
« on: May 09, 2020, 08:38:24 am »
Hi,

I was using TChart and got a strange problem. I'm not sure if I post it in the correct place since the titile of this sub-board is "TAChart".

Ok, Let's make it short. I want to show data (Stored in ListChartSource1) in Chart1. all of the y values less than 20 are actually "missing data". So I set these properties:
Code: Pascal  [Select][+][-]
  1. chart1.Series.add(ListChartSource1);
  2. chart1.AxisList[0].Range.Min:=20;
  3. chart1.AxisList[0].Range.UseMin:=True;
  4.  
*They were set via the Lazarus IDE, not from my code. I wrote them only to avoid posting one more screenshot picture and save a little bit disk storage of this forum.*

I hope the minimum y value shown on the chart1 is 20, all of the value less than 20 are "below the bottom axis", which can not be seen, which would not occupy the chart1's screen extend.

Then in my code, the main process like this:
Code: Pascal  [Select][+][-]
  1. ListChartSource1.clear;
  2. for i:=0 to 3599 do
  3. begin
  4.   ListChartSource1.Add(i,SourceData[i],format('%2.2d:%2.2d',[i div 60,i mod 60]));
  5. end;
  6. Chart1.Refresh;
  7.  

But I got the minimum y value is still 0. The chart1 showed like the attachement. the wave is compacked on Y direction because the scal is 0 to 50, not 20 to 50 as I want.

Did I miss something?

« Last Edit: May 09, 2020, 11:53:02 am by senglit »
I use Win11 + Lazarus3.6 + FPC Trunk. fpcupdeluxe

wp

  • Hero Member
  • *****
  • Posts: 13489
Re: How to set the LeftAxisList.Range ?
« Reply #1 on: May 09, 2020, 10:19:07 am »
I'm not sure if I post it in the correct place since the titile of this sub-board is "TAChart".
Correct. TAChart is the name of library, like Teechart for Delphi. TChart is the main component.

Code: Pascal  [Select][+][-]
  1. chart1.Series.add(ListChartSource1);
Is this real code or pseudo-code? Without having tested it I am very sure that this will not compile. What should happen here?

all of the y values less than 20 are actually "missing data". So I set these properties:
Code: Pascal  [Select][+][-]
  1. chart1.Series.add(ListChartSource1);
  2. chart1.AxisList[0].Range.Min:=20;
  3. chart1.AxisList[0].Range.UseMin:=True;
  4.  
The axis range displayed on the axis is the combination of several contributions. If you want the axis to start at 20 the safest way is to set the Chart.Extent.YMin := 20 and Chart.Extent.UseYMin := true.

The "official" way to handle missing data is to add a NaN ("not a number") value to the series:
Code: Pascal  [Select][+][-]
  1. uses Math;
  2. var
  3.   y: Double;
  4. ...
  5.   if SourceData[i] >= 20 then y := SourceData[i] else y := NaN;
  6.   ListChartSource1.Add(i, y, ...)

If these remarks do not solve your issue please create a simple project as demonstration, pack .pas, .lfm, .lpi, .lpr and data files (if needed) into a common zip and upload it here under "Attachment and other options". Do not add exe, ppu and other compiler-generated file, otherwise the upload will be too large.
« Last Edit: May 09, 2020, 11:45:00 am by wp »

senglit

  • Full Member
  • ***
  • Posts: 141
Re: How to set the LeftAxisList.Range ?
« Reply #2 on: May 09, 2020, 11:51:18 am »
Quote
Is this real code or pseudo-code? Without having tested it I am very sure that this will not compile. What should happen here?
No, I made a comment under it. *They were set via the Lazarus IDE, not from my code. I wrote them only to avoid posting one more screenshot picture and save a little bit disk storage of this forum.*

Quote
The axis range displayed on the axis is the combination of several contributions. If you want the axis to start at 20 the safest way is to set the Chart.Extent.YMin := 20 and Chart.Extent.UseYMin := true.
It works!

Quote
The "official" way to handle missing data is to add a NaN ("not a number") value to the series:
Code: Pascal  [Select][+][-]
  1. uses Math;
  2. var
  3.   y: Double;
  4. ...
  5.   if SourceData[i] >= 20 then y := SourceData[i] else y := NaN;
  6.   ListChartSource1.Add(i, y, ...)

It works perfectly!! Thank you!
I use Win11 + Lazarus3.6 + FPC Trunk. fpcupdeluxe

 

TinyPortal © 2005-2018