Back to Devexpress

ChartCalculatedField.FieldType Property

wpf-devexpress-dot-xpf-dot-charts-dot-chartcalculatedfield-75803c45.md

latest7.8 KB
Original Source

ChartCalculatedField.FieldType Property

Gets or sets the type of calculated field values.

Namespace : DevExpress.Xpf.Charts

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

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
public ChartCalculatedFieldType FieldType { get; set; }
vb
Public Property FieldType As ChartCalculatedFieldType

Property Value

Type
ChartCalculatedFieldType

Available values:

Show 12 items

NameDescription
None

Indicates that the field’s type is undefined and determined based on the returned object during chart initialization.

| | String |

Indicates that the field returns a string value as a sequence of UTF-16 code units (the String type).

| | DateTime |

Indicates that the field returns a value expressed as a date and time of day (the DateTime type).

| | TimeSpan |

Indicates that the field returns a value as a time interval (the TimeSpan type).

| | Byte |

Indicates that the field returns an 8-bit unsigned integer value (the Byte type).

| | Int16 |

Indicates that the field returns a 16-bit signed integer value (the Int16 type).

| | Int32 |

Indicates that the field returns a 32-bit signed integer value (the Int32 type).

| | Float |

Indicates that the field returns a single-precision floating-point value (the Single type).

| | Double |

Indicates that the field returns a double-precision floating-point value (the Double type).

| | Decimal |

Indicates that the field returns a decimal value (the Decimal type).

| | Boolean |

Indicates that the field returns a Boolean ( true or false ) value (the Boolean type).

| | Guid |

Indicates that the field returns a global unique identifier value (the Guid type).

|

Remarks

The FieldType property specifies the type of values (Boolean, DateTime, String, etc.) a calculated field returns after its expression is evaluated. The ChartCalculatedFieldType enumeration lists the available types.

Example

The following example shows how to create a calculated field and then use this field as a data source for a series. The field’s values are calculated by the following expression: [Time.Seconds] * [Velocity].

xaml
<dxc:ChartControl x:Name="chartControl">
    <dxc:ChartControl.DataContext>
        <local:ChartViewModel/>
    </dxc:ChartControl.DataContext>
    <dxc:ChartControl.CalculatedFields>
        <dxc:ChartCalculatedField FieldName="Displacement" 
                                  Expression="[Time.Seconds] * [Velocity]" 
                                  FieldType="Double"/>
    </dxc:ChartControl.CalculatedFields>
    <dxc:XYDiagram2D>
        <dxc:SplineSeries2D DisplayName="Series" 
                            DataSource="{Binding DataPoints}"
                            ArgumentDataMember="Time"
                            ValueDataMember="Displacement" 
                            CrosshairLabelPattern="{}{Displacement:f1}" 
                            MarkerVisible="True"/>
        ...
    </dxc:XYDiagram2D>
</dxc:ChartControl>
csharp
using System;
using System.Collections.Generic;
using System.Windows;

namespace CalculatedFields {
    public class ChartViewModel {
        List<DataPoint> dataPoints;
        public List<DataPoint> DataPoints {
            get {
                if (dataPoints == null) {
                    dataPoints = new List<DataPoint> {
                            new DataPoint (new TimeSpan(0, 0, 0), 10),
                            new DataPoint (new TimeSpan(0, 0, 1), 11.46),
                            new DataPoint (new TimeSpan(0, 0, 2), 11.90),
                            new DataPoint (new TimeSpan(0, 0, 3), 12.1),
                            new DataPoint (new TimeSpan(0, 0, 4), 12.236),
                            new DataPoint (new TimeSpan(0, 0, 5), 12.325),
                            new DataPoint (new TimeSpan(0, 0, 6), 12.625),
                            new DataPoint (new TimeSpan(0, 0, 7), 13.896),
                            new DataPoint (new TimeSpan(0, 0, 8), 14.123),
                            new DataPoint (new TimeSpan(0, 0, 9), 14.623),
                            new DataPoint (new TimeSpan(0, 0, 10), 15.007),
                            new DataPoint (new TimeSpan(0, 0, 11), 15.452),
                            new DataPoint (new TimeSpan(0, 0, 12), 15.756)
                };
                }
                return dataPoints;
            }
        }
    }
    public class DataPoint {
        public TimeSpan Time { get; set; }
        public double Velocity { get; set; }
        public DataPoint(TimeSpan time, double velocity) {
            this.Time = time;
            this.Velocity = velocity;
        }
    }
}
vb
Imports System
Imports System.Collections.Generic
Imports System.Windows

Namespace CalculatedFields
    Public Class ChartViewModel
        Private f_DataPoints As List(Of DataPoint)
        Public ReadOnly Property DataPoints As List(Of DataPoint)
            Get
                If f_DataPoints Is Nothing Then
                    f_DataPoints = New List(Of DataPoint) From {
                        New DataPoint(New TimeSpan(0, 0, 0), 10),
                        New DataPoint(New TimeSpan(0, 0, 1), 11.46),
                        New DataPoint(New TimeSpan(0, 0, 2), 11.90),
                        New DataPoint(New TimeSpan(0, 0, 3), 12.1),
                        New DataPoint(New TimeSpan(0, 0, 4), 12.236),
                        New DataPoint(New TimeSpan(0, 0, 5), 12.325),
                        New DataPoint(New TimeSpan(0, 0, 6), 12.625),
                        New DataPoint(New TimeSpan(0, 0, 7), 13.896),
                        New DataPoint(New TimeSpan(0, 0, 8), 14.123),
                        New DataPoint(New TimeSpan(0, 0, 9), 14.623),
                        New DataPoint(New TimeSpan(0, 0, 10), 15.007),
                        New DataPoint(New TimeSpan(0, 0, 11), 15.452),
                        New DataPoint(New TimeSpan(0, 0, 12), 15.756)
                    }
                End If
                Return f_DataPoints
            End Get
        End Property
    End Class
    Public Class DataPoint
        Public Property Time As TimeSpan
        Public Property Velocity As Double
        Public Sub New(ByVal time As TimeSpan, ByVal velocity As Double)
            Me.Time = time
            Me.Velocity = velocity
        End Sub
    End Class
End Namespace

See Also

ChartCalculatedField Class

ChartCalculatedField Members

DevExpress.Xpf.Charts Namespace