I also encountered the same question. This is a very common application scenario. However, chart cannot directly support arrays, which makes me feel very stressed and regretful.
Hi Yin,
We would like to inform you that in order to visualize the chart with XBindingPath and YBindingPath, we need two points. Therefore, we suggest declaring a model class to store these values. Then, you can set the values for the XBindingPath and YBindingPath properties in an array using a custom array. Please note that we cannot assign the array value directly in the chart as its behavior.
For your reference, we have provided the code snippet below:
|
public class Model { public string Name { get; set; } public double Value { get; set; } }
public class ViewModel { public Model[] Array { get; set; }
public ViewModel() { Array = new Model[] { new Model { Name = "Item 1", Value = 10.5 }, new Model { Name = "Item 2", Value = 20.3 }, new Model { Name = "Item 3", Value = 15.7 }, new Model { Name = "Item 4", Value = 8.2 }, new Model { Name = "Item 5", Value = 12.9 } }; } } |
|
<chart:ColumnSeries ItemsSource="{Binding Array}" XBindingPath="Name" YBindingPath="Value"> </chart:ColumnSeries> |
Additionally, we would like to let you know that we can also use a dictionary instead of an array. Please refer following code.
|
var dictionary = arr.ToDictionary(x => Array.IndexOf(arr, x)); |
Regards,
Saiyath Ali Fathima M