Search code examples
wpfinfragisticsxamdatachart

Using value member object's property on Infragistics StackedFragmentSeries


I'm trying to create a xamDataChart with StackedColumnSeries. In my use case I need to be able to create variable number of StackedColumnSeries and StackedFragmentSeries so I'm creating everything in code behind. StackedColumnSeries ItemsSource is set to a list of dictionaries. Everything works fine if dictionaries have decimal values. But I need them to have object values and fetch the final value from that object. And I can't get it right, the chart just shows empty so the ValueMemberPath must not be working correctly.

Here's an example code demonstrating the problem:

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();

The TestPoint class used in above example:

class TestPoint
{
    public decimal PointValue { get; set; }

    public TestPoint (decimal value)
    {
        PointValue = value;
    }
}

I'm using Infragistics version 14.2 (the problem did not occur on Infragistics 13.1).


Solution

  • I got it working by changing ValueMemberPath from ValueMemberPath = "[Serie1].PointValue" to ValueMemberPath = "[Serie1][PointValue]".