We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to add custom trend line in Chart?

 

TrendLines is used to draw lines in the ChartArea. The Trend Line can be added into the chart by using TrendLineAdder class. Using Mouse Events we can draw trend lines. We use utility class to listen to mouse events and convert them into trend lines. We can draw any number of trend lines and we can set the different colors to differentiate.

C#

// Creating CustomPoints

ChartPoint ptStart = this.chart.ChartArea.GetValueByPoint(start);

ChartPoint ptEnd = this.chart.ChartArea.GetValueByPoint(end);

ChartSeries tseries = this.chart.Model.NewSeries("TrendLine", ChartSeriesType.Line);

tseries.Points.Add(ptStart);

tseries.Points.Add(ptEnd);

this.chart.Series.Add(tseries);

tseries.LegendItem.Visible = false;

// Specify the color for the lines

tseries.Style.Interior = new Syncfusion.Drawing.BrushInfo(ptStart.YValues[0] < ptEnd.YValues[0] ? Color.DarkGreen : Color.Red);

VB

' Creating CustomPoints

Dim tlineAdder As TrendLineAdder

Dim ptStart As ChartPoint = Me.chart.ChartArea.GetValueByPoint(start)

Dim ptEnd As ChartPoint = Me.chart.ChartArea.GetValueByPoint(end_Renamed)

Dim tseries As ChartSeries = Me.chart.Model.NewSeries("TrendLine", ChartSeriesType.Line)

tseries.Points.Add(ptStart)

tseries.Points.Add(ptEnd)

Me.chart.Series.Add(tseries)

tseries.LegendItem.Visible = False

' Specify the color for the lines

If ptStart.YValues(0) < ptEnd.YValues(0) Then

tseries.Style.Interior = New Syncfusion.Drawing.BrushInfo(Color.DarkGreen)

Else

tseries.Style.Interior = New Syncfusion.Drawing.BrushInfo(Color.Red)

End If

Article ID: Published Date: Last Revised Date: Platform: Control:
79 04/30/2011 07/10/2014 WinForms Chart
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon