|
setDateScale labels |
Posted by Darryl on Aug-04-2011 02:25 |
|
The relevant code for the X axis on a real-time XY chart is here.
// Set a linear date scale based on the timestamp array
c->xAxis()->setDateScale(pDevice->tmTimeStamps[m_nLowerArrayIndex],
pDevice->tmTimeStamps[m_nLowerArrayIndex + m_nNumChartDataElements]);
// Set the X axis label format to month/day hour:minute.
c->xAxis()->setLabelFormat("{value|mm/dd hh:nn}");
tmTimeStamps is an array of Chart::chartTime values.
As you can see from the images below, the left-most label always shows the "oldest" value in the array subset (as it should) but the right-most label stops short of displaying the most "recent" value.
Is there any way to format the labels to show the value at the upper end of the array subset? I've tried changing the tick density, that didn't change the behavior.
Thank you in advance for any advice you can offer.
|
Re: setDateScale labels |
Posted by Peter Kwan on Aug-04-2011 16:39 |
|
Hi Darryl,
For the first chart, the first label is at "15:50", and it seems there is a label every 10 minutes. For the most "recent" value, it is on or after "16:50", or is it "16:49" or earlier? If it is "16:50", there should be a label. If it is "16:49", it is normal that there is no label, because the next label should occur at "16:50".
For example, if you have 1 data point per minutes, and you have 60 data points, then your time range is 59 minutes, and your data points would be from 15:50 to 16:49. It is therefore normal that there is no label at 16:50.
For your case, if there is already have a label 16:40, ChartDirector will not put another label at 16:42, even if it is the most recent value. It may overlap with the previous label, and it may also make the labels looking irregular. ChartDirector will only put the next label at 16:50 if it exists on the axis.
If you really want the "most recent value" on the axis, you may add a mark using Axis.addMark with the "most recent value". In your attached charts, it would not overlap with the previous label. However, in the general case, it can overlap with the previous label as the "most recent value" can be arbitrarily close to the previous label. If you know that the "most recent value" is always far from the previous label (eg. your time range is always 59 minutes), then this method would still work.
Another method is to extend your date scale. Instead of using the "most recent value" as the axis end point, you may use "most recent value + 60" to extend the axis range to 60 minutes.
Hope this can help.
Regards
Peter Kwan |
Re: setDateScale labels |
Posted by Darryl on Aug-06-2011 02:21 |
|
Thank you Peter;
I've tried various methods and I think I'll just leave it as it is... when I set the date scale to encompass 60 or 1440 minutes, I get the behavior above. When I set it to 61 or 1441, the label on the left gets dropped.
It isn't a big deal and, since the chart's size is variable, putting a marker and making sure it is aesthetically pleasing is more trouble than it is worth.
I may add a marker somewhere on the chart or axis noting the date and time of the most recent data update but, again, it is a trivial issue that doesn't warrant a lot of attention.
Thank you very much for your time and consideration. |
Re: setDateScale labels |
Posted by Peter Kwan on Aug-06-2011 17:03 |
|
Hi Darryl,
If you would still like to diagnose the problem, you can add the time range in the x-axis title. In this way, you can see the actual time range used in the setDateScale API. For example:
c->xAxis()->setDateScale(pDevice->tmTimeStamps[m_nLowerArrayIndex],
pDevice->tmTimeStamps[m_nLowerArrayIndex + m_nNumChartDataElements]);
char buffer[1024];
sprintf(buffer, "%f to %f", fmod(pDevice->tmTimeStamps[m_nLowerArrayIndex], 86400),
fmod(pDevice->tmTimeStamps[m_nLowerArrayIndex + m_nNumChartDataElements], 86400));
c->xAxis()->setTitle(buffer);
You can then check if the time range is what you expect and whether it is consistent with the labels on the axis.
(Note: the above code displays the time range as "seconds of day" in the axis title.)
If you want to add a mark to show the last time, you can add the mark on the axis using addMark. For example:
c->xAxis()->addMark(pDevice->tmTimeStamps[m_nLowerArrayIndex + m_nNumChartDataElements], 0xccccff, c->formatValue(pDevice->tmTimeStamps[m_nLowerArrayIndex + m_nNumChartDataElements], "{value|mm/dd hh:nn}"));
Regards
Peter Kwan |
|