Silverlight图表工具包:Generated LineSeries抛出异常

时间:2011-08-05 14:54:40

标签: c# silverlight silverlight-4.0 charts silverlight-toolkit

我有以下问题:
在我们的应用程序中,我们有一个报告列表,其中包含在运行时定义的子类别...
报告的整体结果显示在ColumnSeries中,工作正常。现在我必须在LineSeries中显示子类别的结果以进行直接比较,这不起作用。 这是我到目前为止(代码背后):

foreach (var item in ReportListViewModel.ReportSections)
{
    var series = new LineSeries();
    series.SetBinding(DataPointSeries.ItemsSourceProperty, new Binding("ItemList"));
    series.IndependentValuePath = "Date";
    series.DependentValuePath = item.BindingPath; // points to an existing entry in a Dictionary<string, double>
    series.Title = item.Text;
    chart.Series.Add(series);
}

它运行正常,但是一旦加载了数据,我就会得到一个InvalidOperationException,指出找不到合适的绘制值的轴。

以下工作完全正常(即使它不是我需要的):

foreach (...)
{
    ...
    series.DependentValuePath = "Result" // Result is the dependent property of the ColumnSeries, and I tested it just to make sure it isn't me
    ...
}

2 个答案:

答案 0 :(得分:1)

您是否确保在Sections中第一项的ItemList字典中确实存在“人格”条目。如果没有条目,那么您看到的错误就是您将获得的错误。线系列使用项源中第一个项的值来确定要使用的适当轴。如果该值为null,它将失败,并出现类似于您描述的异常(您的问题中的一个是完全错误的措辞?)。

答案 1 :(得分:1)

我不知道有什么不同,但现在它有效......

foreach (var item in ReportListViewModel.ReportSections)
{
    var series = new LineSeries();
    series.SetBinding(DataPointSeries.ItemsSourceProperty, new Binding("ItemList"));
    series.IndependentValuePath = "Date";
    series.DependentValuePath = item.BindingPath;
    series.Title = item.Text;
    chart.Series.Add(series);
}
相关问题