Back to Devexpress

LineSeries2D Class

wpf-devexpress-dot-xpf-dot-charts-dot-lineseries2d.md

latest9.9 KB
Original Source

LineSeries2D Class

Represents the 2D Line series.

Namespace : DevExpress.Xpf.Charts

Assembly : DevExpress.Xpf.Charts.v25.2.dll

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
public class LineSeries2D :
    SegmentSeries2DBase,
    ISupportMarker2DHitTest,
    ISupportMarker2D,
    ILineSeries,
    IGeometryHolder
vb
Public Class LineSeries2D
    Inherits SegmentSeries2DBase
    Implements ISupportMarker2DHitTest,
               ISupportMarker2D,
               ILineSeries,
               IGeometryHolder

Example

The following example demonstrates how to create a 2D Line chart. To do this, it is necessary to assign the ChartControl.Diagram property to XYDiagram2D, and then add a LineSeries2D object with points to the diagram’s Diagram.Series collection.

Also, this example shows how to add a legend (showing series names) to a chart.

View Example

csharp
<Window x:Class="Line2DChart.Window1" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts" 
        xmlns:local ="clr-namespace:Line2DChart"
        Title="Window1" Height="350" Width="620">
    <Grid>
        <dxc:ChartControl Name="chartControl1">
            <dxc:ChartControl.DataContext>
                <local:ChartViewModel/>
            </dxc:ChartControl.DataContext>
            <dxc:ChartControl.Diagram>
                <dxc:XYDiagram2D>
                    <dxc:XYDiagram2D.Series>
                        <dxc:LineSeries2D DisplayName="Day Temperature" 
                                          DataSource="{Binding DataPoints}" 
                                          ArgumentScaleType="DateTime"
                                          ArgumentDataMember="Time"
                                          ValueDataMember="Value"
                                          LabelsVisibility="True"
                                          CrosshairLabelPattern="{}{A:MMMM}: {V:f2}&#176;C"
                                          MarkerSize="14" 
                                          MarkerVisible="True">
                            <dxc:LineSeries2D.MarkerModel>
                                <dxc:RingMarker2DModel/>
                            </dxc:LineSeries2D.MarkerModel>
                            <dxc:LineSeries2D.Label>
                                <dxc:SeriesLabel TextPattern="{}{V:f1}" 
                                                 dxc:MarkerSeries2D.Angle="90" 
                                                 ConnectorVisible="False"/>
                            </dxc:LineSeries2D.Label>
                        </dxc:LineSeries2D>
                    </dxc:XYDiagram2D.Series>
                </dxc:XYDiagram2D>
            </dxc:ChartControl.Diagram>
            <dxc:ChartControl.Legend>
                <dxc:Legend HorizontalPosition="Left"/>
            </dxc:ChartControl.Legend>
        </dxc:ChartControl>
    </Grid>
</Window>
csharp
using System;
using System.Collections.Generic;
using System.Windows;

namespace Line2DChart {

    public partial class Window1 : Window {
        public Window1() {
            InitializeComponent();
        }
    }
    public class ChartViewModel {
        List<DataPoint> dataPoints;
        public List<DataPoint> DataPoints {
            get {
                if (dataPoints == null) {
                    dataPoints = new List<DataPoint> {
                            new DataPoint (new DateTime(2021, 1, 1), 7.2),
                            new DataPoint (new DateTime(2021, 2, 1), 8.3),
                            new DataPoint (new DateTime(2021, 3, 1), 12.2),
                            new DataPoint (new DateTime(2021, 4, 1), 15.6),
                            new DataPoint (new DateTime(2021, 5, 1), 19.6),
                            new DataPoint (new DateTime(2021, 6, 1), 22.7),
                            new DataPoint (new DateTime(2021, 7, 1), 25.2),
                            new DataPoint (new DateTime(2021, 8, 1), 25),
                            new DataPoint (new DateTime(2021, 9, 1), 21.1),
                            new DataPoint (new DateTime(2021, 10, 1), 16.3),
                            new DataPoint (new DateTime(2021, 11, 1), 10.8),
                            new DataPoint (new DateTime(2021, 12, 1), 7.5)
                };
                }
                return dataPoints;
            }
        }
    }
    public class DataPoint {
        public DateTime Time { get; set; }
        public double Value { get; set; }
        public DataPoint(DateTime time, double value) {
            this.Time = time;
            this.Value = value;
        }
    }
}
vb
Imports System
Imports System.Collections.Generic
Imports System.Windows

Namespace Line2DChart

    Public Partial Class Window1
        Inherits Window

        Public Sub New()
            Me.InitializeComponent()
        End Sub
    End Class

    Public Class ChartViewModel

        Private dataPointsField As List(Of DataPoint)

        Public ReadOnly Property DataPoints As List(Of DataPoint)
            Get
                If dataPointsField Is Nothing Then
                    dataPointsField = New List(Of DataPoint) From {New DataPoint(New DateTime(2021, 1, 1), 7.2), New DataPoint(New DateTime(2021, 2, 1), 8.3), New DataPoint(New DateTime(2021, 3, 1), 12.2), New DataPoint(New DateTime(2021, 4, 1), 15.6), New DataPoint(New DateTime(2021, 5, 1), 19.6), New DataPoint(New DateTime(2021, 6, 1), 22.7), New DataPoint(New DateTime(2021, 7, 1), 25.2), New DataPoint(New DateTime(2021, 8, 1), 25), New DataPoint(New DateTime(2021, 9, 1), 21.1), New DataPoint(New DateTime(2021, 10, 1), 16.3), New DataPoint(New DateTime(2021, 11, 1), 10.8), New DataPoint(New DateTime(2021, 12, 1), 7.5)}
                End If

                Return dataPointsField
            End Get
        End Property
    End Class

    Public Class DataPoint

        Public Property Time As Date

        Public Property Value As Double

        Public Sub New(ByVal time As Date, ByVal value As Double)
            Me.Time = time
            Me.Value = value
        End Sub
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the LineSeries2D class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-charts-custom-draw-crosshair-cursor/CS/CrosshairCustomDraw/MainWindow.xaml#L24

xml
</dxc:XYDiagram2D.AxisX>
<dxc:LineSeries2D DisplayName="Series1">
    <dxc:SeriesPoint Argument="1" Value="50"/>

wpf-bind-a-range-control-to-a-chart-control/CS/GoldPrices/MainWindow.xaml#L69

xml
</dxc:XYDiagram2D.AxisY>
<dxc:LineSeries2D x:Name="series"
                  DisplayName="Gold Price"

Implements

ILegendVisible

ISupportMarker2D

Inheritance

Show 20 items

Object DispatcherObject DependencyObject Visual UIElement FrameworkElement Control ChartElementBase ChartElement Series XYSeries XYSeries2D MarkerSeries2D SegmentSeries2DBase LineSeries2D LineScatterSeries2D

LineStackedSeries2D

LineStepSeries2D

SplineSeries2D

LineFullStackedSeries2D

See Also

LineSeries2D Members

DevExpress.Xpf.Charts Namespace