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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to add custom trend line in Chart?

Platform: WinForms |
Control: Chart |
Published Date: April 30, 2011 |
Last Revised Date: June 25, 2019

 

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow 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.