Page 1 of 1

Wrong axis min/max values for automatic axis

Posted: Thu Feb 06, 2014 4:22 pm
by 16458946
Hello,
We are currently facing an issue concerning TeeChart Pro v2013.09.131119 for C++Builder XE5. It appeared after we upgraded from TeeChart Pro v2012.07.121105 for C++Builder XE3.

In the software we are developing, we must get the range being displayed by the Y axis of a TeeChart graph. When the automatic axis mode is off, we can easily get the current range by reading the Minimum and Maximum properties of the TChartAxis class.

However, those properties doesn't return the displayed range under the following conditions:
- Automatic axis mode is on;
- MinimumRound = true
- MaximumRound = true
- RoundFirstLabel = true

In this case, the Minimum and Maximum properties returns the series' data minimum and maximum values. Previously, we could get around this problem by using the TChartAxis.CalcPosPoint method using the TChart.ChartRect rectangle as reference. However, since the upgrade, this function no longer returning the correct values.

Here is an example using a demo program (see screenshots attached to this e-mail):

Figure 1: The Y axis has the range 4 to 20 with the automatic axis mode off.
The TChartAxis Minimum and Maximum properties returns 4 and 20 respectively.
The TChartAxis CalcPosPoint returns 4 and 20 for the top and bottom of the Y axis respectively.

Figure 2: The Y axis has the range 3 to 21 with the automatic axis mode on.
The TChartAxis Minimum and Maximum properties returns 4.73 and 19.54 respectively.
This is actually the range of the series' data values.

The TChartAxis CalcPosPoint returns 4 and 20 for the top and bottom of the Y axis respectively.
This is clearly incorrect (it should return 3 to 21).

Any advice or effort to resolve this issue would be appreciated.

Re: Wrong axis min/max values for automatic axis

Posted: Fri Feb 07, 2014 2:57 pm
by yeray
Hi,

I've done a simple project trying to simulate what you have explained but I'm not sure about what's the exact code the buttons are executing.
testCalcPosPoint.zip
(1.85 KiB) Downloaded 402 times
Here you have little explanation of what CalcPosPoint does:
http://www.teechart.net/support/viewtop ... 993#p60993

Could you please modify the attached project so we can reproduce the problem here?
If you don't have Delphi personality, could you please arrange a simple example project we can run as-is to reproduce the problem here?

Thanks in advance.

Re: Wrong axis min/max values for automatic axis

Posted: Fri Feb 07, 2014 4:06 pm
by 16458946
Hi Yeray,

We use C++ for our development projects. In the attached file, you will find the source code and the data file used by our sample program.
Advise us if you require anything else.

Re: Wrong axis min/max values for automatic axis

Posted: Tue Feb 11, 2014 9:42 am
by yeray
Hello,

If you comment out the following line in both BtUseMinMaxPropClick and BtUseCalcPosPointClick, doesn't it work as expected?

Code: Select all

//yAxis->AdjustMaxMin();

Re: Wrong axis min/max values for automatic axis

Posted: Wed Feb 12, 2014 3:53 pm
by 16458946
Hi Yeray,

We modified the sample program and commented out the AdjustMaxMin method as suggested. Indeed the values returned by CalcPosPoint() are now correct. However, when we tried this in our software, we sometimes get incorrect values for the Y axis after its properties get modified programmatically.

We attached another version of the sample program to demonstrate the problem. The new button "Test Y axis range" triggers the following procedure:
1) The Y axis' automatic mode is deactivated
2) The range of the Y axis is set to: Min = 0, Max = 0
3) The chart's data source get closed, then reopened
4) The chart gets repainted
5) The Y axis is set on automatic mode
6) The AdjustMaxMin() method is called if the corresponding checkbox is checked
7) The range of the Y axis is calculated using the CalcPosPoint() method.

So, if the "Automatic Y axis" checkbox is unchecked and button "Test Y axis range" is clicked:
- The Y axis range as shown by the graph is 3 to 21
- The range returned by the CalcPosPoint() method is 4 to 20 (not correct !).
- The "automatic Y axis" checkbox becomes checked (since the Y axis is now in automatic mode).

