1

我正在尝试编写一个将 XY 值列表绘制到实时图表的代码。有问题的列表已附上,但这里是一个示例:

1 0,01
1,01 0,01
1,02 0,01
1,03 0,01
1,04 0,01
1,05 0,01
1,06 0,01
1,07 0,01
1,08 0,01
1,09 0,01
...
2,45 0,15
2,46 0,15
2,47 0,15
2,48 0,16
2,49 0,16
2,5 0,16
2,51 0,17
2,52 0,17

我正在使用以下代码:

List<double> xValues, yValues;
            GenerateValues(out xValues, out yValues);
            ChartValues<ObservablePoint> ListPoints = new ChartValues<ObservablePoint>();
            for (int i = 0; i < xValues.Count; i++)
            {
                ListPoints.Add(new ObservablePoint
                {
                    X = xValues[i],
                    Y = yValues[i]
                });
            }

            var brush = new SolidColorBrush(Colors.Orange);
            brush.Opacity = 0.25;
            var series = new LineSeries();
            series.Values = ListPoints;
            series.Title = "Pressão";
            series.Stroke = new SolidColorBrush(Colors.OrangeRed);
            series.LineSmoothness = 0;
            series.PointGeometry = null;
            series.Fill = brush;

            var seriesCollection = new SeriesCollection { series };

            if (chart.AxisY[0] != null && chart.AxisY[0].Labels != null)
                chart.AxisY[0].Labels.Clear();
            if (chart.Series != null)
                chart.Series.Clear();
            chart.AxisY[0].Title = "Pressão (bar)";
            chart.AxisX[0].Title = "Tempo (min)";
            chart.Series = seriesCollection;

但是,我得到的结果与文件上的 X 标签不匹配。曲线的形状是正确的,Y 值也是正确的,但 X 值不是。以结果为例:图表结果

谁能帮我理解这种行为?

带有应用程序的 GitHub

4

0 回答 0