ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Wrong value assignment on yAxis2 min/max
Posted by Joe on Dec-04-2025 16:09

Hi Peter

I am using 2 yaxis for the graph. Left hand is fixed values, but for righthand y axis,  max /min values are changed according to needs.
Sometimes i have to increase righthand y axis by amount of 0.1 for their min and max values, and I am using below code as an example.



double sec_graph_max, sec_graph_min;

sec_graph_max = 13.6;
sec_graph_min = 10.0;

sec_graph_max = sec_graph_max + 0.100;
sec_graph_min = sec_graph_min + 0.100;
c.yAxis2().setLinearScale(sec_graph_min, sec_graph_max);



Problem is that above code is working well, but after several repeated increase, although sec_graph_max / sec_graph_min values are correct, the min or max value of the graph is changed from these variables.
For example, if i increase 4 times, then sec_graph_max becomes 14.0, and sec_graph_min is 10.4, but on the graph, max value is corretly displayed with 14.0 but min value is displayed with 10.3.

These unexpected deviation happens randomly. Sometimes, 10 time increase is ok, but other times, 6 times increase gets thesee wrong change in the minimum or maximum values.

Would you give me solution on this issue?

  Re: Wrong value assignment on yAxis2 min/max
Posted by Peter Kwan on Dec-05-2025 00:00
Hi Joe,

The "c.yAxis2().setLinearScale(sec_graph_min, sec_graph_max);" only specify the min and max values. It does not specify the tick increment. In this case, ChartDirector will automatically determine the tick increment. It may extend the min and/or max values to align with the ticks.

For example, if the code is "c.yAxis2().setLinearScale(100.5, 109.699);", and if ChartDirector choose to use 0.1 as the tick increment, it will generate the labels as (100.5, 100.6, 100.7, 100.8, 100.9, 110.0). Note that range is extended to 100.5 - 110 to align with the tick increment.

See the following for the description of the tick increment parameter:

https://www.advsofteng.com/doc/cdnet.htm#Axis.setLinearScale.htm

In your case, repeating adding an non-exact number 0.1 can also be an issue. For example, in decimal systems, 1/3 can only be represented approximately as 0.333333..... (it requires infinite number of digits). For the same reason, 0.1 can only be represented approximately in IEEE 754 floating point format. If you add 0.1 multiple times, the error will accumulate, so what you think is 110.5 may actually be 110.5000000001. ChartDirector may then extend it to 110.6 to align with the ticks.

To solve the problem, you may try:

(A) To avoid error accumulation:

sec_graph_min = initial_graph_min + N/10.0;

where N is an integer. Basically, you adjust N to move the axis range. This avoids adding 0.1 multiple times to sec_graph_min and accumulating the errors.

(B) You may specify the tick increment. In this case, ChartDirector will not automatically adjust the numbers.

c.yAxis2().setLinearScale(sec_graph_min, sec_graph_max, 0.1);

(C) If you cannot determine the tick increment, you can let ChartDirector automatically determine it, and ask ChartDirector not to extend the scale to fit the tick increment.

c.yAxis2().setLinearScale(sec_graph_min, sec_graph_max);
c.yAxis2().setRounding(false, false);

Best Regards
Peter Kwan

  Re: Wrong value assignment on yAxis2 min/max
Posted by Joe on Dec-05-2025 15:22
Hi Peter

Always thanks for your deep and detailed knowledge of the operations of the library.
I adopted (B), and now graph works flawlessly.  Regardless of number of repeated increase, the y-axis is working correctly.


Thank you very much again, and wish you have a nice year end!