1
Vote

How to bind the Dictionary to LineSeries...

description

Hello,

I am very new for .net & WPF, I am not able to bind the data to lineSeries.

I am gone through with some of the examples, but I didn't understand how to bind the data

I need to bind the data which is in the Dictionary.
Plotgraph.cs
internal class Plotgraph : ICommand
    {
        private ViewModel viewModel;

        public Plotgraph(ViewModel viewModel)
        {
            this.viewModel = viewModel;
        }

        public event EventHandler CanExecuteChanged;

        public bool CanExecute(object parameter) => true;

        public void Execute(object parameter)
        {
             viewModel.Model.GetParameterValues(viewModel.SelectedParameter.Name);

        }
    }
I have the chart in Window.xaml
<ChartingControls:Chart Title="Parameter Values v/s TimeStamp" x:Name="GraphPlot" Grid.Row="1" Grid.Column="0">
            <ChartingControls:LineSeries x:Name="ParameterTimeStamp" 
                    Title="{Binding Path=SelectedParameter.Description}" DependentValuePath="Value"
                                         IndependentValuePath="Key" ItemsSource="{Binding PlotParameter}">
            </ChartingControls:LineSeries>
            <ChartingControls:Chart.Axes>
                <ChartingControls:LinearAxis
                        Orientation="X"
                        Title="TimeStamp"
                        Interval="50" Minimum="0" Maximum="{Binding Path=Mission.DataLength}"/>
                <ChartingControls:LinearAxis
                        Orientation="Y"
                        Title="Values"
                        Interval="30" Minimum="{Binding Path=SelectedParameter.MinimumValue}" 
                    Maximum="{Binding Path=SelectedParameter.MaximumValue}"/>
            </ChartingControls:Chart.Axes>
        </ChartingControls:Chart>
the window.cs looks like
public partial class GraphPlotUIWindow : Window
    {
        public GraphPlotUIWindow(IViewModel viewModel)
        {
            InitializeComponent();
            DataContext = viewModel;
        }
    }
I have added PlotParameter in both Iviewmodel and in viewmodel, as below:

IViewModel.cs
Dictionary<int, double> PlotParameter { get; set; }
ViewModel.cs
public Dictionary<int, double> plotparameter;

public Dictionary<int, double> PlotParameter
        {
            get
            {
                return plotparameter;
            }

            set
            {
                plotparameter = Model.GetParameterValues(SelectedParameter.Name);
                OnPropertyChanged(nameof(PlotParameter));
            }
        }
But the dataset is available in Model.cs:
public Dictionary<int, double> ParameterDataSet;


public Dictionary<int, double> GetParameterValues(string name)
        {
           var parameterValues =  tcpServiceClient.GetParameterValues(name);

            ParameterDataSet = new Dictionary<int, double>();

            foreach (var item1 in parameterValues)
            {
                var key = item1.TimeStamp;
                var value = item1.Value;
                ParameterDataSet.Add(key, value);
            }
            return ParameterDataSet;
        }
I have read the example. still I am in dark, I am not getting where I am doing mistake...

Please help me from this,

Thanks in advance...

comments