winRT XAML工具包数据可视化Windows Phone 8.1

时间:2015-03-26 01:50:02

标签: c# xaml windows-phone-8.1 winrt-xaml-toolkit

我尝试实现WinRT XAML Toolkit数据可视化 我有一个分组的数据列表

 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; 

班级:

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

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

XAML代码:

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

但它没有显示任何图表,如果我的代码出错了,请帮助我知道,

谢谢。

1 个答案:

答案 0 :(得分:1)

我没有使用过PieCharts,但一般来说你绑定到一个集合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>

像这样。

如果你改变了绑定,就像你在中那样(我会删除它,因为你要从一开始就绑定并使用一个可观察的集合)

PieChart.ItemsSource= groupedList2;

您应该对xaml实施notification以告知它重新渲染。

public class YourClass : INotifyPropertyChanged

同样,我还没有与Pie Charts合作