【问题标题】:WPF Toolkit Data Visualization - How To Set Interval, Minimum and Maximum In Code-Behind?WPF 工具包数据可视化 - 如何在代码隐藏中设置间隔、最小值和最大值?
【发布时间】:2015-11-28 15:17:12
【问题描述】:

首先是我的 xaml

<charting:Chart x:Name="ChartMain" />

这是我的代码:

List<KeyValuePair<string, int>> valueList1 = new List<KeyValuePair<string, int>>();
valueList1.Insert(0, new KeyValuePair<string, int>(DateTime.Now.ToString(), 1));

LineSeries lineSeries1 = new LineSeries();
lineSeries1.Title = "Eins";
lineSeries1.DependentValuePath = "Value";
lineSeries1.IndependentValuePath = "Key";
lineSeries1.ItemsSource = valueList1;
ChartMain.Series.Add(lineSeries1);

我的问题:如何在后面的代码中设置最小值/最大值和间隔?

【问题讨论】:

  • 看看ChartMain.Axes。您在该集合中看到任何可用的轴吗?
  • 是的,我愿意。示例:LinearAxis lx = new LinearAxis(); lx.最小值 = -1; lx.最大值 = +1; lx.Interval = 0.5; ChartMain.Axes.Add(lx);但是编译后我在 Chart 上看不到 ist...
  • 哦,对不起,少了一行:lx.Orientation = AxisOrientation.Y;现在它可以工作了,很好——谢谢!

标签: c# wpf charts wpftoolkit


【解决方案1】:
List<KeyValuePair<string, int>> valueList1 = new List<KeyValuePair<string, int>>();
valueList1.Insert(0, new KeyValuePair<string, int>(DateTime.Now.ToString(), 1));

LineSeries lineSeries1 = new LineSeries();
lineSeries1.Title = "Eins";
lineSeries1.DependentValuePath = "Value";
lineSeries1.IndependentValuePath = "Key";
lineSeries1.ItemsSource = valueList1;
ChartMain.Series.Add(lineSeries1);

LinearAxis linearAxis = new LinearAxis();
linearAxis.Orientation = AxisOrientation.Y;
linearAxis.Minimum = 0;
linearAxis.Maximum = +1;
linearAxis.Interval = 0.1;

ChartMain.Axes.Add(linearAxis);

【讨论】:

  • 我会改用KeyValuePair&lt;DateTime, int&gt;DateTimeAxis
  • KeyValuePair&lt;DateTime, int&gt; 听起来不错!但是我需要两轴吗?一个用于AxisOrientation.X(日期时间),一个用于AxisOrientation.Y(值)?
  • 不是真的,您可以完全按照您目前所做的,只需将LinearAxis 替换为DateTimeAxis
  • 那么AxisOrientation.X; 呢?在我的例子中:AxisOrientation.Y;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-29
  • 2019-02-10
  • 2017-01-07
  • 1970-01-01
  • 2016-04-13
相关资源
最近更新 更多