|
Custom Y-Axis Label with LOG scale |
Posted by Robert on Dec-21-2013 04:23 |
|
Is it possible to use multiple expressions / formats for a Y-Axis with log scale?
Generally we set the format string as follows:
if ($max >= 10000 && $max < 1000000) {
$format = "{=({value}/1000) - (({value}%10)/1000)}K";
}
elsif ($max >= 1000000 && $max < 1000000000) {
$format = "{=({value}/1000000) - (({value}%10000)/1000000)}M";
}
elsif ($max < 1000000000000 && $max >= 1000000000) {
$format = "{=({value}/1000000000) - (({value}%10000000)/1000000000)}G";
}
elsif ($max < 1e15 && $max >= 1e12) {
$format = "{=({value}/1e12) - (({value}%1e10)/1e12)}T";
}
...which works great for a linear graph to show useful "units".
However the labels on a log graph covering a lot of disk space end up like this:
0T, 0T, 0T, 0T, 0.01T, 0.1T, 1T, 10T, 100T
I'd prefer that the y-axis graphs looked more like this:
1M, 10M, 100M, 1G, 10G, 100G, 1T, 10T, 100T
It seems tricky because there's no ternary support (so I have to perform the case-
statement in perl, not chartdir expressions), and I want to change the TEXT more than the
VALUE (K => M => G => T) ... expressions seem to support math on the values with no
way to interact with any of the TEXT portion of the labels.
Thanks! |
Re: Custom Y-Axis Label with LOG scale |
Posted by Peter Kwan on Dec-23-2013 17:01 |
|
Hi Robert,
If your code specify the scale (eg. using Axis.setLogScale2), it can also specify the labels to use, so you can use any labels you want.
If you would like ChartDirector to auto-scale the axis, you may use custom formatting to format the labels. The code is like:
..... create chart as usual ......
// after configuring the chart and adding all the data, can auto-scale the axis
$c->layoutAxes();
// get the label positions chosen by ChartDirector auto-scaling
$ticks = $c->yAxis->getTicks();
for ($i = 0; $i < count($ticks); ++$i)
$c->yAxis->addLabel($ticks[$i], myFormatFunction($ticks[$i]));
In the above, myFormatFunction is a function you write that accepts a number as input and returns a text string. You can use this to format the number using any method you like.
Hope this can help.
Regards
Peter Kwan |
|