我正在使用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);
}
这没有问题。但是,我想用数据点存储其他值,因为我想显示有关DataPoint鼠标悬停的其他信息。所以我天真地尝试了这个:
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."
。
想法?我这样做完全错了吗?
答案 0 :(得分:1)
事实证明这完美无缺。我刚刚在其他地方的代码中输入了一个拼写错误。