Example E1836
Visible to All Users

Chart for WinForms - Use the SwiftPlot Diagram to Create a Real-Time Chart

The following example shows how to use a Swift Plot series to create a real-time chart at runtime.

The Swift Plot series view type is associated with the Swift Plot Diagram type. Cast your diagram object to this type to access its options.

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

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

Example Code

ASwiftPlotChart/Form1.cs(vb)
C#
using System; using System.Windows.Forms; using DevExpress.XtraCharts; // ... namespace ASwiftPlotChart { public partial class Form1 : Form { public Form1() { InitializeComponent(); } const int interval = 20; Random random = new Random(); int TimeInterval = 10; double value1 = 10.0; Range AxisXRange { get { SwiftPlotDiagram diagram = chartControl1.Diagram as SwiftPlotDiagram; if (diagram != null) return diagram.AxisX.VisualRange; return null; } } double CalculateNextValue(double value) { return value + (random.NextDouble() * 10.0 - 5.0); } void UpdateValues() { value1 = CalculateNextValue(value1); } private void timer1_Tick(object sender, EventArgs e) { Series series1 = chartControl1.Series[0]; if (series1 == null) return; DateTime argument = DateTime.Now; SeriesPoint[] pointsToUpdate1 = new SeriesPoint[interval]; for (int i = 0; i < interval; i++) { pointsToUpdate1[i] = new SeriesPoint(argument, value1); argument = argument.AddMilliseconds(1); UpdateValues(); } DateTime minDate = argument.AddSeconds(-TimeInterval); int pointsToRemoveCount = 0; foreach (SeriesPoint point in series1.Points) if (point.DateTimeArgument < minDate) pointsToRemoveCount++; if (pointsToRemoveCount < series1.Points.Count) pointsToRemoveCount--; series1.Points.AddRange(pointsToUpdate1); if (pointsToRemoveCount > 0) { series1.Points.RemoveRange(0, pointsToRemoveCount); } if (AxisXRange != null) { AxisXRange.SetMinMaxValues(minDate, argument); } } } }

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.