|
Date/Time format |
Posted by Sai on Nov-12-2012 20:56 |
|
How do I format date/Time?
time labels should be HH:MM
format should actually be automatic as follows
if chart interval is 20 min or less, label should be MM:SS, otherwise HH:MM
I tried following code but this one not working for me
c->xAxis()->setDateScale(viewPortTimeStamps[0], viewPortTimeStamps[0] +
DataInterval * viewPortTimeStamps.len / 1000);
//c->xAxis()->setLabelFormat("{value|hh:nn<*br*>dd}");
c->xAxis()->setFormatCondition("align", 60*60);
c->xAxis()->setLabelFormat("{value|nn:ss<*br*>dd}");
c->xAxis()->setMultiFormat(Chart::StartOfHourFilter(), "<*font=bold*>{value|hh:nn:ss}", Chart::AllPassFilter(), "{value|nn}");
c->xAxis()->setFormatCondition("else");
c->xAxis()->setLabelFormat("{value|hh:nn<*br*>dd/mm}"); |
Re: Date/Time format |
Posted by Peter Kwan on Nov-12-2012 23:26 |
|
Hi Sai,
In your case, your code determines the axis scale (using setDateScale) but does not specify where are the axis labels. ChartDirector will then automatically determine the label positions on the x-axis. Your code specify how to display those labels (the date/time format to use).
The format condition "align, 60 * 60" means that the format should be applied if all of the label positions determined by ChartDirector is at hourly boundary (60 * 60 = 1 hour). If ChartDirector chooses these label positions, it is likely your axis range is much more than 1 hour. So this does not achieve what you mentioned.
To use nn:ss if the chart interval is 20 mins or less, you can simply use:
if (DataInterval * viewPortTimeStamps.len / 1000 <= 20 * 60)
c->xAxis()->setLabelFormat("{value|nn:ss}");
else
c->xAxis()->setLabelFormat("{value|hh:nn}");
Hope this can help.
Regards
Peter Kwan |
Re: Date/Time format |
Posted by Sai on Nov-14-2012 21:03 |
|
Peter, this one not helping me.
I want to know how do I find the number of major tick drawn on my chart how to find the interval between two consecutive intervals(in sec). If I able to find then I can set the time as per my setting
One more query, how do show tool-tip on my chart?
Peter Kwan wrote:
Hi Sai,
In your case, your code determines the axis scale (using setDateScale) but does not specify where are the axis labels. ChartDirector will then automatically determine the label positions on the x-axis. Your code specify how to display those labels (the date/time format to use).
The format condition "align, 60 * 60" means that the format should be applied if all of the label positions determined by ChartDirector is at hourly boundary (60 * 60 = 1 hour). If ChartDirector chooses these label positions, it is likely your axis range is much more than 1 hour. So this does not achieve what you mentioned.
To use nn:ss if the chart interval is 20 mins or less, you can simply use:
if (DataInterval * viewPortTimeStamps.len / 1000 <= 20 * 60)
c->xAxis()->setLabelFormat("{value|nn:ss}");
else
c->xAxis()->setLabelFormat("{value|hh:nn}");
Hope this can help.
Regards
Peter Kwan
|
Re: Date/Time format |
Posted by Peter Kwan on Nov-15-2012 02:45 |
|
Hi Sai,
To obtain the ticks on the chart, first, set up the entire chart (entering all the data, configure all the layers, set the font size, angles, and so on). Then call BaseChart.layout. ChartDirector will then auto-scale the axis based on the available data. You may then use Axis.getTicks to get the tick positions, and use Axis.getLabel to get the label at those positions. If you do not like the labels, you may use Axis.setLabel to change them. May be you can use the code in the following thread as a reference:
http://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1152355156#N1152378417
However, if your intention is to format the labels different based on the spacing between the ticks, a better method is to use setFormatCondition. (In my last message, I did not suggested setFormatCondition because your enquiries mentioned that you would like the labels to be based on the "chart interval", rather than tick spacing.)
To use setFormatCondition based on tick spacing, an example is:
//tick is aligned to day boundary, so no need to show the hh:nn:ss
c->xAxis()->setFormatCondition("align", 24*60*60);
c->xAxis()->setLabelFormat("{value|mmm dd}");
//tick is hourly aligned, so no need to show the nn:ss
c->xAxis()->setFormatCondition("align", 60*60);
c->xAxis()->setMultiFormat(Chart::StartOfDayFilter(),
"<*font=bold*>{value|mmm dd}", Chart::AllPassFilter(), "{value|hh}");
c->xAxis()->setFormatCondition("else");
c->xAxis()->setMultiFormat(Chart::StartOfHourFilter(), "<*font=bold*> {value|hh:nn:ss}", Chart::AllPassFilter(), "{value|nn:ss}");
Hope this can help.
Regards
Peter Kwan |
Re: Date/Time format |
Posted by Sai on Nov-16-2012 17:59 |
|
Thanks a Ton Peter:) |
|