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

Message ListMessage List     Post MessagePost Message

  Clipping the trend lines to not extend to the edge of the plotarea
Posted by Justin Fletcher on Jan-14-2015 20:34
Attachments:
Hiya,

I'm trying to plot a number of datasets on a single graph with different trend lines. In the case I'm looking at, the data is in separate blocks across the time-domain (x-axis). When I plot the data using the LOWESS trend line, the resulting trend line terminates at the bounds of the data that was given. The other trend lines, however, extend to the edge of the plot area.

I'd like to clip the trend lines to the time-domain in a consistent way, but I can't see a way to do that. The attached graphs show the difference between the LOWESS (which is pretty much what I want) and the Linear trend lines (which isn't what I want). Can you suggest a way to do that?

In reality I'm planning on graphing results from different product release tests, but the music charts attached have a similar pattern.
musiccharts-top10-bydecade-lowess.png
musiccharts-top10-bydecade-linear.png

  Re: Clipping the trend lines to not extend to the edge of the plotarea
Posted by Peter Kwan on Jan-14-2015 23:47
Hi Justin,

In ChartDirector, by default, all "trend lines" will be extended to the plot area border,
regardless of where are the data points. This applies to all regression types in the
TrendLayer, such as linear, exponential, logarithmic and polynormial regression. It is because
a common usage of the "trend line" is to analyse the "trend", and it is common to
extrapolate to the future for the future trends. You can limit the x-range of the trend line
by using XYChart.xZoneColor. For example, in Java/C#, it may be like:

// create a color which is blue inside startDate to endDate, and transparent otherwise.
int myTrendColor = c.xZoneColor(startDate, Chart.Transparent, c.xZoneColor(endData,
0x0000ff, Chart.Transparent));

c.addTrendLayer(xData, yData, myTrendColor, ....);

For LOWESS, the usage is usually to "smooth" the data points. It cannot predict trends or
extrapolate data. So it is limited to the data range of the original data.

Hope this can help.

Regards
Peter Kwan

  Re: Clipping the trend lines to not extend to the edge of the plotarea
Posted by Justin Fletcher on Jan-15-2015 01:32
Make it transparent! That's actually quite cute. I hadn't realised that the zones could be transparent.

Thank you, yet again for the fast turnaround and an answer that meets the requirements :-)

  Re: Clipping the trend lines to not extend to the edge of the plotarea
Posted by Justin Fletcher on Jan-15-2015 05:28
Attachments:
Hmm... That works but has an Interesting effect on the legend.

The zone colour appears to apply not only to the region but to the colour of the line in the key as well. So if the line in the key appears in the region that is coloured, it will be visible, but if it appears in the region that is transparent, it will be invisible.

In the examples shown, the trendline legend is coloured according to the data region of the first dataset. So when the first dataset lines up with the position of the legend horizontally, it's visible in red. If the first dataset doesn't line up with the position of the legend, the line is invisible within the legend.

The way I'm going to solve this is to remove the dataset name, so that no legend item appears, and add a fake line layer that has nothing in it, but which has the right colour. Is there a better way to do it, or is this the best solution?

(not knocking the solution of using the zones - it's great, but it just has this side effect I'd not considered)
musiccharts-top10-bydecade-linear-visible.png
musiccharts-top10-bydecade-linear-notvisible.png

  Re: Clipping the trend lines to not extend to the edge of the plotarea
Posted by Peter Kwan on Jan-16-2015 01:09
Hi Justin,

Your suggested method is in fact the best method I can think of - that is, to disable the
automatic legend entry for the trend layer, and then add a dummy line layer to create the
legend.

To disable the automatic legend entry, you can remove the data set name from the trend
layer. However, sometimes the data set name may be needed for other purpose (such as
for tooltips). In this case, you can keep the data set name but to use
Layer.setLegendOrder to disable to automatic legend entry for the trend layer.

Regards
Peter Kwan

  Re: Clipping the trend lines to not extend to the edge of the plotarea
Posted by Justin Fletcher on Jan-16-2015 03:43
I had not tried the tooltips and the like, and appreciate the reminder of that.

Thanks again :-)