Back to Devexpress

Swift Plot Series View

windowsforms-7093-controls-and-libraries-chart-control-series-views-2d-series-views-swift-plot-series-view.md

latest8.5 KB
Original Source

Swift Plot Series View

  • Apr 16, 2023
  • 4 minutes to read

Short Description

The Swift Plot is represented by the SwiftPlotSeriesView object, which belongs to Point and Line series.

This view is intended for quick series rendering, based on a lightened charts generation algorithm. This view is primarily used when it’s required either to display a large amount of data points (tens of thousands and more), and/or create a real-time chart that reflects processes and is updated (by adding new points) in short time spans (e.g. milliseconds). Thanks to the specially introduced algorithm, series of this view type easily manage such tasks with much better performance than any other view.

Note that to provide the best possible performance, the Swift Plot lacks some elements and features available for other view types. These features are listed below.

However, the most important capabilities are still available for the Swift Plot (e.g. panes, secondary axes, financial indicators and regression lines, and the ChartControl.CustomDrawSeries event).

Note

You can also use the SwiftPointSeriesView to quickly render a large number of scatter points.

Chart Type Characteristics

Although the Swift Plot belongs to Point and Line series, it is incompatible with other views of this group, because it uses a special SwiftPlotDiagram type. So, within a single chart control you can only display Swift Plot series, while this limitation doesn’t restrict using multiple Swift Plot series within the same chart (either in a single, or separate panes).

Note

The Swift Plot is designed to process primarily numerical and date-time data. So, the declared performance isn’t guaranteed when the qualitative scale-type is specified for the series SeriesBase.ArgumentScaleType property. For more information, refer to Series Scale Types.

A notable option available for series of this type is the SwiftPlotSeriesView.Antialiasing property, which allows you to enable smooth series drawing.

The table below lists the main characteristics of this chart type.

FeatureValue
Series View typeSwiftPlotSeriesView
Diagram typeSwiftPlotDiagram
Number of arguments per series point1
Number of values per series point1

Example

This example demonstrates how to create a real-time chart (which is updated in a very short period of time), based on the Swift Plot.

Note that this series view type is associated with the Swift Plot Diagram type, and you should cast your diagram object to this type, in order to access its specific options.

csharp
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...

const int interval = 20;
Random random = new Random();
int TimeInterval = 10;
double value1 = 10.0;

AxisRange AxisXRange {
    get {
        SwiftPlotDiagram diagram = chartControl1.Diagram as SwiftPlotDiagram;
        if (diagram != null)
            return diagram.AxisX.Range;
        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);
    }
}
vb
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...

Private Const interval As Integer = 20
    Private random As New Random()
    Private TimeInterval As Integer = 10
    Private value1 As Double = 10.0

    Private ReadOnly Property AxisXRange() As AxisRange
    Get
        Dim diagram As SwiftPlotDiagram = TryCast(chartControl1.Diagram, SwiftPlotDiagram)
        If diagram IsNot Nothing Then
            Return diagram.AxisX.Range
        End If
        Return Nothing
    End Get
End Property

Private Function CalculateNextValue(ByVal value As Double) As Double
    Return value + (random.NextDouble() * 10.0 - 5.0)
End Function

Private Sub UpdateValues()
    value1 = CalculateNextValue(value1)
End Sub

Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles timer1.Tick
    Dim series1 As Series = chartControl1.Series(0)

    If series1 Is Nothing Then
        Return
    End If
    Dim argument As DateTime = DateTime.Now
    Dim pointsToUpdate1(interval - 1) As SeriesPoint
    For i As Integer = 0 To interval - 1
        pointsToUpdate1(i) = New SeriesPoint(argument, value1)
        argument = argument.AddMilliseconds(1)
        UpdateValues()
    Next i
    Dim minDate As DateTime = argument.AddSeconds(-TimeInterval)
    Dim pointsToRemoveCount As Integer = 0
    For Each point As SeriesPoint In series1.Points
        If point.DateTimeArgument < minDate Then
            pointsToRemoveCount += 1
        End If
    Next point
    If pointsToRemoveCount < series1.Points.Count Then
        pointsToRemoveCount -= 1
    End If
    series1.Points.AddRange(pointsToUpdate1)
    If pointsToRemoveCount > 0 Then
        series1.Points.RemoveRange(0, pointsToRemoveCount)
    End If
    If AxisXRange IsNot Nothing Then
        AxisXRange.SetMinMaxValues(minDate, argument)
    End If
End Sub

Tip

A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/e1836/chart-for-winforms-use-the-swiftplot-diagram-to-create-a-real-time-chart.

See Also

Swift Plot Diagram

Swift Point Series View