【问题标题】:Binding LineSeries values to object fields将 LineSeries 值绑定到对象字段
【发布时间】:2012-07-18 18:38:11
【问题描述】:

我正在使用 2010 版的 WPF Toolkit for DataVisualization。

如果我想以编程方式创建 LineSeries 图表,这就是我之前所做的。此代码工作并成功绘制数据:

public class TrendData {
    public string Group;
    public IEnumerable<KeyValuePair<DateTime, decimal>> Series;
}
...
//somewhere within my chart update method
foreach (TrendData line in DataCollection) {
   LineSeries l = new LineSeries() {
      DependentValuePath = "Value",
      IndependentValuePath = "Key",
      Title = line.Group,
      ItemsSource = line.Series
   };
   Chart.Series.Add(l);
}

这没有问题。但是,我想将其他值与数据点一起存储,因为我想在鼠标悬停数据点时显示其他信息。所以我天真地尝试了这个:

public class TrendData {
   public string Group;
   public IEnumerable<PointData> Series;
}
public class PointData {
   public DateTime time;
   public decimal rate;
   public int x;
}
...
//somewhere within my chart update method
foreach (TrendData line in DataCollection) {
   LineSeries l = new LineSeries() {
      DependentValuePath = "rate",
      IndependentValuePath = "time",
      Title = line.Group,
      ItemsSource = line.Series
   };
   Chart.Series.Add(l);
}

这不起作用,而是给我一个来自 DataPointSeries 的InvalidOperationException: "No suitable axis is available for plotting the dependent value."

想法?我这样做完全错了吗?

【问题讨论】:

    标签: c# wpf wpftoolkit


    【解决方案1】:

    事实证明这绝对完美。我只是在其他地方的代码中有错字,导致了这种情况。

    【讨论】:

    • 我也收到了这个错误,因为我的 DependentValueBinding 中有错字。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-11
    • 2016-01-06
    • 2020-04-15
    • 2013-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多