默认的LineSeries实现按独立值对数据点进行排序。这会导致像这样的数据产生奇怪的结果:
是否可能绘制一条线系列,其中的线是按原始顺序在点之间绘制的?
我目前通过继承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);
}
}
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 {
....
}
}