ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Adding an 'offset' to the x-axis of time
Posted by DC Kelley on Mar-30-2011 23:54
Attachments:
Is there a clean way to add an static offset value to the X axis when time is used?  I want to use this so do some adaptive scrolling where the data details will change with the current range of data to be displayed.

In other words, if I had a set of data that ran an hour (3600 points), and I wanted to start the graph from the 15th minute (point 900) to some end range (say 1800), and I have re-built my data set to be the displayed data in an array of doubles (from 0 to 899)...  I would want my time to show from 15:00 onwards, not from 00:00 (which is what a time value of zero would result in).

I know I can do this with a set of labels as in
   // Set the labels on the x axis using developed time values / labels with offset
   c->xAxis()->setLabels(DoubleArray(pTime, dataSize),"{value}\\n{value|nn:ss}");
   c->xAxis()->setLabelStep(120);

But managing this list for each scale used, and its display step rate is a problem, and this also demands I create an array with the x axis values. And the tool tips will show the index value of the point not this value.

Is there some way to set the scale with line like
   // ALT: Set the labels on the x axis. using auto-range of labels
   c->xAxis()->setDateScale(startTime, startTime+dataSize, 60.0, 30.0);
   c->xAxis()->setLabelFormat("{value}\\n{value|nn:ss}");

but also tell the chart that data point (0) in all layers should align with the passed start time of the axis?  [The first X axis, item zero, has a value of 900, and should align with the first index point in each layer, not the 900th one - as it does in the below]

The above 2nd fragment results the chart plotting the data from zero to the start point to the left of the axis (outside the plot area, see below), in other words the entire plot is shift to the left by the number of points in the start value.

Perhaps there is some sort of static offset attribute to solve this?
SavedScreenChart.png

  Re: Adding an 'offset' to the x-axis of time
Posted by Peter Kwan on Mar-31-2011 01:35
Hi DC Kelley,

You may try:

//The x-axis scale
c->xAxis()->setDateScale(startTime, startTime+dataSize, 60.0, 30.0);
c->xAxis()->setLabelFormat("{value}\\n{value|nn:ss}");

//This is the y-data you want to plot
Layer *layer = c->addLineLayer(DoubleArray(myData + startTime, dataSize), ....);
//Tell ChartDirector that these data are from startTime to startTime+dataSize
layer->setXData(startTime, startTime+dataSize);

Hope this can help.

Regards
Peter Kwan

  Re: Adding an 'offset' to the x-axis of time
Posted by DC Kelley on Mar-31-2011 03:10

The documentation on Layer.setXData2 is hopeful, looks like that would be the key line for this problem.  This seem like a nice trivial way to start an anchor point and still use the nice auto-layout features and not have the created an manage specific labels.   A quick test produces the desired results, now I just need to keep a pointer to the layer (I had isolated the time axis stuff form the multiple layers that use it).   Many thanks. DCK

Aside: But the line
    ...(DoubleArray(myData + startTime, ...

Implies that I  have in fact created a data array that spans over the full possible span of time and I am just starting on the nth data point.    Can't really do that as the "startTime may span thousands of seconds and its not reasonable in this app to have such a vast empty array preceding the 'real' data (the data to be plotted. I am just copying the data I need from other places as you explained to me when I started all this a week ago.