【问题标题】:WPF Toolkit Chart Unordered LineSeriesWPF 工具包图表无序 LineSeries
【发布时间】:2013-03-16 07:28:01
【问题描述】:

默认 LineSeries 实现按独立值对数据点进行排序。对于这样的数据,这给了我奇怪的结果:

是否可以绘制一个线系列,其中在原始顺序的点之间绘制线?

【问题讨论】:

    标签: wpf charts wpftoolkit


    【解决方案1】:

    我目前通过继承 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);
        }
    }
    

    结果:

    【讨论】:

    • @FrancescoDS,已经晚了一年多,但我已经在下面粘贴了如何使用它。 :)
    【解决方案2】:

    值得指出的是,要使用上面@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 {
         ....
        }      
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-10
      • 2011-12-09
      • 1970-01-01
      • 2011-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-20
      相关资源
      最近更新 更多