Ganesh Cauda
Ganesh Cauda

Reputation: 1016

winRT XAML Toolkit Data Visualization Windows Phone 8.1

I try to implement WinRT XAML Toolkit Data Visualization I have a Grouped List of Data

 ObservableCollection<Notes> items = await App.DataModel.GetNotes();

        var groupedData = (from data in items
                           group data by data.Title into g
                           orderby g.Key
                           select new Group<string, Notes>
                           {
                               Key = g.Key.ToString(),
                               Items = g.ToList()
                           }).ToList();

        List<GroupedDataType> groupedList2 = new List<GroupedDataType>();

        foreach (var item in groupedData)
        {
            int results = 0;
            foreach (var rslt in item.Items)
            {
                results += rslt.Result;
            }

            groupedList2.Add(new GroupedDataType(results, item.Items[0].Title));
        }
        PieChart.ItemsSource= groupedList2; 

The Class:

 public GroupedDataType(int totalresult, string type)
    {
        TotalResult = totalresult;
        Type = type;
    }

    public int TotalResult { get; set; }
    public string Type { get; set; }

The XAML Code :

 <Charting:PieSeries x:Name="PieChart"
                     HorizontalAlignment="Stretch"
                     VerticalAlignment="Stretch"
                     IndependentValueBinding="{Binding Type}"
                     DependentValueBinding="{Binding TotalResult}">
                </Charting:PieSeries>

But it doesn't show any chart, please help me know if I did something wrong with my code,

Thank you.

Upvotes: 1

Views: 761

Answers (1)

Barnstokkr
Barnstokkr

Reputation: 3129

I haven't worked with PieCharts, but in general you bind to a collection ItemsSource="{Binding groupedList2}"

<Charting:Chart x:Name="MyPie" Title="Results" Width="400" > 
        <Charting:PieSeries ItemsSource="{Binding groupedList2}" IndependentValuePath="Type"
            DependentValuePath="TotalResult"> 
        </Charting:PieSeries> 
</Charting:Chart>

Something like this.

And if you change the binding as you did in: (which I would remove since you are going to bind from the start and you are using an observable collection)

PieChart.ItemsSource= groupedList2;

You should implement a notification to the xaml to tell it to re-render.

public class YourClass : INotifyPropertyChanged

Again, I haven't worked with Pie Charts

Upvotes: 1

Related Questions