|
label formats: "1000000" => "1M", "1000" => "1K" |
Posted by Alexey Rybak on Mar-02-2010 18:59 |
|
Hi! Is it possible to use short labels 1M, 1K, 1m instead of 1000000, 1000, 0.001? Can't find anything about this in docs. I use ChartDirector on PHP/Linux box. |
Re: label formats: "1000000" => "1M", "1000" => "1K" |
Posted by Peter Kwan on Mar-03-2010 11:22 |
|
Hi Alexey,
There are many methods, depending on exact what you want to do.
For example, if the label is 0, do you want to show the value of "0" as "0K", "0M" or just "0". If the label is 500, do you want to show it as "0.5K" or "500"? If you have the labels (0, 500, 1000, 1500, 2000), do you want to show (0, 500, 1K, 1500, 2K) or some other ways?
As you can see, you cannot just mention how to format one label. In axis formatting, you need to specify how to format all possible combination of labels, which some of them can be divisible by 1000, and some of them not divisible by 1000, and some of them can be 0.
The API to configure how to format the labels in various case is Axis.setFormatCondition and Axis.setLabelFormat. You may refer to the documentation on Axis.setFormatCondition and Axis.setLabelFormat for details.
Here are some examples:
#format the label as ###K
$c->yAxis->setLabelFormat("{={value}/1000}K");
Another example:
$format the labels as ###K only if all the labels are divisible by 1000
$c->yAxis->setFormatCondition("align", 1000);
$c->yAxis->setLabelFormat("{={value}/1000}K");
Yet another example:
$format the labels as ###K only if the largest label is >= 1000
$c->yAxis->setFormatCondition(">=", 1000);
$c->yAxis->setLabelFormat("{={value}/1000}K");
Hope this can help.
Regards
Peter Kwan |
Re: label formats: "1000000" => "1M", "1000" => "1K" |
Posted by Alexey Rybak on Mar-03-2010 14:12 |
|
Tnanx, Peter!
I will play with setFormatCondition and setLabelFormat, but I'm not sure this is what I was asking. As far as I can understand having
$c->yAxis->setLabelFormat("{={value}/1000}K");
I will get 1K for 1.000 and 1000K for 1.000.000 but not 1M and definitely I won't have 1m for 0.001.
What I said was a very simple thing like RRD does: if you have points with distribution from 0.001 to 1.000.000 in one graph (in log format surely) RRD _automatically_ converts labes into short form - 1m for 0.001, 1K for 1.000, 1M for 1.000.000. This conversion is very simple but is can't be described as simple as "{={value}/1000}K"
In pseudo code this could be solved as a set of rules, not single rule, say,
if Y > 0.0001 and Y < 0.01 then Y = (Y*1000)m
if Y > 100 and Y < 10000 then Y -> (Y/1000)K
if Y > 100000 and Y < 10000000 then Y -> (x/1000000)M
et cetera
Is it possible to do things like this, having 1M, 1K and 1m on a single graph? |
Re: label formats: "1000000" => "1M", "1000" => "1K" |
Posted by Alexey Rybak on Mar-03-2010 14:24 |
|
Sorry, my ranges should be "wider" - to cover the whole axis - but I hope the idea is pretty clear now. |
Re: label formats: "1000000" => "1M", "1000" => "1K" |
Posted by Peter Kwan on Mar-03-2010 21:51 |
|
Hi Alexey,
If you want to implement the rule you described, you may use custom label formatting. It is like:
.... create the chart as usual and adds all the data to the chart ....
#auto-scale the axis to determine the label positions - after this, no more data can be added to the chart
$c->layout();
#the label positions
$ticks = $c->yAxis->getTicks();
for ($i = 0; $i < count($ticks); ++$i) {
$y = $ticks[i];
#your rules in PHP syntax
if ($y > 0.0001 && $y < 0.01) $c->yAxis->addLabel($y, ($y*1000) . "m");
if ($y > 100 && $y < 10000) $c->yAxis->addLabel($y, ($y/1000) . "K");
if ($y > 100000 && $y < 10000000) $c->yAxis->addLabel($y, ($y/1000000) . "M");
}
Hope this can help.
Regards
Peter Kwan |
Re: label formats: "1000000" => "1M", "1000" => "1K" |
Posted by Alexey Rybak on Mar-03-2010 23:30 |
|
thank you very much! |
|