Binding Stacked colums series chart to Series

Mar 4, 2011 at 11:27 AM

i, i have big problem with binding Stacked Column Series to my chart.

I have public ObservableCollection Series property in my ViewModel and try by many ways but it still not working.

This is code from ViewModel to prepare Series;

Series.clear();
var dataValues = new List<List<SimpleDataValue>>();

int wartoscNiezalezna = 1;

for (int i = 0; i < 2; i++)
{
dataValues.Add(new List<SimpleDataValue>());
}

foreach (var item in myCollection)
{
var param = someparam;

dataValues[0].Add(new SimpleDataValue { IndependentValue = " " + wartoscNiezalezna, DependentValue = 100 });
//czerwone dataValues[1].Add(new SimpleDataValue { IndependentValue = "" + wartoscNiezalezna, DependentValue = 200 });

wartoscNiezalezna++;

}
var stackedSeries = Activator.CreateInstance(typeof(StackedColumnSeries)) as DefinitionSeries;

int itemnr=0;
foreach (var item in dataValues)
{
var definicja = new SeriesDefinition();
if(itemnr==0)
definicja.Title = "Stan 1";
else definicja.Title = "Stan 2";
definicja.DependentValuePath = "DependentValue";
definicja.IndependentValuePath = "IndependentValue";
definicja.ToolTip = "asdas";
definicja.ItemsSource = item;
stackedSeries.SeriesDefinitions.Add(definicja);
itemnr++;
}
Series.Add(stackedSeries);
}

I cant bind it to:

<charting:Chart x:Name="MyChart"  Padding="10,10,10,10">
        <charting:Chart.Series>
            <charting:StackedColumnSeries>
                <charting:SeriesDefinition ItemsSource="{Binding Series}" DependentValuePath="DependentValue" IndependentValuePath="IndependentValue">
                </charting:SeriesDefinition>
            </charting:StackedColumnSeries>
        </charting:Chart.Series>
    </charting:Chart>

I was trying with SeriesDefinitions Collection and others. I will be very grateful to some help.