繁体   English   中英

Winforms图表未按升/降序显示x轴标签

[英]Winforms Chart not displaying x-axis labels in ascending/descending order

在此处输入图片说明

.net桌面应用程序接收来自微控制器的响应,并根据时间间隔将数据绘制到图形上。 如果查看带有红色圆圈的x轴标签,则不会按有序方式找到它们。 例如。 -20.0应该在-20.4之前。 问题是,如果您查看代码:

   chart1.Series[0].Points.AddXY(rLabData[0], rLabData[1]);

根据msdn doc的“ AddXY”:将DataPoint对象添加到集合的末尾,并带有指定的X值和Y值。 这是问题所在,我不希望将数据点添加到先前结果的末尾,而是希望在比例尺定义的X轴的最大值和最小值之内添加数据。 ,但是在固定间隔的基础上,winform中的图表不会显示期望的结果。

您的第一个问题可以得到解答:如果您不想在Points集合的末尾添加新的DataPoints ,则需要在正确的位置插入它们。

这是将DataPoint(yourXValue, yourYValue)插入到Series S的示例:

    // we try to find the DataPoint right after our X-Value:
    DataPoint dp = S.Points.FirstOrDefault(p => p.XValue > yourXValue);
    if (dp != null)
    {
        // got it, so we insert before it..
        int index = S.Points.IndexOf(dp);
        if (index >= 0) S.Points.InsertXY(index, yourXValue, yourYValue);
    }
    // no, so we add to the end
    else S.Points.AddXY(yourXValue, yourYValue);

不幸的是,我怀疑您的Label问题确实是由添加引起的。

  • 您的图表看起来像是ChartType.Point 对于此类型,不显示DataPoints的顺序,这与其他类型(例如Line 。)相反。

  • 并且,除非添加(错误) CustomLabels ..,否则Labels任何类型都不应乱序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM