|
Round values on y axis |
Posted by Sofia on Oct-26-2012 22:00 |
|
Hi,
I have built Stacked bar chart in the application. The y-axis shows the time in minutes but I need time in hours.
That is why I have next funktion used:
barchart->yAxis()->setLabelFormat("{={value}/60|0}:{={value}%60|0}");
but the values are not rounded and it does not look nice.
I have posted a picture of what I have before (1.jpg) and after (2.jpg) using the funktion.
The result that I need is scale something like this: 0, 50:20, 100:20 etc.. instead of
0:0, 83:20, 167:40 etc..
Is there a way to round up the values?
Thank you
|
Re: Round values on y axis |
Posted by Peter Kwan on Oct-26-2012 22:30 |
|
Hi Sofia,
Please use:
c->yAxis()->setDateScale();
If you inform ChartDirector the y-axis is a date/time axis, ChartDirector will choose the labels so that they are divisible by 60 (like 1800, 3600, 4800, etc). Otherwise ChartDirector will choose labels that are divisible by 10 or 100, like 2000, 4000, 6000. So using setDateScale should result in labels that look nice in date/time formatting.
Also, the correct formula is:
"{=({value}-{value}%60)/60}:{value|ss}"
If you use {={value}/60|0}}:{={value}%60|0}, then 45 will be formatted as 1:45. It is because {value}/60 = 0.75, and will be rounded to 1, so the hour part will become 1 instead of 0.
Hope this can help.
Regards
Peter Kwan |
Re: Round values on y axis |
Posted by Sofia on Oct-26-2012 23:23 |
|
Hi Peter,
That is exactly what I needed.
Thank you!!
Sofia |
|