Example E1208
Visible to All Users

Chart for WinForms - Create a Line Chart

This example shows how to create a Line chart at runtime.

Resulting chart

In this example, you add a Series object to the ChartControl.Series collection and then populate its Series.Points collection with points.

The Chart Control uses the XY-Diagram to display the line series. Cast the ChartControl.Diagram property to the XYDiagram type to access diagram settings. The Chart Control determines the diagram type based on the series that is added first. We recommend that you access the diagram to configure its settings after at least one series is added to the chart.

Note that you can cast the View property of the series to the LineSeriesView type to access line series appearance settings.

Files to Look At

Documentation

More Examples

Does this example address your development requirements/objectives?

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

Example Code

Series_LineChart/Form1.cs(vb)
C#
using System; using System.Windows.Forms; using DevExpress.XtraCharts; using System.Drawing; // ... namespace Series_LineChart { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Create a new chart. ChartControl lineChart = new ChartControl(); // Create a line series. Series series1 = new Series("Series 1", ViewType.Line); // Add points to it. series1.Points.Add(new SeriesPoint(1, 2)); series1.Points.Add(new SeriesPoint(2, 12)); series1.Points.Add(new SeriesPoint(3, 14)); series1.Points.Add(new SeriesPoint(4, 17)); // Add the series to the chart. lineChart.Series.Add(series1); // Set the numerical argument scale types for the series, // as it is qualitative, by default. series1.ArgumentScaleType = ScaleType.Numerical; // Access the view-type-specific options of the series. ((LineSeriesView)series1.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; ((LineSeriesView)series1.View).LineMarkerOptions.Size = 20; ((LineSeriesView)series1.View).LineMarkerOptions.Kind = MarkerKind.Triangle; ((LineSeriesView)series1.View).LineStyle.DashStyle = DashStyle.Dash; // Access the view-type-specific options of the series. ((XYDiagram)lineChart.Diagram).AxisY.Interlaced = true; ((XYDiagram)lineChart.Diagram).AxisY.InterlacedColor = Color.FromArgb(20, 60, 60, 60); ((XYDiagram)lineChart.Diagram).AxisX.NumericScaleOptions.AutoGrid = false; ((XYDiagram)lineChart.Diagram).AxisX.NumericScaleOptions.GridSpacing = 1; // Hide the legend (if necessary). lineChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False; // Add a title to the chart (if necessary). lineChart.Titles.Add(new ChartTitle()); lineChart.Titles[0].Text = "Line Chart"; // Add the chart to the form. lineChart.Dock = DockStyle.Fill; this.Controls.Add(lineChart); } } }

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.