Binding Live Data with Variable Y Column

Hi SyncFusion Team, 

I am attempting to bind an ObservableCollection of datapoints that contain a dictionary with a number of y-values. The purpose behind this is to be able to store segments of interest and highlight them on a StackPanel of sfCharts, where the user is able to add or remove plots that contain different sets of data. Below is the structure of the DataPoint object I am using within the observable collection:

public class DataPoint
{
    public double Time { get; set; }
    public int Index { get; set; }
    public Dictionary<string, double> Columns { get; set; }
    public DataPoint(double time, int index)
    {
        this.Time = time;
        this.Index = index;
        this.Columns = new Dictionary<string, double>();
    }
}


I receive an error when attempting to perform the YBindingPath on a FastLineBitmapSeries using the path:
YBindingPath = $"Columns[{dict_key}]"

Is it possible to perform the binding in this way? If not, I am open to alternatives, as long as I can have a variable number of y-paths that are identifiable. I have already attempted with DataViews, but these do not seem compatible as a Series ItemSource. Additionally, I have attempted using DataTables, but I am having difficulty achieving live updates as I take differing slices of the DataTable.

Thank you.


2 Replies

AJ Arul Jenith Berkmans Syncfusion Team October 28, 2024 02:10 PM UTC

Hi Matrix Sensors,

 

We have reviewed your query and would like to inform you that the series ItemsSource supports complex bindings, such as with dictionaries, List<>, and observable collections. We are currently validating whether complex bindings support dictionary types for YBindingPath and will update you with further details within two business days (October 30, 2024).

 

In the meantime, you can refer to the documentation: Seamlessly Load Data from Different Data Sources into WPF Charts

 

Thank you for your understanding.

 

Best regards,

Arul Jenith B.



AJ Arul Jenith Berkmans Syncfusion Team October 30, 2024 12:33 PM UTC

Hi Matrix Sensors,


We have validated the possibilities of complex binding of dictionary to Ybinding path and we regret to inform you that it is currently not possible to set a dictionary value as the YBindingPath directly. However, you can achieve the desired outcome by adding the dictionary value to a model property and then binding that property to the YBindingPath.


Here is an ViewModel code snippet:


public class ChartViewModel

{

    public ObservableCollection<DataPoint> DataPoints { get; set; }


    public ChartViewModel()

    {

        DataPoints = new ObservableCollection<DataPoint>

        {

            new DataPoint(1.0, 0) { Columns = { { "Value1", 10 }, { "Value2", 15 } } },

            new DataPoint(2.0, 1) { Columns = { { "Value1", 20 }, { "Value2", 25 } } },

            new DataPoint(2.0, 2) { Columns = { { "Value1", 30 }, { "Value2", 25 } } },

            new DataPoint(2.0, 3) { Columns = { { "Value1", 10 }, { "Value2", 25 } } },

            // Add more DataPoints as needed

        };


        AddYValue();

    }


    private void AddYValue()

    {

        foreach (DataPoint point in DataPoints)

        {

            if (point.Columns.Count > 0)

            {

                point.YValue = point.Columns.ContainsKey("Value1") ? point.Columns["Value1"] : 0;

            }

        }

    }

}


Model code snippet:


public class DataPoint

{

    public double Time { get; set; }

    public int Index { get; set; }

    public Dictionary<string, double> Columns { get; set; }


    public double YValue { get; set; }

    public DataPoint(double time, int index)

    {

        this.Time = time;

        this.Index = index;

       this.Columns = new Dictionary<string, double>();

    } 

}



XAML code snippet for series:


…..

<chart:SplineSeries ItemsSource="{Binding  DataPoints}"

                    XBindingPath="Index"

                    YBindingPath="YValue" />

….


Hops this helps you! If you need any further assistance, feel free to ask.



Thank you for your patience and understanding.


Best regards,

Arul Jenith B.


Loader.
Up arrow icon