|
Formats to support time labels on the axis |
Posted by DC Kelley on Mar-22-2011 08:22 |
|
I am new of CD (and loving it) and see that time, in seconds of a day, is a supported axis format. I can take our "typical" data and treat it as if it occurred on 01-01-0001 CE, but what I would like to do is get the time line values in a HH:MM:SS format and not just the seconds. And I would love to control if the ":SS" or "HH" part was shown based on the overall span of time involved.
I use a line like:
// close to 24 hours, treat as a day, label every hour, tick every 15 min
c->xAxis()->setDateScale(0.0, 86000.0, 3600.0, 900.0);
To get the attached graph, which is close, but would like to also add a line like "01:00am" below the current label of "3600" - and not not sure how to best proceed. While a full 24 hour long run is common, other runs of varying length occur and start and end at arbitrary times. I would like to get this auto-formatting, but may have to develop an algorithm. Thought I would ask first.
And FYI, I do want to keep/display the actual TOD second value, as our users think in those terms. So I am thinking that "setMultiFormat" may be part of the solution, but it seems to effect the format of a single set, not support multiple sets.
And, FYI, we almost never care about the date or data of week.
Do I need to add a second label, or is there some formatting convention I should use to express the time.
To my thinking the ideal label for this need would be two lines like:
3605
01:00:05am
|
Re: Formats to support time labels on the axis |
Posted by Peter Kwan on Mar-23-2011 00:06 |
|
Hi DC Kelley,
You can use something like:
c->xAxis()->setLabelFormat("{value}\\n{value|hh:nna}");
The above formats the labels into two lines. The first line displays the value in numeric format, and the second line displays the same value, but in hh:nna format.
If you have different time spans, I suggest you use something like:
if (duration >= 86000) {
c->xAxis()->setDateScale(0.0, duration, 3600.0, 900.0);
c->xAxis()->setLabelFormat("{value}\\n{value|hh:nna}");
} else if (duration >= ....) {
c->xAxis()->setDateScale(.....);
c->xAxis()->setLabelFormat(.....);
} .....
Hope this can help.
Regards
Peter Kwan |
Re: Formats to support time labels on the axis |
Posted by DC Kelley on Mar-23-2011 03:10 |
|
Works Great! And as you guessed, I have an if/else bit of logic to handle the common ranges sizes and tweak it a bit. I will hang the "start time" off to the side somewhere when that is needed and move on.
My only gripe, a minor one, is can I force the very last major tick mark to have some label text as well? It seems a bit odd to me that a "24 hour run" has a label every 2 hours but does not end up as time 24:00 as a last label. Will I need to adjust the plot area to allow for this as well? |
Re: Formats to support time labels on the axis |
Posted by Peter Kwan on Mar-23-2011 18:25 |
|
Hi DC Kelley,
If your chart covers 24 hours, it should show the last label 00:00am. Note that in your original code, the chart does not cover 24 hours (it only covers 86000 seconds, whereas a day has 86400 seconds), so it is normal there is no label at the 24th hour position.
Also, please note that the "hh" means hour of day. The hour of day is from 1 - 12 if you are using AM/PM format, or 00 - 23 if you are using 24 hour format. "24" is not a valid hour of day number in both cases.
If you would like to show 24:00, perhaps your would like to show "elapsed time", not calendar time or clock time. Instead of using {value|hh:nn}, you may try:
{=({value}-{value}%3600)/3600}:{value|nn}
You may refer to the following link for an explanation of the above:
http://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1299796611#N1299860768
Hope this can help.
Regards
Peter Kwan |
|