简体   繁体   中英

How to set ItemsSource value of ColumnSeries?

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM