WPF Toolkit Chart Unordered LineSeries

Standard LineSeries runtimes order data by independent values. This gives me weird results for such data:

Ordered LineSeries

Is it possible to build a line of lines where lines are drawn between points in the original order?

+3
source share
2 answers

Currently, I decided to inherit this from 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);
    }
}

Result: Unordered line series

+5
source

It is worth noting that to use the @ hansmaad suggestion above, you need to create a new namespace and point to it with XAML, not the assembly. i.e.

XAML:

xmlns:chart="clr-namespace:MyApplication.UserControls.Charting"

WITH#

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

namespace MyApplication.UserControls.Charting {

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

    class UnorderedLineSeries : LineSeries {
     ....
    }      
}
0
source

Source: https://habr.com/ru/post/1759566/


All Articles