Contact Support
Populating Data
3 Sep 20202 minutes to read
SfChart
control can be configured with data points using ItemsSource
property of ChartSeries
. You can assign a collection of custom objects to the ItemsSource
property. In this case, you need to set the XBindingPath
and YBindingPath
properties of chart series with the property names of the custom object which contains the x-value/category and y-value respectively.
NOTE
While using custom objects,
XBindingPath
property is required for all types of chart series. You need to setYBindingPath
property only for theXYDataSeries
types which needs single y-value for a data point. For example, Line, Spline, Column, Bar, Pie etc. ForBubbleSeries
type, you need to set bothYBindingPath
andSize
properties since it requires two y-values to plot a single bubble data point. In the case of financial series types like Candle and HiLoOpenClose, which requires four y-values for a single data point, you need to setHigh
,Low
,Open
andClose
properties with the property names of a custom object which contains respective values.
Following code snippet illustrates this,
[C#]
public class ChartData
{
public ChartData(string demand, double year2010, double year2011)
{
this.Demand = demand;
this.Year2010 = year2010;
this.Year2011 = year2011;
}
public string Demand { get; set; }
public double Year2010 { get; set; }
public double Year2011 { get; set; }
}
[C#]
ObservableCollection<ChartData> demands = new ObservableCollection<ChartData>();
demands.Add(new ChartData("Jan", 42, 27));
demands.Add(new ChartData("Feb", 44, 28));
demands.Add(new ChartData("Mar", 53, 35));
demands.Add(new ChartData("Apr", 64, 44));
demands.Add(new ChartData("May", 75, 54));
chart.Series.Add (new ColumnSeries () {
ItemsSource = demands,
XBindingPath = "Demand",
YBindingPath = "Year2010"
});