2D Chart for WinForms | ComponentOne
Charting Data / Working with TrendLines / Creating TrendLines
In This Topic
    Creating TrendLines
    In This Topic

    Creating TrendLines at Design Time

    TrendLines can be created at design time using the TrendLine Collection Editor. Using the collection editor, you may add, modify and remove trend lines. For more information on the TrendLine Collection Editor, see TrendLine Collection Editor.

    Creating TrendLines Programmatically

    To create a TrendLine programmatically, create instance of TrendLine object and set its properties. The TrendLine can be created using its constructor or AddNewTrendLine.TrendLinesCollection() method of TrendLinesCollection.

    The following code adds a red TrendLine to ChartGroup(0) of the Chart:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    ' create trend line        
    Dim tl As C1.Win.C1Chart.TrendLine = New C1.Win.C1Chart.TrendLine()
    ' first data series       
    tl.SeriesIndex = 0       
    ' set line color and thickness      
    tl.LineStyle.Color = Color.Red      
    tl.LineStyle.Thickness = 2
    ' show formula in legend    
    tl.Text = "{#FORMULA}"       
    ' add trend to the chart        
    c1Chart1.ChartGroups(0).ChartData.TrendsList.Add(tl)
    

    To write code in C#

    C#
    Copy Code
    // create trend line       
    C1.Win.C1Chart.TrendLine tl = new C1.Win.C1Chart.TrendLine();        
    // first data series       
    tl.SeriesIndex = 0;        
    // set line color and thickness       
    tl.LineStyle.Color = Color.Red;  
    tl.LineStyle.Thickness = 2;     
    // show formula in legend    
    tl.Text = "{#FORMULA}";     
    // add trend to the chart    
    c1Chart1.ChartGroups[0].ChartData.TrendsList.Add( tl);
    

    This topic illustrates the following:

    The red trend line connects the first and last data points.

    See Also