Adding a Trendline

Hi,

I am trying to create a chart with one serie that shows the Sales per Month for a particular Customer for the last 24 months.  There is not problem with this and my chart works correctly.  Now I want to add a trend line to this chart, and this is where I dont seem to be able to get it right.  I have searched for a practical example but could not find one.

I am using the following piece of code, but nothing is displayed on my chart.

SalesChart.PaneByName['ChartPane 0'].AddTrendLine(0,0,24,True);

Can someone please guide me in getting this to work?  I also do not understand the startx and endx parameters that you need to pass to the trend line, where would I get these values, or am I correct in assuming that it would be from 0 to 24?

Regards
Marius

The code you are using is correct, did you wrap it with BeginUpdate and EndUpdate?

For each action you do that needs recalculation you need to wrap your statements with BeginUpdate and EndUpdate.

Hello Pieter,

Fantstic, now it works. I did not have the Begin and End Updates.

Just one more question, how can I get the maximum number of x, if my graph is not limited to a certain period of time?

Regards
Marius

Can you explain more in detail?

Is it the X-Axis range you are talking about?

Hi,

Yes, I think it must be the x-axis.

Its specifically the endx integer prameter in the TrendChannel/Line and Moving Avg procedures. Like the 24 I inserted in the example below.

SalesChart.PaneByName['ChartPane 0'].AddTrendLine(0,0,24,True);

Regards
Marius

Each chart has a RangeFrom and RangeTo property.

The trendline is only based on the numbers indexes of the points, if you add 100 points but only display 24 you can add 100 instead of the 24. The trendline will automatically calculated the line and only display the part between 0 and 24.

Changes in data will cause the trendline to be invalid. The trendline then needs to be readded. If you have only one serie the trendline will be the second serie. You can remove the trendline with:

Series[1].Free;

Regards, 
Scheldeman Pieter