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

Message ListMessage List     Post MessagePost Message

  Interpolation methods for line plots?
Posted by Tim on Jul-27-2016 23:24
Attachments:
I use two DoubleArrays (X1, X2) to store two groups of samples and make a simple plot, but one DoubleArray X1 has full samples while the other X2 not. I wish to ask whether the ChartDirector has already included some handy interpolation methods for this, so gaps in X2 will be automatically interpolated and populated before plotting. I prefer a linear interpolation. Before making my own one, I'd check with you first. Thanks
2016-07-28.jpg

  Re: Interpolation methods for line plots?
Posted by Peter Kwan on Jul-28-2016 01:16
Hi Tim,

In your chart, it appears X2 includes some samples that are zero in value. May be they are the "missing samples" in X2, and that your data arrays are initialized to 0, so non-existing samples become 0.

From ChartDirector's point of view, the data value 0 is just the same as any other data value, and ChartDirector cannot know it means non-existing samples, so it can only zero values as zero, just like any other values.

For your case, there are two methods:

(a) Do not include non-existing samples in X2. That means the length of X1 and X2 will be different. This is perfectly OK in ChartDirector as long as your provide both the x and y coordinates of the data points to ChartDirector (that is, your code should use Layer.setXData to provide the x-coordinates of the points).

or

(b) Instead of using zero, please use Chart::NoValue to representing missing points. By default, this will cause the line to be "broken", but you can use LineLayer.setGapColor to ask ChartDirector to join through the missing points. For example:

layer->setGapColor(Chart::SameAsMainColor);

Both (a) and (b) above are equivalent to linear interpolation through the missing points.

There is an example "Missing Data Points" in ChartDirector that illustrates several methods of handling missing points. May be you can use it as a reference.

http://www.advsofteng.com/doc/cdcpp.htm#missingpoints.htm

Hope this can help.

Regards
Peter Kwan

  Re: Interpolation methods for line plots?
Posted by Tim on Jul-28-2016 10:52
Thanks, Peter.

I use the Option (b) you you suggested and it works nicely.

If I change the line layer to spine layer, i.e.

from
// Add a line layer to the chart
LineLayer *layer = c->addLineLayer();

to

// Add a spline layer to the chart
SplineLayer *layer = c->addSplineLayer();

I note the following code is actually not necessary.
layer->setGapColor(Chart::SameAsMainColor);

of course, this result will not be based on linear interpolation.

Thanks again, Tim.