3

默认 LineSeries 实现按独立值对数据点进行排序。对于这样的数据,这给了我奇怪的结果:

Ordered Line系列

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

4

2 回答 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);
    }
}

结果: 无序线系列

于 2013-03-26T13:22:30.550 回答
0

值得指出的是,要使用上述@hansmaad 的建议,您需要创建一个新的命名空间并将您的 XAML 指向它,而不是程序集。IE

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 {
     ....
    }      
}
于 2016-05-05T05:04:02.050 回答