我试图绘制一些简单的线图...我想。到目前为止我做到了这一点:
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值。
谷歌向我展示了很多相关的帖子,但没有回答这个问题。有谁知道在哪里可以找到DVC的完整文档:来自WPF工具箱的图表?
您可以从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 };