c# - WPF DVC :Lineseries Style and axes settings using c#

标签 c# wpf xaml data-visualization wpftoolkit

我正在尝试绘制一些简单的折线图……我想。到目前为止,我已经这样做了:

XAML

<DVC:Chart x:Name="DVA_Cycle_Chart" BorderThickness="0" BorderBrush="{x:Null}" >
<DVC:Chart.Axes>
   <DVC:LinearAxis Orientation="X" Title="Zeit"/>
      <DVC:LinearAxis Orientation="Y" Location="Left" Title="Volumenstrom Q "/>
      <DVC:LinearAxis Orientation="Y" Location="Right" Title="Druck p"/>
   </DVC:Chart.Axes>
</DVC:Chart>

这会生成一个图表,其中 x 轴标记为“Zeit”,左侧 y 轴标记为“Volumenstrom Q”,右侧 y 轴标记为“Druck p”。美好的。 现在我添加了两个 Lineseries:

C#

KeyValuePair<double, double>[] single_pressure_KeyValuePair = new KeyValuePair<double, double>[2];
KeyValuePair<double, double>[] single_flow_rate_KeyValuePair = new KeyValuePair<double, double>[2];
   for (int i = 0; i < 2; i++)
      {
       single_pressure_KeyValuePair[i] = new KeyValuePair<double, double>(i, 3);
       single_flow_rate_KeyValuePair[i] = new KeyValuePair<double, double>(i, 4);
      }

     LineSeries single_pressure_LS = new LineSeries();
     single_pressure_LS.Title = "Pressure";
     single_pressure_LS.IndependentValueBinding = new Binding("Key");
     single_pressure_LS.DependentValueBinding = new Binding("Value");
     single_pressure_LS.ItemsSource = single_pressure_KeyValuePair;
     DVA_Cycle_Chart.Series.Add(single_pressure_LS);

     LineSeries single_flow_rate_LS = new LineSeries();
     single_flow_rate_LS.Title = "Flow Rate";
     single_flow_rate_LS.IndependentValueBinding = new Binding("Key");
     single_flow_rate_LS.DependentValueBinding = new Binding("Value");
     single_flow_rate_LS.ItemsSource = single_flow_rate_KeyValuePair;
     DVA_Cycle_Chart.Series.Add(single_flow_rate_LS);

这导致两条简单的水平线!美好的。不幸的是,两条线都与左侧 Y 轴相关,但我想将第一个系列重新定位到左侧,将第二个系列重新定位到右侧 y 轴。我在哪里可以设置这个。我更喜欢在 C# 而不是 XAML 中执行此操作。 额外的小问题:如何设置轴的范围?假设我想绘制 x=0.5 和 x=33.1 之间的 x 值。

Google 给我看了很多相关的帖子,但没有回答这个问题。有谁知道在哪里可以找到 DVC:Chart from WPF Toolbox 的完整文档?

最佳答案

您可以从 XAML 中删除相应的 LinearAxis 代码并在代码隐藏中定义它,如下所示:

    single_pressure_LS.DependentRangeAxis = new LinearAxis {
        Orientation = AxisOrientation.Y,
        Location = AxisLocation.Left,
        Title = "Volumenstrom Q",
        Minimum = 1,
        Maximum = 4 };
    single_flow_rate_LS.DependentRangeAxis = new LinearAxis {
        Orientation = AxisOrientation.Y,
        Location = AxisLocation.Right,
        Title = "Druck p",
        Minimum = 3,
        Maximum = 5 };

enter image description here

关于c# - WPF DVC :Lineseries Style and axes settings using c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42557350/

相关文章:

c# - 如何确定属性是否为 C# 中的用户定义类型?

c# - 从 IList<> 中选择一个随机元素而不是这个元素

c# - ASP.NET MVC 4 表单发布变量在接收 Controller 中为空

c# - 内部 System.Linq.Set<T> 与公共(public) System.Collections.Generic.HashSet<T>

c# - 如何在 C# WPF 中的 MS 访问数据库中存储来自 2 个不同表的数据的数据库中创建表

WPF如何为文本框设置工具提示(在样式文件中)

c# - 滚动 WPF TabItems(不是整个 TabControl)

wpf - 绑定(bind)到附加属性不起作用

c# - 扩展 Button 以制作可重复使用的自定义按钮

.net - XAML 解析异常