Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Tchart - How to adjust Left Axis scale during runtime ?


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Oct 18, 2017 3:36 AM Last Post By: Yeray Alonso
Jose Silva

Posts: 18
Registered: 11/1/11
Tchart - How to adjust Left Axis scale during runtime ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2017 7:26 AM
Hi guys , I need some help to solve an issue with Tchart Left Axis scale.

I'm using Delphi Tokyo 10.2 , Update 1 , with Tchart component. I plot a Tline series points based on values returned by a running procedure, which can be of very different magnitude.

As an example, for the first 12 "X"-axis elements , the Y-axis values returned are between 1,000 and 900.00 (thousands) , but for next X elemensts its is possible to get values that gos to 1,000,000 - 10,000,000 or even over thos values (millions) . HOW TO adjust the scale of Left Axis (Y-values) during runtime , considering that the first 12 values will need to be readjusted in the new scale ??

I do appreciate your help and suggestions on this issue.

Thank you in advance.

JRG

Edited by: Jose Silva on Oct 16, 2017 7:26 AM

Edited by: Jose Silva on Oct 16, 2017 9:52 AM
Yeray Alonso

Posts: 68
Registered: 6/12/11
Re: Tchart - How to adjust Left Axis scale during runtime ?
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2017 11:59 PM   in response to: Jose Silva in response to: Jose Silva
Hello Jose,

Jose Silva wrote:
I'm using Delphi Tokyo 10.2 , Update 1 , with Tchart component. I plot a Tline series points based on values returned by a running procedure, which can be of very different magnitude.

As an example, for the first 12 "X"-axis elements , the Y-axis values returned are between 1,000 and 900.00 (thousands) , but for next X elemensts its is possible to get values that gos to 1,000,000 - 10,000,000 or even over thos values (millions) . HOW TO adjust the scale of Left Axis (Y-values) during runtime , considering that the first 12 values will need to be readjusted in the new scale ??

By default, TeeChart Axes are Automatic. When an Axis is Automatic, its scale (Minimum and Maximum) is automatically set considering all the values in all the series assigned to that axis.
Ie, in a new blank chart, if you add 12 values between 900 and 1000, both the bottom and the left axes scale to fit all the values and everything looks correct:

  Chart1.View3D:=False;
  Chart1.Legend.Visible:=False;
  Chart1.AddSeries(TPointSeries);
 
  for i:=0 to 11 do
    Chart1[0].Add(900+Random*100);


[img]https://i.imgur.com/S4Qfky9.png[/img]

If you add more values in a different range, ie between 1M and 10M, the axes are rescaled to fit all the points. The result is still correct. You can't see the differences between the first 12 values but that's something to expect:

var i: Integer;
begin
  Chart1.View3D:=False;
  Chart1.Legend.Visible:=False;
  Chart1.AddSeries(TPointSeries);
 
  for i:=0 to 11 do
    Chart1[0].Add(900+Random*100);
 
  for i:=0 to 11 do
    Chart1[0].Add(1000000+Random*9000000);


[img]https://i.imgur.com/IU0Fzxy.png[/img]

Now, having those values in the chart, if you want to focus the view to the first 12 points, you have to manually set both the bottom and the left axes scales. Ie:

  Chart1.Axes.Left.SetMinMax(900, 1000);
  Chart1.Axes.Bottom.SetMinMax(-0.25, 11.25);


Or, you can focus the view to the other 12 (high) points:

  Chart1.Axes.Left.SetMinMax(1000000, 10000000);
  Chart1.Axes.Bottom.SetMinMax(11.75, Chart1[0].Count-0.75);


Then, if you want to set the axes back to automatically set the scales, you can set the Automatic property:

  Chart1.Axes.Left.Automatic:=True;
  Chart1.Axes.Bottom.Automatic:=True;


--
Best Regards,

Yeray Alonso
Steema Software
Facebook, Twitter, GPlus, LinkedIn, YouTube, GitHub, RSS
Support Options
Jose Silva

Posts: 18
Registered: 11/1/11
Re: Tchart - How to adjust Left Axis scale during runtime ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2017 7:48 AM   in response to: Yeray Alonso in response to: Yeray Alonso
Yeray

