WPF工具包图表无序线系列

WPF工具包图表无序线系列,wpf,charts,wpftoolkit,Wpf,Charts,Wpftoolkit,默认LineSeries实现按独立值对数据点进行排序。对于这样的数据,这给了我奇怪的结果: 是否可以在点之间按原始顺序绘制直线系列?我目前通过继承直线系列解决了这一问题: class UnorderedLineSeries : LineSeries { protected override void UpdateShape() { double maximum = ActualDependentRangeAxis.GetPlotAreaCoordinate(

默认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);
    }
}
类无序LineSeries:LineSeries
{
受保护的覆盖void UpdateShape()
{
双倍最大值=ActualDependentRangeAxis.GetPlotArea坐标(
ActualDependentRangeAxis.Range.Maximum)值;
Func PointCreator=数据点=>
新点(
实现独立轴。GetPlotArea坐标(
dataPoint.RealizationIndependentValue).Value,
最大值-ActualDependentRangeAxis.GetPlotArea坐标(
dataPoint.ActualDependentValue).Value);
IEnumerable points=Enumerable.Empty();
如果(最大值)
{
//原始实现在这里执行排序
points=ActiveDataPoints。选择(PointCreator);
}
更新ShapeFromPoints(点);
}
布尔曲线图(双值)
{
return!double.IsNaN(值)&&
!double.IsNegativeInfinity(值)&&
!double.IsPositiveInfinity(值)&&
!double.IsInfinity(值);
}
}
结果:

值得指出的是,要使用上面@Hansmad的建议,您需要创建一个新名称空间,并将XAML指向该名称空间,而不是程序集。 i、 e

XAML:

xmlns:chart="clr-namespace:MyApplication.UserControls.Charting"
using System.Windows.Controls.DataVisualization.Charting;
using System.Windows;

namespace MyApplication.UserControls.Charting {

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

    class UnorderedLineSeries : LineSeries {
     ....
    }      
}
C#:

xmlns:chart="clr-namespace:MyApplication.UserControls.Charting"
using System.Windows.Controls.DataVisualization.Charting;
using System.Windows;

namespace MyApplication.UserControls.Charting {

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

    class UnorderedLineSeries : LineSeries {
     ....
    }      
}

@FrancescoDS,已经晚了一年多了,但我已经在下面粘贴了如何使用它