在 Infragistics StackedFragmentSeries 上使用值成员对象的 属性
Using value member object's property on Infragistics StackedFragmentSeries
我正在尝试使用 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();
上例中使用的测试点class:
class TestPoint
{
public decimal PointValue { get; set; }
public TestPoint (decimal value)
{
PointValue = value;
}
}
我使用的是 Infragistics 14.2 版(该问题未在 Infragistics 13.1 上出现)。
我通过将 ValueMemberPath 从 ValueMemberPath = "[Serie1].PointValue"
更改为 ValueMemberPath = "[Serie1][PointValue]"
来让它工作。
我正在尝试使用 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();
上例中使用的测试点class:
class TestPoint
{
public decimal PointValue { get; set; }
public TestPoint (decimal value)
{
PointValue = value;
}
}
我使用的是 Infragistics 14.2 版(该问题未在 Infragistics 13.1 上出现)。
我通过将 ValueMemberPath 从 ValueMemberPath = "[Serie1].PointValue"
更改为 ValueMemberPath = "[Serie1][PointValue]"
来让它工作。