If we click on the "Test Y axis range" button a second time, leaving the "automatic Y axis" checkbox checked:
- The Y axis range as shown by the graph is 3 to 21
- The range returned by the CalcPosPoint() method is 3 to 21 (correct this time).

Now, if we uncheck the "automatic Y axis" checkbox and click on the button "Test Y axis range" again, the results will depend on the status of the "Use AdjustMaxMin()" checkbox:

- If unchecked (AdjustMaxMin() is not called), the range returned by CalcPosPoint() is 4.73 to 19.54
- If checked (AdjustMaxMin() is called), the range returned by CalcPosPoint() is 4 to 20.

In both cases, the Y axis' range displayed by the graph is 3 to 21, which are the values we are expecting. So the CalcPosPoint() method is not returning the correct values, regardless if we use the AdjustMaxMin() method or not.
In any case, we really much prefer to get the real Y axis displayed range the first time around. If there is a way to do this, we would be happy to know about it.

Re: Wrong axis min/max values for automatic axis

Posted: Fri Feb 14, 2014 3:33 pm
by narcis
Hi Alain,

First of all, apologies for the delayed reply.

Thanks for your collaboration and feedback. I have found that I can not run your test project properly because the .txt file for the TSeriesTextSource component is missing. Could you please attach it as well so that we can run the complete test?

Thanks in advance.

Re: Wrong axis min/max values for automatic axis

Posted: Tue Feb 18, 2014 1:51 pm
by 16458946
Hi NarcĂ­s,

Attached to this post, the TestData.txt is the file used for our sample project, which is a simple comma-separated XY data table.

Regards,
Alain

Re: Wrong axis min/max values for automatic axis

Posted: Tue Feb 18, 2014 3:55 pm
by 16458946
Sorry, forgot to attach the file TestData.txt.

Regards,
Alain

Re: Wrong axis min/max values for automatic axis

Posted: Wed Feb 19, 2014 4:18 pm
by yeray
Hello Alain,
Alain wrote:We attached another version of the sample program to demonstrate the problem. The new button "Test Y axis range" triggers the following procedure:
1) The Y axis' automatic mode is deactivated
2) The range of the Y axis is set to: Min = 0, Max = 0
3) The chart's data source get closed, then reopened
4) The chart gets repainted
5) The Y axis is set on automatic mode
6) The AdjustMaxMin() method is called if the corresponding checkbox is checked
7) The range of the Y axis is calculated using the CalcPosPoint() method.
Note you are not repainting the chart between changing some chart properties and retrieving some others.
Alain wrote:So, if the "Automatic Y axis" checkbox is unchecked and button "Test Y axis range" is clicked:
- The Y axis range as shown by the graph is 3 to 21
Not for me here. Note this is what you see when you start the application:
start.png
start.png (15.06 KiB) Viewed 12722 times
Then, after clicking the "Test Y axis range" button, this is what I see:
1_click.png
1_click.png (28.98 KiB) Viewed 12731 times
Where do you see a 3 to 21 range in the left axis?
Alain wrote:- The range returned by the CalcPosPoint() method is 4 to 20 (not correct !).
Yes, this is what I see, but it's correct. You've added values to the chart but note you haven't repainted the chart after it, so the axes values haven't still been recalculated.
Alain wrote:- The "automatic Y axis" checkbox becomes checked (since the Y axis is now in automatic mode).
Same for me here:
1_click_2.png
1_click_2.png (25.01 KiB) Viewed 12723 times

Re: Wrong axis min/max values for automatic axis

Posted: Wed Feb 19, 2014 4:40 pm
by yeray
I continue...
Alain wrote:If we click on the "Test Y axis range" button a second time, leaving the "automatic Y axis" checkbox checked:
- The Y axis range as shown by the graph is 3 to 21
No for me here. This is what I get the second time I clicked the same "Test Y axis range" button:
2_click.png
2_click.png (28.35 KiB) Viewed 12715 times
Alain wrote:- The range returned by the CalcPosPoint() method is 3 to 21 (correct this time).
Not for me. See image above.
Alain wrote:Now, if we uncheck the "automatic Y axis" checkbox and click on the button "Test Y axis range" again, the results will depend on the status of the "Use AdjustMaxMin()" checkbox:

