我正在尝试使用StackedColumnSeries创建一个xamDataChart。在我的用例中,我需要能够创建可变数量的StackedColumnSeries和StackedFragmentSeries,所以我在后面的代码中创建了所有内容。 StackedColumnSeries ItemsSource设置为字典列表。如果字典有十进制值,一切正常。但我需要它们具有对象值并从该对象获取最终值。我无法做到正确,图表只显示为空,因此ValueMemberPath必须无法正常工作。
以下是演示此问题的示例代码:
var window = new Window() { Width = 600, Height = 400, WindowStartupLocation = WindowStartupLocation.CenterScreen };
var chart = new XamDataChart();
Axis xAxis = new CategoryXAxis() { ItemsSource = new List<string> { "First", "Second" } };
Axis yAxis = new NumericYAxis() { MinimumValue = 0, MaximumValue = 1000 };
chart.Axes.Add(xAxis);
chart.Axes.Add(yAxis);
// Trying to fetch chart fragment values from value member's property: Does not work.
var testItems = new List<Dictionary<string, TestPoint>>();
var stackedSeries = new StackedColumnSeries() { ItemsSource = testItems, XAxis = xAxis as CategoryXAxis, YAxis = yAxis as NumericYAxis };
stackedSeries.Series.Add(new StackedFragmentSeries() { ValueMemberPath = "[Serie1].PointValue" });
stackedSeries.Series.Add(new StackedFragmentSeries() { ValueMemberPath = "[Serie2].PointValue" });
testItems.Add(new Dictionary<string, TestPoint>() { { "Serie1", new TestPoint(100) }, { "Serie2", new TestPoint(200) } });
testItems.Add(new Dictionary<string, TestPoint>() { { "Serie1", new TestPoint(300) }, { "Serie2", new TestPoint(400) } });
// Value member is decimal and using it directly, works fine.
//var testItems = new List<Dictionary<string, decimal>>();
//var stackedSeries = new StackedColumnSeries() { ItemsSource = testItems, XAxis = xAxis as CategoryXAxis, YAxis = yAxis as NumericYAxis };
//stackedSeries.Series.Add(new StackedFragmentSeries() { ValueMemberPath = "[Serie1]" });
//stackedSeries.Series.Add(new StackedFragmentSeries() { ValueMemberPath = "[Serie2]" });
//testItems.Add(new Dictionary<string, decimal>() { { "Serie1", 100 }, { "Serie2", 200 } });
//testItems.Add(new Dictionary<string, decimal>() { { "Serie1", 300 }, { "Serie2", 400 } });
chart.Series.Add(stackedSeries);
window.Content = chart;
window.ShowDialog();
以上示例中使用的TestPoint类:
class TestPoint
{
public decimal PointValue { get; set; }
public TestPoint (decimal value)
{
PointValue = value;
}
}
我正在使用Infragistics版本14.2(Infragistics 13.1上没有出现此问题)。
答案 0 :(得分:0)
我通过将ValueMemberPath从ValueMemberPath = "[Serie1].PointValue"
更改为ValueMemberPath = "[Serie1][PointValue]"
来实现它。