如何在 WPF Toolkit 折线图中交换轴?

发布于 2024-12-26 11:02:32 字数 475 浏览 1 评论 0原文

如何交换 WPF 工具包折线图中的轴?我有以下 xaml:

<chartingToolkit:Chart  Name="lineChart" Title="Line Series Demo" Margin="0,0,0,0">
     <chartingToolkit:LineSeries  DependentValuePath="Key" IndependentValuePath="Value" ItemsSource="{Binding}" IsSelectionEnabled="True" />
  </chartingToolkit:Chart>

从属值始终显示为 Y 轴。我需要它们作为 X 轴。这可以通过 WPF Toolkit 图表实现吗?如果我无法使用 WPF Toolkit 执行此操作,是否可以使用其他免费的 WPF 图表库?我所需要的只是能够处理 X 轴上的时间和 Y 轴上的字符串的多个系列的折线图。

How does one swap the axes in a WPF Toolkit line chart? I have the following xaml:

<chartingToolkit:Chart  Name="lineChart" Title="Line Series Demo" Margin="0,0,0,0">
     <chartingToolkit:LineSeries  DependentValuePath="Key" IndependentValuePath="Value" ItemsSource="{Binding}" IsSelectionEnabled="True" />
  </chartingToolkit:Chart>

The dependent values always appear as the Y-axis. I need them as the X-axis. Is this possible with WPF Toolkit charts? If I can't do this with WPF Toolkit, are there other free WPF charting libraries I can use instead? All I need is line chart that can handle multiple series with time on X-Axis and Strings on Y-Axis.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪心 2025-01-02 11:02:32

在尝试使用原始 WPF 工具包找到问题的答案失败后,我决定自己编辑图表工具包源代码。以下是我为了使其正常工作而所做的更改:(

显示源代码更改,要查看原始源代码,请在编辑之前查看原始帖子)

  1. 获取源代码。我正在使用 VS2010,因为一些组件
    从WPF Toolkit已经成为.NET4的一部分,我不得不修改WPF
    工具包解决方案。值得庆幸的是,这些跑腿工作已经为我完成了。
    此处获取源代码

  2. 将 LineSeries.cs:115 更改为

     if (轴 == null)
                    {
                       轴=新的CategoryAxis();
                    } 
    
  3. 将 LineAreaBaseSeries.cs:243 更改为

     double x = ActualIndependentAxis.GetPlotAreaCooperative(dataPoint.ActualIndependentValue).Value;
       double y = this.InternalActualDependentAxis.GetPlotAreaCooperative(dataPoint.ActualDependentValue).Value;
    
       if (ValueHelper.CanGraph(x) && ValueHelper.CanGraph(y))
       {
          dataPoint.Visibility = Visibility.Visible;
    
          双坐标Y = Math.Round(y - (dataPoint.ActualHeight / 2));
          Canvas.SetTop(dataPoint, 坐标Y);
          双坐标X = Math.Round(x - (dataPoint.ActualWidth / 2));
          Canvas.SetLeft(dataPoint, 坐标X);
       }
       别的
       {
          dataPoint.Visibility = Visibility.Collapsed;
       }
    

LineAreaBaseSeries.cs:298 更改为

       Func<DataPoint, Point> createPoint =
           dataPoint =>
               new Point(
                   ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue).Value,
                   this.InternalActualDependentAxis.GetPlotAreaCoordinate(dataPoint.ActualDependentValue).Value);
       IEnumerable<Point> points = Enumerable.Empty<Point>();
       if (ActualIndependentAxis is IRangeAxis)
       {
          points = DataPointsByIndependentValue.Select(createPoint);
       }
       else
       {
          points =
             ActiveDataPoints
                   .Select(createPoint)
                   .OrderBy(point => point.X);
       }

在这些更改之后,您可以使用依赖的字符串源。

干杯!

After unsuccessfully trying to find an answer to my problem with the original WPF Toolkit, I decided to edit the Charting toolkit source myself. Here are the changes that I did in order to get it working:

(Showing source code changes, to see original source, look at the original post prior to edit)

  1. Get the source. I am using VS2010 and since some of the components
    from WPF Toolkit have become a part of .NET4, I had to modify WPF
    Toolkit solution. Thankfully, that legwork was already done for me.
    Get the source here

  2. Change LineSeries.cs:115 To

                    if (axis == null)
                    {
                       axis = new CategoryAxis();
                    } 
    
  3. Change LineAreaBaseSeries.cs:243 To

       double x = ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue).Value;
       double y = this.InternalActualDependentAxis.GetPlotAreaCoordinate(dataPoint.ActualDependentValue).Value;
    
       if (ValueHelper.CanGraph(x) && ValueHelper.CanGraph(y))
       {
          dataPoint.Visibility = Visibility.Visible;
    
          double coordinateY = Math.Round(y - (dataPoint.ActualHeight / 2));
          Canvas.SetTop(dataPoint, coordinateY);
          double coordinateX = Math.Round(x - (dataPoint.ActualWidth / 2));
          Canvas.SetLeft(dataPoint, coordinateX);
       }
       else
       {
          dataPoint.Visibility = Visibility.Collapsed;
       }
    

Change LineAreaBaseSeries.cs:298 To

       Func<DataPoint, Point> createPoint =
           dataPoint =>
               new Point(
                   ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue).Value,
                   this.InternalActualDependentAxis.GetPlotAreaCoordinate(dataPoint.ActualDependentValue).Value);
       IEnumerable<Point> points = Enumerable.Empty<Point>();
       if (ActualIndependentAxis is IRangeAxis)
       {
          points = DataPointsByIndependentValue.Select(createPoint);
       }
       else
       {
          points =
             ActiveDataPoints
                   .Select(createPoint)
                   .OrderBy(point => point.X);
       }

After these changes you can use a dependent source of strings.

Cheers!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文