Wrong axis min/max values for automatic axis

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Alain
Newbie
Newbie
Posts: 7
Joined: Tue Apr 05, 2011 12:00 am

Wrong axis min/max values for automatic axis

Post by Alain » Thu Feb 06, 2014 4:22 pm

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.
Attachments
Example.zip
(55.24 KiB) Downloaded 413 times

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Wrong axis min/max values for automatic axis

Post by Yeray » Fri Feb 07, 2014 2:57 pm

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 396 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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Alain
Newbie
Newbie
Posts: 7
Joined: Tue Apr 05, 2011 12:00 am

Re: Wrong axis min/max values for automatic axis

Post by Alain » Fri Feb 07, 2014 4:06 pm

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.
Attachments
TestData.zip
(86.8 KiB) Downloaded 378 times

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Wrong axis min/max values for automatic axis

Post by Yeray » Tue Feb 11, 2014 9:42 am

Hello,

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

Code: Select all

//yAxis->AdjustMaxMin();
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Alain
Newbie
Newbie
Posts: 7
Joined: Tue Apr 05, 2011 12:00 am

Re: Wrong axis min/max values for automatic axis

Post by Alain » Wed Feb 12, 2014 3:53 pm

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.
Attachments
DataTest2.zip
(42.33 KiB) Downloaded 381 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Wrong axis min/max values for automatic axis

Post by Narcís » Fri Feb 14, 2014 3:33 pm

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Alain
Newbie
Newbie
Posts: 7
Joined: Tue Apr 05, 2011 12:00 am

Re: Wrong axis min/max values for automatic axis

Post by Alain » Tue Feb 18, 2014 1:51 pm

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

Alain
Newbie
Newbie
Posts: 7
Joined: Tue Apr 05, 2011 12:00 am

Re: Wrong axis min/max values for automatic axis

Post by Alain » Tue Feb 18, 2014 3:55 pm

Sorry, forgot to attach the file TestData.txt.

Regards,
Alain
Attachments
TestData.zip
(37.39 KiB) Downloaded 376 times

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Wrong axis min/max values for automatic axis

Post by Yeray » Wed Feb 19, 2014 4:18 pm

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 12578 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 12587 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 12579 times
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Wrong axis min/max values for automatic axis

Post by Yeray » Wed Feb 19, 2014 4:40 pm

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 12571 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 12574 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 12574 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;
}
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Alain
Newbie
Newbie
Posts: 7
Joined: Tue Apr 05, 2011 12:00 am

Re: Wrong axis min/max values for automatic axis

Post by Alain » Fri Feb 21, 2014 12:00 pm

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

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Wrong axis min/max values for automatic axis

Post by Yeray » Mon Feb 24, 2014 10:08 am

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 12519 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! :)
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply