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

Message ListMessage List     Post MessagePost Message

  Is It Possible to Set the Position of a DataSet
Posted by Robert on Jul-31-2013 13:23
Hi Peter,

Here is my situation:

I want to create a stacked line chart (fairly sure this is not supported by CD at the moment
right?).

The way I'm doing this is manually add a offset to the ydata for each data set so that the
lines appears to be stacked on each other.
The problem with this is that the values are wrong when the user mouse over the data with
trackline.
To solve this I tried to set all values back to what they were on the JsChartModel. This
fixed the values when mouse over but the position of the data is now incorrect.

I'm wondering is there a way to set the data position in JsChartModel?
Or perhaps there is a better way of creating stacked line chart with CD?

Regards

Robert

  Re: Is It Possible to Set the Position of a DataSet
Posted by Peter Kwan on Jul-31-2013 20:13
Hi Robert,

To create the effect or a stacked line chart, I would use the same method as what you did - simply accumulate the data before passing the data to ChartDirector - as the definition of the "stack" is to accumulate the data.

For example, if the 3 data series are in the arrays data0, data1, and data2, I would simply use:

'accumulate the data first
data1 = (New ArrayMath(data0)).add(data1).result()
data2 = (New ArrayMath(data1)).add(data2).result()

In the browser side, if you use the original sample code for the track cursor, it will display the accumulated data value. If you want the original data value, you just need to display the difference between the current data value and the corresponding data value in the last data set. It is like:

// Iterate through all the data sets in the layer
for (var j = 0; j < layer.getDataSetCount(); ++j)
{
      var dataValue = layer.getDataSet(j).getValue(xIndex);
      if (j > 0)
           dataValue -= layer.getDataSet(j - 1).getValue(xIndex);

      .... display dataValue ....
}

Hope this can help.

Regards
Peter Kwan

  Re: Is It Possible to Set the Position of a DataSet
Posted by Robert on Aug-01-2013 06:45
Hi Peter,

Thanks! Your solution worked perfectly for displaying the correct value from trackline.
Sorry I realized that this is actually quite obvious. I will try to read the sample code a bit
more before posting a question next time :-)

The only issue is that I am trying to get all the lines stacked as close as possible to each
other. So the offsets I am applying are slightly different from what you suggested. But this
should still work. Just need to store them somewhere for each dataset.

Regards

Robert