|
Trendline on partial data and chart legend |
Posted by bhill on Oct-20-2012 00:00 |
|
I'm trying to add a trendline to my chart for a partial set of the data. In my case there are 8 datapoints and I want a limited trend on datapoints 2,3,4 (Oct., Nov. Dec.). I found a thread in this forum that lead me down the right path - you basically obscure the latter half of the data by setting the color to trasnsparent, but the issue I have now is that the color bar doesn't show up the legend. I'm using VB.NET.
Dim last3PointsY() As Double = {data0(1), data0(2), data0(3)}
Dim last3PointsX() As Double = {1, 2, 3}
layerT = c.addTrendLayer2(last3PointsX, last3PointsY, c.xZoneColor(3, &HFF0000, Chart.Transparent), "Frcst/OSO Trend")
layerT.setLineWidth(3)
c.addLegend(chtLong.Width - 149, 20, True, "Arial", 8)
As I learned in the earlier post I mentioned, c.xZoneColor(3, &HFF0000, Chart.Transparent) is the code to change the color of the trendline at datapoint 3. As you can see in my attachment, it works well (although I'd like the line to really start in Oct., not Sept. - but I can live with this). The problem is that the legend uses Chart.Transparent as the color and not &HFF0000. Any ideas (hopefully simple) on how to get the right color in the legend?
Thanks in advance,
Brent
|
Re: Trendline on partial data and chart legend |
Posted by Peter Kwan on Oct-23-2012 00:31 |
|
Hi bhill,
The code I suggest is:
'Add the trend line visible only between last3PointsX(0) and last3PointsX(Ubound(last3Points)
layerT = c.addTrendLayer2(last3PointsX, last3PointsY, c.xZoneColor(last3PointsX(Ubound(last3Points)), c.xZoneColor(last3PointsX(0), Chart.Transparent, &HFF0000), Chart.Transparent), "Frcst/OSO Trend")
layerT.setLineWidth(3)
'Do not use layerT for the legend entry. Add another empty layer to generate the legend entry
layerT = c.setLegendOrder(Chart.NoLegend);
c.addTrendLayer(Nothing, &HFF0000, "Frcst/OSO Trend").setLineWidth(3)
Hope this can help.
Regards
Peter Kwan |
Re: Trendline on partial data and chart legend |
Posted by bhill on Oct-23-2012 01:48 |
|
That pretty much did it ... I had to make one minor adjustment:
layerT = c.setLegendOrder(Chart.NoLegend);
changed to:
layerT.setLegendOrder(Chart.NoLegend)
I think setlegendOrder is a member of Layer and not Chart, unless you have a different version of the software that accounts for it. Nevertheless, I got it to work. Also, the modification on the trendline to visually appear only on my datapoints Oct-Dec worked perfect too.
Thank you for your reply and great advice, Peter!
Brent |
Re: Trendline on partial data and chart legend |
Posted by Peter Kwan on Oct-23-2012 04:17 |
|
Hi bhill,
Sorry for the mistake. Your code is absolutely the correct one.
Regards
Peter Kwan |
|