3

デフォルトのLineSeries実装は、独立した値でデータポイントを並べ替えます。これにより、次のようなデータに対して奇妙な結果が得られます。

注文したLineSeries

元の順序で点の間に線が引かれる一連の線をプロットすることは可能ですか?

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がこれを指すようにする必要があることを指摘しておく価値があります。すなわち

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 に答える