Problem creating Line Series dynamically

Oystein Bjorke 10 лет назад 0
This discussion was imported from CodePlex

terry_513 wrote at 2014-01-01 11:47:

Hi,
I am using OxyPlot to achieve few line charts using WPF C#.
Using XML :
I had created Logarithmic & Linear axis as Left & Bottom respectively and 5 line series in xml respectively. I assign each line series ItemSource as List<Point> and it works well.

Now I am to create the same thing dynamically,
I could create both axis properly. And for line series, I add it to the PlotModel as below :
    public void AddData(List<List<Point>> data, string title)
    {
        LineSeries lineSeries;
        int ctr = 0;
        foreach (List<Point> set in data)
        {
            ctr++;
            // Setting the itemsource as set i.e. List<Point>
            lineSeries = new LineSeries { StrokeThickness = 5, MarkerSize = 3, Title = title + " " + ctr, ItemsSource = set };
            PlotModel.Series.Add(lineSeries);
        }
    }
With the above code, I get the plot, 5 titles, but no lines - I guess because somehow data is not set to Points of the line. I also tried :
lineSeries.Points = set;
but this could do as it doesn't accept List<Point>

Why is this difference between creating thru XML and code ? Why their are no lines visible ? Do I need to set or pass data in some other format ?

Can anyone please help me.

terry_513 wrote at 2014-01-01 16:20:

I got the solution,
I need to set DataFieldX = "X", DataFieldY = "Y" in my LineSeries along with ItemSource.

Thanks

Сервис поддержки клиентов работает на платформе UserEcho