|
Min/Max on Y Axis |
Posted by djschorn on Mar-25-2015 23:30 |
|
Hello,
If we configure an axis with : axis.setAutoScale();
Is there a way to get the min/max value,the majorTickInc and minorTickInc before the image generation ?
Thanks |
Re: Min/Max on Y Axis |
Posted by Peter Kwan on Mar-26-2015 00:33 |
|
Hi Djschorn,
Yes. You can use XYChart.layoutAxes to auto-scale the axis, then you can use
Axis.getMinValue, Axis.getMaxValue and Axis.getTicks to get information you need. For
example:
c.layoutAxes();
double maxValue = c.yAxis().getMaxValue(); //or yAxis2 if that axis is being used
double minValue = c.yAxis().getMinValue(); //or yAxis2 if that axis is being used
double[] ticks = c.yAxis().getTicks(); //or yAxis2 if that axis is being used
To determine if a tick is a major or minor tick, you may use Axis.getLabel to get the label at
the tick. If there is a tick with no label, it is a minor tick.
Hope this can help.
Regards
Peter Kwan |
Re: Min/Max on Y Axis |
Posted by djschorn on Mar-28-2015 00:03 |
|
Thanks for this answer.
I try to explain my problem in few words.
I want to allow a user to enter a min and/or a max and/or major Tick and/or minor Thick. If the user does not enter one or several values, let Chart Director do.
In order to do that, I want to :
1. let Chart Director computes "default values" for min/max/thick(s)
2. apply the user min/max/major tick and minor thick (if hehas set them) with a setLinearScale.
With this solution I'm able to to know exactelly where is the min & max values (I need these values to compute a gradient on my bar layer).
3. add bar layer(s) with correct gradients.
For the step 1, my first idea was to add a 'fake bar layer", then let ChartDirector computes values. But I don't know how to remove this "fake layer". Is there a solution ?
If it's not possibile, is there another solution ?
Thanks by advance |
Re: Min/Max on Y Axis |
Posted by Peter Kwan on Mar-31-2015 03:12 |
|
Hi djschorn,
If you want ChartDirector to automatically determine the max and min values, simply use
Chart.NoValue in setLinearScale. For example:
//low limit is 10, upper limit and tick increment are determine by ChartDirector.
c.yAxis().setLinearScale(10, Chart.NoValue);
If you want ChartDirector to automatically determine the tick increment, but you must
set the tick interval to some value, please set it to 0. For the tick increment, the value 0
means the tick increment will be automatically determined. The NoValue means there will
be no tick.
Note that in ChartDirector, if the user wants to specify the tick increment, he must also
specify both the upper and lower limits. It is because the tick increment should depend
on the upper and lower limits. For example, if the axis scale is 0 to 1000, a reasonable
tick increment would be 100. If the the axis scale is 0 to 10, a reasonable tick interval
would be 1. If would not be reasonable to use a tick interval of 100 if the axis scale is 0
to 10. If the user does not even know the axis scale (because he does not specify both
the upper and lower limits), ChartDirector would ignore the tick interval specified by the
user. Instead, ChartDirector would automatically determine the axis scale (by computing
the parameter(s) not specified by the user), and use them to automatically determine the
tick interval.
If you want ChartDirector to automatically determine the min/max/tick, and use them to
fill up the values that the user has not specified, it may need to unreasonable tick
increment. For example, ChartDirector may determine that the min/max/tick to be
0/1000/100. If the user sets the max to 10, the axis scale would then become 0/10/100,
which is not reasonable. However, if you prefer this approach, you can create another
"fake" chart of similar size and data to obtain the min/max/ticks. The "fake" chart only
needs to contain a plot area of similar size and the data. There is no need to have the
other "decorations" (such as the chart title, fancy colors, etc), and there is no need to
actually output it.
Hope this can help.
Regards
Peter Kwan |
Re: Min/Max on Y Axis |
Posted by djschorn on Apr-07-2015 17:47 |
|
Thanks for your answer, I did it with a "fake" image. |
|