WPF Toolkit Chart Unordered LineSeries

匿名 (未验证) 提交于 2019-12-03 07:50:05

问题:

The default LineSeries implementation orders data points by independed value. This gives me strange results for data like this:

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

回答1:

I currently solved this by inheriting 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:



回答2:

It's worth pointing out that, to use @hansmaad's suggestion above, you will need to create a new namespace and point your XAML to this, rather than the assembly. i.e.

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 {      ....     }       } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!