- If unchecked (AdjustMaxMin() is not called), the range returned by CalcPosPoint() is 4.73 to 19.54
I get 190.488 to 6.348.110.243:
3_manual.png
3_manual.png (28.8 KiB) Viewed 12718 times
Alain wrote:- If checked (AdjustMaxMin() is called), the range returned by CalcPosPoint() is 4 to 20.
I get 0 to 6.500.000.000:
4_manual_adjust.png
4_manual_adjust.png (28.69 KiB) Viewed 12718 times
Alain wrote:In both cases, the Y axis' range displayed by the graph is 3 to 21, which are the values we are expecting. So the CalcPosPoint() method is not returning the correct values, regardless if we use the AdjustMaxMin() method or not.
In any case, we really much prefer to get the real Y axis displayed range the first time around. If there is a way to do this, we would be happy to know about it.
I'm getting different results here with XE5 and TeeChart v2013.09. You are suing the same environment, aren't you?
I don't understand what the purpose of having an "Automatic Y Axis" checkbox that changes the left axis AutomaticMinimum and AutomaticMaximum properties accordingly but then doing this at the BtTestYAxisRangeClick:

Code: Select all

void __fastcall TMainForm::BtTestYAxisRangeClick(TObject *Sender)
{
//...

	yAxis = MainChart->LeftAxis;

	MainChart->LeftAxis->AutomaticMinimum = false;
	MainChart->LeftAxis->AutomaticMaximum = false;

	yAxis->SetMinMax(0,0);

//...

	MainChart->LeftAxis->AutomaticMinimum = true;
	MainChart->LeftAxis->AutomaticMaximum = true;

//...

	CBAutomaticYAxis->Checked = true;
}

Re: Wrong axis min/max values for automatic axis

Posted: Fri Feb 21, 2014 12:00 pm
by 16458946
Hello Yeray,

We are not sure why our sample program gives you a different result and behavior. You are indeed using the same version of C++Builder and TeeChart than us.

For example, the Y axis in the sample data only has data between 4.73 and 19.54 and all of them are valid floating point values, so we don't understand how you can get a range like -500.000.000 to 7.000.000.000. We do not observe anything like this on our side. You should also be able to see the data upon starting the program.

That being said, you told us we need to force the TChart component to repaint itself after adding data to it or changing the axis' properties before we can read the Y axis' limit values. So we tried this by adding a call to the TChart->Draw() method as follow:

void __fastcall TMainForm::BtTestYAxisRangeClick(TObject *Sender)
{
TRect chartRect = MainChart->ChartRect;

// Add data...

// Set Y axis' properties...

MainChart->Draw(); // <-- Added line

if( CBAdjustMaxMin->Checked )
yAxis->AdjustMaxMin();

double yMin = yAxis->CalcPosPoint(chartRect.Bottom);
double yMax = yAxis->CalcPosPoint(chartRect.Top);

//...
}
//---------------------------------------------------------------------------

This time around, the Y axis limits are computed correctly by the CalcPosPoint() method every time.
This solves our problem.

Thank you for your help !
Alain

Re: Wrong axis min/max values for automatic axis

Posted: Mon Feb 24, 2014 10:08 am
by yeray
Hi Alain,
Alain wrote:We are not sure why our sample program gives you a different result and behavior. You are indeed using the same version of C++Builder and TeeChart than us.
It seems we have different locales. I've added this to your project to be sure the '.' is taken as the decimal separator and not as the thousand separator.

Code: Select all

	SetLocaleInfoA(GetUserDefaultLCID(),LOCALE_STHOUSAND,",");
	SetLocaleInfoA(GetUserDefaultLCID(),LOCALE_SDECIMAL,".");
Then when the application starts, I see this (I've also added a button that opens a TChartEditor):
start.png
start.png (25.18 KiB) Viewed 12663 times
Now the values look as the ones you were talking about. And everything behaves as you detailed in your previous messages.
Alain wrote:This time around, the Y axis limits are computed correctly by the CalcPosPoint() method every time.
This solves our problem.
Great! :)