|
Default values for lowerLimit and upperLimit for SetLinear function |
Posted by John on Apr-19-2013 15:12 |
|
Hi,
I want to know the default values for lowerLimit and upperLimit values If we are not provided any values for those in the SetLinearfunction of Chartdirector.
here my overloaded function:
void setLinearScale(double lowerLimit, double upperLimit, double majotTickInc)
Below are the my cases:
Case 1:
lowerLimit: provided
upperLimit: default value
majotTickInc : provided
Case 2:
lowerLimit: default value
upperLimit : provided
majotTickInc : provided
How Can I apply setLinear function for the above cases.
Thanks,
John |
Re: Default values for lowerLimit and upperLimit for SetLinear function |
Posted by Peter Kwan on Apr-20-2013 09:31 |
|
Hi John,
You can set the lowerLimit or upperLimit to Chart::NoValue if you want ChartDirector to automatically determine it. For example, you can set the lowerLimit to Chart::NoValue, and supply the upperLimit. ChartDriector will then automatically determine the lowerLimit. For example:
c->yAxis()->setLinearScale(Chart::NoValue, 8.8385);
ChartDirector will determine the lowerLimit and/or upperLimit based on many factors, such as the data values, how the values are combined, margins and extensions and the "zero affinity" (see Axis.setAutoScale), tick density (see Axis.setTickDensity), etc.. After ChartDirector has determined the axis scale, you may obtain it using Axis.getMinValue and Axis.getMaxValue.
Note that if your code does not provide both the lowerLimit and the upperLimit, it could not provide the majorTickInc. Any provided majorTickInc value would be ignored. Currently, ChartDirector will need the freedom to choose the tick increment in order to automatically determine the lowerLimit or upperLimit.
Also, note that if you do not provide the majorTickInc, ChartDirector may adjust the lowerLimit and upperLimit to align it with the majorTickInc it has chosen. For example, if the axis scale ends up being 0 to 8.833875287 (because the provided upperLimit is 8.833875287), and the tick increment is 2, ChartDirector may round the scale to 0 to 10, so that the axis end-points are at a labelled position. (This can be disabled using Axis.setRounding.)
Hope this can help.
Regards
Peter Kwan |
Re: Default values for lowerLimit and upperLimit for SetLinear function |
Posted by John on Apr-20-2013 14:05 |
|
Hi Thanks for your reply..
here what problem with SetLinear function is if I didnt provide either Minlimit or Maxlimit with majorTickInc its not working with the given limits. Its taking some other limits.
So Is the Minlimit and Maxlimit fields are manadatory to give when we set majorTickInc? |
Re: Default values for lowerLimit and upperLimit for SetLinear function |
Posted by Peter Kwan on Apr-20-2013 17:00 |
|
Hi John,
Yes. In setLinearScale, if you would like to specify majorTickInc, you must also specify lowerLimit and upperLimit.
If you do not want to specify lowerLimit or upperLimit, but want to use a certain majorTickInc, may be you can use the following method:
c->yAxis()->setLinearScale(100, Chart::NoValue);
//disable the ticks and labels
c->yAxis()->setLabelFormat("~");
..... create chart as usual .....
//auto-scale the axis and add the ticks directly
c->layoutAxes();
for (double d = c->yAxis()->getMinValue(); d <= c->yAxis()->getMaxValue() + 0.00001; d += majorTickInc)
c->yAxis()->addLabel(d, c->formatValue(d, "{value}"));
Hope this can help.
Regards
Peter Kwan |
Re: Default values for lowerLimit and upperLimit for SetLinear function |
Posted by John on Apr-22-2013 21:12 |
|
Hi Peter Kwan,
Thanks for your reply.
Its working for the case where we are providing lowerlimit and majorTickInc
But If I am trying to use the same snippet for the case where we are proving only upperlimit and majorTickInc not displaying lables correctly.
Below is my code snippet code:
c->xAxis()->setLinearScale(Chart::NoValue, nMaxX, MTickX);
c->xAxis()->setLabelFormat("~");
c->layoutAxes();
for (double d = c->xAxis()->getMinValue(); d <= c->xAxis()->getMaxValue() + 0.00001; d += nUnitX)
c->xAxis()->addLabel(d, c->formatValue(d, "{value}"));
And also I want know the constant value which we are using in the snippet i.e. 0.00001
Please give your suggetions.
Thanks & Regards,
John |
Re: Default values for lowerLimit and upperLimit for SetLinear function |
Posted by Peter Kwan on Apr-23-2013 00:31 |
|
Hi John,
Would you mind to clarify what is the issue? Is it possible to attach the chart you get to illustrate the issue?
For example, suppose nMaxX = 62.4872 and MTickX = 2. If your data values are from 57.88 to 61.123, ChartDirector may automatically set the lowerLimt 56, so the ticks should at "56, 58, 60, 62". Is it the case?
Note that the ticks start from the lowerLimit, so there is no guarantee that the nMaxX is at a tick position. In the above example, the axis scale would be 56 to 62.4872, but the ticks are from 56 up to 62 only. If you would like the ticks to start from the upperLimit, you would need to reverse the "for loop" to start from the getMaxValue and decrement by nUnitX.
I am not sure what is the nMaxX or nUnitX you are using. It is possible they may be inaccurate in the computer (because the "double" only has 64-bit precision). To handle floating point inaccuracies, we extend the range by a small value, which I just choose 0.00001. As long as this value is much smaller than nUnixX, it should be OK.
Hope this can help.
Regards
Peter Kwan |
Re: Default values for lowerLimit and upperLimit for SetLinear function |
Posted by John on Apr-23-2013 21:22 |
|
Hi Kewel,
Thanks for your reply.
Alomost the above code is working properly but there is a case
the graph x Axis scale lables are not displaying properly
below I am providing the test values which are I am using for ploting graph.
lowerLimit: Not provided
upperLimit: 45000
majotTickInc : 1000
X Y
53023 9813
47407 9625
42514 9446
38219 9300
For the above test input values the X axis scale parameters are displaying on the X axis like the below:
37500------38500-------39500-----40500-----41500------42500------43500-----44500
But My expected scaling parameters would be:
37000------38000------39000-----41000-------42000-----43000-----44000-----45000
that means instead of displaying of Max value as 45000 on x-Axis it displaying 44500
And my code snippet is:
c->xAxis()->setLinearScale(Chart::NoValue, upperLimit);
c->xAxis()->setLabelFormat("~");
c->layoutAxes();
for (double d = c->xAxis()->getMinValue(); d <= c->xAxis()->getMaxValue() + 0.00001; d += majotTickInc)
c->xAxis()->addLabel(d, c->formatValue(d, "{value}"));
Please see attached screenshot for your reference.
|
Re: Default values for lowerLimit and upperLimit for SetLinear function |
Posted by Peter Kwan on Apr-24-2013 01:35 |
|
Hi John,
As mentioned in my last message, there is no guarantee that both axis end points will be at a label position. If your code starts the labelling from the lower limit, then there will be a tick at the lower limit, but not necessarily at the upper limit. If you want to have a tick at the upper limit, you may start the labelling from the upper limit, like:
for (double d = c->xAxis()->getMaxValue(); d <= c->xAxis()->getMinValue() - 0.00001; d -= majotTickInc)
c->xAxis()->addLabel(d, c->formatValue(d, "{value}"));
Hope this can help.
Regards
Peter Kwan |
Re: Default values for lowerLimit and upperLimit for SetLinear function |
Posted by John on Apr-25-2013 15:10 |
|
Hi Peter Kwan,
Thanks for your reply.
I found a case there is an issue regarding scaling when I am trying to do scaling for the both X and y Axis at a time with the below case.
Here issue is Scaling is applying only for X axis but its not applying for y axis .
Case :
For X axis:
LowerLimitX: 39000
upperLimitX: Not providing
majotTickIncX : 1000
For y axis:
LowerLimitY: 9300
upperLimitY: Not providing
majotTickIncY : 100
X Y
53023 9813
47407 9625
42514 9446
38219 9300
The code snippet which I have used is
For x axis:
c->xAxis()->setLinearScale(LowerLimitX, Chart::NoValue);
c->xAxis()->setLabelFormat("~");
c->layoutAxes();
for (double d = c->xAxis()->getMinValue(); d <= c->xAxis()->getMaxValue() + 0.00001; d += majotTickIncX)
c->xAxis()->addLabel(d, c->formatValue(d, "{value}"));
For y axis:
c->yAxis()->setLinearScale(LowerLimitY, Chart::NoValue);
c->yAxis()->setLabelFormat("~");
c->layoutAxes();
for (double d = c->yAxis()->getMinValue(); d <= c->yAxis()->getMaxValue() + 0.00001; d += nmajotTickIncY)
c->yAxis()->addLabel(d, c->formatValue(d, "{value}"));
Note:
1) If I apply scaling for X and y axis individually with the bove case its working .
2) Also scaling is workign for both X and y Axis at a time If Iam providing all the LowerLimit, upperLimit and majotTickInc values for both x and y axis.
Please provide any solution for this.
Attached is the screen shot for your reference.
Thanks In Advance,
John.
|
Re: Default values for lowerLimit and upperLimit for SetLinear function |
Posted by Peter Kwan on Apr-26-2013 00:15 |
|
Hi John,
From your data and chart, it seems everything is working normally.
If you do not provide the y-axis scale, ChartDirector will automatically determine the scale based on your data. In your data, the data range is from 9300 to 9813. By default, ChartDirector will add 5% margin to the values before decided on the axis scale. This is to prevent the data points from touching the top of bottom border of the plot area. After adding the margin, the axis scale should be from 92xx to 98xx. ChartDirector eventually chooses 9200 to 9900.
If you do not want to add the margin, you may configure a zero margin using Axis.setAutoScale.
Hope this can help.
Regards
Peter Kwan |
Re: Default values for lowerLimit and upperLimit for SetLinear function |
Posted by John on Apr-26-2013 19:35 |
|
Hi Peter Kwan,
Thanks for your reply.
please read my prevoius post once again ( Y-axis scale is also provided).
For X axis:
LowerLimitX: 39000
upperLimitX: Not provided
majotTickIncX : 1000
For y axis:
LowerLimitY: " 9300 "
upperLimitY: Not provided
majotTickIncY : 100
X Y
53023 9813
47407 9625
42514 9446
38219 9300
The code snippet which I have used is
For x axis:
c->xAxis()->setLinearScale(LowerLimitX, Chart::NoValue);
c->xAxis()->setLabelFormat("~");
c->layoutAxes();
for (double d = c->xAxis()->getMinValue(); d <= c->xAxis()->getMaxValue() + 0.00001; d += majotTickIncX)
c->xAxis()->addLabel(d, c->formatValue(d, "{value}"));
For y axis:
c->yAxis()->setLinearScale(LowerLimitY, Chart::NoValue);
c->yAxis()->setLabelFormat("~");
c->layoutAxes();
for (double d = c->yAxis()->getMinValue(); d <= c->yAxis()->getMaxValue() + 0.00001; d += nmajotTickIncY)
c->yAxis()->addLabel(d, c->formatValue(d, "{value}"));
Please provide any solution for this.
Screen shot is attached for your reference.
Thanks In Advance,
John.
|
Re: Default values for lowerLimit and upperLimit for SetLinear function |
Posted by Peter Kwan on Apr-27-2013 08:02 |
|
Hi John,
When you call layoutAxes, the scale of all the axes will be determined. Calling setLinearScale after layoutAxes has no effect. The setLinearScale must be called before layoutAxes.
For your case, if you run the xAxis code first (which calls layoutAxes), followed by the yAxis code, then the yAxis code has no effect, because they are run after the xAxis code, which already calls the layout Axes. To manually scale both the x and y axes, the code should be structure like:
c->xAxis()->setLinearScale(LowerLimitX, Chart::NoValue);
c->xAxis()->setLabelFormat("~");
c->yAxis()->setLinearScale(LowerLimitY, Chart::NoValue);
c->yAxis()->setLabelFormat("~");
c->layoutAxes();
for (double d = c->xAxis()->getMinValue(); d <= c->xAxis()->getMaxValue() + 0.00001; d += majotTickIncX)
c->xAxis()->addLabel(d, c->formatValue(d, "{value}"));
for (double d = c->yAxis()->getMinValue(); d <= c->yAxis()->getMaxValue() + 0.00001; d += nmajotTickIncY)
c->yAxis()->addLabel(d, c->formatValue(d, "{value}"));
Hope this can help.
Regards
Peter Kwan |
Re: Default values for lowerLimit and upperLimit for SetLinear function |
Posted by John on Apr-29-2013 15:08 |
|
Hi Peter Kwan,
Many many thanks for your reply.
Now the code is working perfectly.
John. |
|