Articles in this section
Category / Section

How to add custom trend line in Chart?

1 min read

 

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

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied