WPF工具包图表无序折线系列

3
默认的LineSeries实现按独立值对数据点进行排序。这会导致像这样的数据产生奇怪的结果: Ordered LineSeries 是否可能绘制一条线系列,其中的线是按原始顺序在点之间绘制的?
2个回答

5

我目前通过继承LineSeries来解决这个问题:

class UnorderedLineSeries : LineSeries
{
    protected override void UpdateShape()
    {
        double maximum = ActualDependentRangeAxis.GetPlotAreaCoordinate(
            ActualDependentRangeAxis.Range.Maximum).Value;

        Func<DataPoint, Point> PointCreator = dataPoint =>
            new Point(
                ActualIndependentAxis.GetPlotAreaCoordinate(
                dataPoint.ActualIndependentValue).Value,
                maximum - ActualDependentRangeAxis.GetPlotAreaCoordinate(
                dataPoint.ActualDependentValue).Value);

        IEnumerable<Point> points = Enumerable.Empty<Point>();
        if (CanGraph(maximum))
        {
            // Original implementation performs ordering here
            points = ActiveDataPoints.Select(PointCreator);
        }
        UpdateShapeFromPoints(points);
    }

    bool CanGraph(double value)
    {
        return !double.IsNaN(value) &&
            !double.IsNegativeInfinity(value) &&
            !double.IsPositiveInfinity(value) &&
            !double.IsInfinity(value);
    }
}

结果: 无序线系列

@FrancescoDS,虽然已经晚了一年,但我已经将如何使用此功能粘贴在下面了。 :) - XtraSimplicity

0
值得一提的是,要使用@hansmaad上面的建议,您需要创建一个新的命名空间并将您的XAML指向它,而不是程序集。 即。
XAML:
xmlns:chart="clr-namespace:MyApplication.UserControls.Charting"

C#:

using System.Windows.Controls.DataVisualization.Charting;
using System.Windows;

namespace MyApplication.UserControls.Charting {

    class Chart : System.Windows.Controls.DataVisualization.Charting.Chart {}

    class UnorderedLineSeries : LineSeries {
     ....
    }      
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接