thanks for the examples and clarifications, it certainly helped me to think in another direction to solve that.
One point that I didn't mentioned clearly was related to the Title of Left Axis related to the scale . Although scales changes automatically, from 900k to 1 million for example, the Title will remain the same . If initially the original title was Thousands US$ and scale changed to milions , is there any "Automatic" way to change the title to Milions US$ ?

I appreciate your support ! and contact.

Thank you.


Yeray Alonso wrote:
Hello Jose,

Jose Silva wrote:
I'm using Delphi Tokyo 10.2 , Update 1 , with Tchart component. I plot a Tline series points based on values returned by a running procedure, which can be of very different magnitude.

As an example, for the first 12 "X"-axis elements , the Y-axis values returned are between 1,000 and 900.00 (thousands) , but for next X elemensts its is possible to get values that gos to 1,000,000 - 10,000,000 or even over thos values (millions) . HOW TO adjust the scale of Left Axis (Y-values) during runtime , considering that the first 12 values will need to be readjusted in the new scale ??

By default, TeeChart Axes are Automatic. When an Axis is Automatic, its scale (Minimum and Maximum) is automatically set considering all the values in all the series assigned to that axis.
Ie, in a new blank chart, if you add 12 values between 900 and 1000, both the bottom and the left axes scale to fit all the values and everything looks correct:

  Chart1.View3D:=False;
  Chart1.Legend.Visible:=False;
  Chart1.AddSeries(TPointSeries);
 
  for i:=0 to 11 do
    Chart1[0].Add(900+Random*100);


[img]https://i.imgur.com/S4Qfky9.png[/img]

If you add more values in a different range, ie between 1M and 10M, the axes are rescaled to fit all the points. The result is still correct. You can't see the differences between the first 12 values but that's something to expect:

var i: Integer;
begin
  Chart1.View3D:=False;
  Chart1.Legend.Visible:=False;
  Chart1.AddSeries(TPointSeries);
 
  for i:=0 to 11 do
    Chart1[0].Add(900+Random*100);
 
  for i:=0 to 11 do
    Chart1[0].Add(1000000+Random*9000000);


[img]https://i.imgur.com/IU0Fzxy.png[/img]

Now, having those values in the chart, if you want to focus the view to the first 12 points, you have to manually set both the bottom and the left axes scales. Ie:

  Chart1.Axes.Left.SetMinMax(900, 1000);
  Chart1.Axes.Bottom.SetMinMax(-0.25, 11.25);


Or, you can focus the view to the other 12 (high) points:

  Chart1.Axes.Left.SetMinMax(1000000, 10000000);
  Chart1.Axes.Bottom.SetMinMax(11.75, Chart1[0].Count-0.75);


Then, if you want to set the axes back to automatically set the scales, you can set the Automatic property:

  Chart1.Axes.Left.Automatic:=True;
  Chart1.Axes.Bottom.Automatic:=True;


--
Best Regards,

Yeray Alonso
Steema Software
Facebook, Twitter, GPlus, LinkedIn, YouTube, GitHub, RSS
Support Options
Yeray Alonso

Posts: 68
Registered: 6/12/11
Re: Tchart - How to adjust Left Axis scale during runtime ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2017 3:35 AM   in response to: Jose Silva in response to: Jose Silva
Hello Jose,

Jose Silva wrote:
thanks for the examples and clarifications, it certainly helped me to think in another direction to solve that.
One point that I didn't mentioned clearly was related to the Title of Left Axis related to the scale . Although scales changes automatically, from 900k to 1 million for example, the Title will remain the same . If initially the original title was Thousands US$ and scale changed to milions , is there any "Automatic" way to change the title to Milions US$ ?

There's no automatic way to change the axis title. However, you can add some logic to do it after changing the axis scale. Ie:

  if (Chart1.Axes.Left.Minimum < 1000000) then
     Chart1.Axes.Left.Title:='Thousands US$'
  else
     Chart1.Axes.Left.Title:='Millions US$';


--
Best Regards,

Yeray Alonso
Steema Software
Facebook, Twitter, GPlus, LinkedIn, YouTube, GitHub, RSS
Support Options
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02