XYSeries.Data Property
Gets or sets the series data.
Namespace: DevExpress.XamarinForms.Charts
Assembly: DevExpress.XamarinForms.Charts.dll
NuGet Package: DevExpress.XamarinForms.Charts
Declaration
public IXYSeriesData Data { get; set; }
Property Value
Type | Description |
---|---|
IXYSeriesData | An object that supplies data for the series. |
Example
For example, to bind a spline series to data, set its Data property to a SeriesDataAdapter object. Use the adapter’s properties to specify the data source and its fields that contain arguments and values (this series type requires one argument and one value for a data point).
<ContentPage.BindingContext>
<local:MainViewModel/>
</ContentPage.BindingContext>
<dxc:ChartView>
<dxc:ChartView.Series>
<dxc:SplineSeries>
<dxc:SplineSeries.Data>
<dxc:SeriesDataAdapter DataSource="{Binding PowerConsumptionCenterBranch}"
ArgumentDataMember="Time">
<dxc:ValueDataMember Type="Value" Member="Power"/>
</dxc:SeriesDataAdapter>
</dxc:SplineSeries.Data>
</dxc:SplineSeries>
</dxc:ChartView.Series>
</dxc:ChartView>
public class MainViewModel {
public List<SplineDataItem> PowerConsumptionCenterBranch { get; }
public MainViewModel() {
PowerConsumptionCenterBranch = new List<SplineDataItem> {
new SplineDataItem(new DateTime(1, 1, 1, 7, 0, 0), 429),
new SplineDataItem(new DateTime(1, 1, 1, 8, 0, 0), 432),
new SplineDataItem(new DateTime(1, 1, 1, 9, 0, 0), 301),
new SplineDataItem(new DateTime(1, 1, 1, 10, 0, 0), 307),
new SplineDataItem(new DateTime(1, 1, 1, 11, 0, 0), 310),
new SplineDataItem(new DateTime(1, 1, 1, 12, 0, 0), 380),
new SplineDataItem(new DateTime(1, 1, 1, 13, 0, 0), 384),
new SplineDataItem(new DateTime(1, 1, 1, 14, 0, 0), 398),
new SplineDataItem(new DateTime(1, 1, 1, 15, 0, 0), 379),
new SplineDataItem(new DateTime(1, 1, 1, 16, 0, 0), 220),
new SplineDataItem(new DateTime(1, 1, 1, 17, 0, 0), 321),
new SplineDataItem(new DateTime(1, 1, 1, 18, 0, 0), 341),
new SplineDataItem(new DateTime(1, 1, 1, 19, 0, 0), 368),
new SplineDataItem(new DateTime(1, 1, 1, 20, 0, 0), 557),
new SplineDataItem(new DateTime(1, 1, 1, 21, 0, 0), 523),
new SplineDataItem(new DateTime(1, 1, 1, 22, 0, 0), 501),
new SplineDataItem(new DateTime(1, 1, 1, 23, 0, 0), 443)
};
}
}
public class SplineDataItem {
public DateTime Time { get;}
public double Power { get; }
public SplineDataItem(DateTime time, double power) {
Time = time;
Power = power;
}
}
Important
ChartView chooses the X-axis type depending on data in the first series. If you need to explicitly specify argument axis type for the chart or an individual series, use the ChartView.AxisX or Series.AxisX property. The assigned object should be compatible with the series data type. Otherwise, the chart does not display the series.
You can create a custom data adapter. This will help you support custom data supply scenarios. For example, you can generate series points dynamically without a data storage.