Example E1245
Visible to All Users

Charts for WinForms - How to Add a Trend Line to a Chart

This example demonstrates how add a Trend Line to the stock chart at runtime. The following image illustrates the resulting UI:

stock-chart

Files to Review

Documentation

More Examples

How to Display a Regression Line for a Series

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Form1.cs(vb)
C#
#region #usings using System; using System.Drawing; using System.Windows.Forms; using DevExpress.XtraCharts; // ... #endregion #usings namespace TrendLines { public partial class Form1 : Form { public Form1 () { InitializeComponent(); } #region #code private void Form1_Load (object sender, EventArgs e) { // Create an empty chart. ChartControl stockChart = new ChartControl(); // Create a stock series, add it to the chart and set its properties. Series series1 = new Series("Series 1", ViewType.Stock); stockChart.Series.Add(series1); series1.ArgumentScaleType = ScaleType.DateTime; series1.ValueScaleType = ScaleType.Numerical; // Add points to the series. series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 1), new object[] { 4.00, 5.00, 5.00, 4.85 })); series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 2), new object[] { 6.05, 8.05, 6.05, 7.05 })); series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 3), new object[] { 6.25, 8.25, 6.75, 7.15 })); // Create and customize a trendline, TrendLine trendline1 = new TrendLine("A Trend"); trendline1.Point1.Argument = new DateTime(1994, 3, 1); trendline1.Point1.ValueLevel = ValueLevel.High; trendline1.Point2.Argument = new DateTime(1994, 3, 3); trendline1.Point2.ValueLevel = ValueLevel.High; trendline1.ExtrapolateToInfinity = false; trendline1.Color = Color.Red; trendline1.LineStyle.DashStyle = DashStyle.Dash; // Cast the view type of the series to the Stock view. StockSeriesView myView = ((StockSeriesView)series1.View); // Define the Y-axis range. myView.AxisY.WholeRange.AlwaysShowZeroLevel = false; // Add the trendline to the series collection of indicators. myView.Indicators.Add(trendline1); // Add the chart to the form. stockChart.Dock = DockStyle.Fill; this.Controls.Add(stockChart); } #endregion #code } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.