How to set ItemsSource value of ColumnSeries?

306 Views Asked by At

I am not able to set ItemsSource value of ColumnSeries. I am following some examples (this and this) but they seem to be out dated.

Here is my XAML:

<Charting:Chart x:Name="ColumnChart"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Width="Auto"
                Height="Auto">
    <Charting:ColumnSeries Title="Georgi Kyuchukov"
                           Margin="0"
                           Name="ColumnChartSeries"
                           IndependentValuePath="Name"
                           DependentValuePath="Pts"
                           IsSelectionEnabled="True" />
</Charting:Chart>

and here is my C# code:

public class ChartData
{
    public string Name { get; set; }
    public int Pts { get; set; }
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    List<ChartData> personalData = (List<ChartData>)e.Parameter;

    foreach (ChartData x in personalData){
        Debug.WriteLine(x.Name + " " + x.Pts);
    }

    (ColumnChart.Series[0] as ColumnSeries).ItemsSource = personalData;
    //ColumnChartSeries.ItemsSource = personalData;
}

I am getting the following error:

Error 1 The type or namespace name 'ColumnSeries' could not be found (are you missing a using directive or an assembly reference?)

I have also try:

ColumnChartSeries.ItemsSource = personalData;

But get:

An exception of type 'System.NullReferenceException' occurred in gotqn.exe but was not handled in user code.

Also, I am getting the following error often:

Error 1 A value of type 'ColumnSeries' cannot be added to a collection or dictionary of type 'Collection`1'.

but I am able to run the application, so I guess it is not critical.

Could you tell what I am doing wrong?

Also, I will be grateful for being given some good up-to-dated documentation link/article.

1

There are 1 best solutions below

0
On BEST ANSWER

Perhaps you're missing this in your code behind...

using WinRTXamlToolkit.Controls.DataVisualization.Charting;

Try moving your cursor to ColumnSeries and press Alt+Shift+F10 to add the missing namespace. Or simply use Alt+Enter if you have ReSharper (which I recommend).