WPF工具包图表无序LineSeries

han*_*aad 3 wpf charts wpftoolkit

默认的LineSeries实现按固定值对数据点进行排序.这给我这样的数据奇怪的结果:

有序LineSeries

是否可以绘制一个线序列,其中在原始顺序中的点之间绘制线条?

han*_*aad 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);
    }
}
Run Code Online (Sandbox Code Playgroud)

结果: 无序线系列