Search code examples
c#wpfchartslivecharts

LiveCharts - plotting x&y from lists


I have four lists (x1List, y1List, x2List, y2List) which hold 1000 values each, i want to plot these lists as x & y values using LiveCharts.

i understand how to plot the y values using;

            new LineSeries
            {
                Title = "Series1",
                Values = y1List.AsChartValues(),
                PointGeometry = null
            },

            new LineSeries
            {
                Title = "Series2",
                Values = y2List.AsChartValues(),
                PointGeometry = null
            },

I don't understand how to apply the x values to their respective series.

I'm new to c# so apologies if this is something simple i am overlooking.


Solution

  • You can use an ObserablePoint object to store an X and Y value. Then you can create a ChartValues<ObservablePoint> that will plot what I'm thinking you want to see. Make sure to include the statement for LiveCharts.Defualts namespace;

    using LiveCharts.Defaults;
    
    ChartValues<ObservablePoint> List1Points = new ChartValues<ObservablePoint>();
    
    For(int i = x1List, i < x1List.Count, i++)
    {
        List1Points.Add(new ObservablePoint 
        { 
            X=x1List[i], 
            Y=y1List[i]
        });
    }
    

    Hopefully something like that will work for you.