我正在尝试创建一个具有StackedColumnSeries的xamDataChart。在我的用例中,我需要能够创建可变数量的StackedColumnSeries和StackedFragmentSeries,这样我就可以在代码背后创建所有内容。StackedColumnSeriesItemsSource设置为字典列表。如果字典有十进制值,一切都会正常工作。但我需要它们具有对象值,并从该对象中获取最终值。我搞不清楚,图表只是显示为空,所以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;
}
}
我使用的是Infrastics 14.2版(Infrastics 13.1上没有出现问题)。
我通过将ValueMemberPath从ValueMemberPath = "[Serie1].PointValue"
更改为ValueMemberPath = "[Serie1][PointValue]"
使其工作。