Recent

Author Topic: TChart how setup nicestep to 50  (Read 245 times)

eldonfsr

  • Hero Member
  • *****
  • Posts: 583
TChart how setup nicestep to 50
« on: April 18, 2026, 05:18:14 am »
How i can setup tchart nice steps to 50 units value

wp

  • Hero Member
  • *****
  • Posts: 13507
Re: TChart how setup nicestep to 50
« Reply #1 on: April 19, 2026, 12:02:04 am »
You can try to set the Intervals.Nicesteps of the axis to 0.5 (or 5 or 50 - this does not matter). If the labels are too close you can increase the Intervals.MaxLength; I usually get good results for MaxLength = 120 or so.

But be aware that when the size of the chart increases the labeler may suddenly switch to intervals of step size 5 rather than 50 because of the restriction of the NiceSteps it has no other option.

If you insist on step size 50 under all circumstances you should add a TListChartSource to the form and link it to the Marks.Source of the axis. Then write code which adds numbers in the given step size between the rounded minimum and maximum of your data.

Untested:
Code: Pascal  [Select][+][-]
  1. uses
  2.   ..., Math, TAChartUtils;
  3.  
  4. procedure PopulateAxisLabels(Chart: TChart; Axis: TChartAxis; ASource: TListChartSource; ASteps: Double);
  5. var
  6.   ext: TDoubleRect;
  7.   min, max, value: Double;
  8. begin
  9.   ext := Chart.LogicalExtent;
  10.   if Axis.IsVertical then
  11.   begin
  12.     min := floor(ext.a.y/ASteps) * ASteps;
  13.     max := ext.b.y;
  14.   end else
  15.   begin
  16.     min := floor(ext.a.x/ASteps) * ASteps;
  17.     max :=ext.b.x;
  18.   end;
  19.   value := min;
  20.   while (value <= max) do
  21.   begin
  22.     ASource.Add(value, value);
  23.     value := value + AStep;
  24.   end;
  25.   Axis.Marks.Source := ASource;
  26. end;

The problem with the ListSource solution is that there is no refinement of the steps when you zoom into the chart
 
 
« Last Edit: April 19, 2026, 12:03:45 am by wp »

 

TinyPortal © 2005-2018