|
Add Label to trendline |
Posted by Brent on May-25-2011 04:04 |
|
Is there a way to add a label to a trendline? I can add it to a line layer, but the same code doesn't seem to do it for a trend line.
'Line Layer
layerL = c.addLineLayer(data0, &HFF, "Monthly Data", 1)
layerL.addCustomDataLabel(0, 6, "Forecast Units", "Arial", 8, &HFF, 0)
'Trendline to the above line layer
layerT = c.addTrendLayer(data0, &HFF0000, "Trend", 1)
layerT.addCustomDataLabel(0, 6, "Trend", "Arial", 8, &HFF0000, 0) '<-- This doesn't work for me
Thanks in advance.
Brent |
Re: Add Label to trendline |
Posted by Peter Kwan on May-25-2011 18:14 |
|
Hi Brent,
In a normal line chart, only the data points can be labelled. For example, in your code, you put a custom label in the 7th data point. The line or line segments cannot be labelled.
The rule is similar for the trend line chart - that the line cannot be labelled. Since the trend line chart does not plot the data points at all, so we do not label the data points for a trend layer. If you would like to label the data points, it is likely you will add another layer (eg. a line layer or scatter layer) that shows the data points, and you can use that layer for the labels.
For your case, it seems your intention is to label the line, not the data points. There are two methods:
(a) Do not label the line on the line. Instead, use a legend box to associate a text with the line.
(b) Pick any point you want on the trend line (you can use TrendLayer.getSlope and TrendLayer.getIntercept to get the formula of the trend line), then add a transparent scatter layer with that point, and add the label to that scatter layer. For example, in your case, it may be like:
layerT = c.addTrendLayer(data0, &HFF0000, "Trend", 1)
//assume you want to add the label at intersection of x = 6 with the line
Dim layer As ScatterLayer = c.addScatterLayer(new Double() {6}, new Double() { layerT.getSlope() * 6 + layerT.getIntercept() }, "", Chart.SquareSymbol, 1, Chart.Transparent, Chart.Transparent).addCustomDataLabel(0, 0, "Trend", "Arial", 8, &HFF0000, 0)
Hope this can help.
Regards
Peter Kwan |
Re: Add Label to trendline |
Posted by Brent on May-27-2011 00:01 |
|
Thank you for the reply, Peter.
I thought about the legend (option A), but my form has a handful of charts and I wanted to maximize the plot area within each chart, limiting the amount of white space around the chart. I guess I could probably layer the legend within the plot area in a non data filled area.
I went with option B. With some minor tweaking (I'm using VB.NET), I got your code to function. It puts the tag directly above the trendline, which is exactly what I wanted.
I'm just starting to get into Chart Director for one of my applications, so it's nice to know there is great support for the little custom issues I may run across that may not be in the help documentation. Thanks again for your help!
Brent |
|