1

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

 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>

但它没有显示任何图表,请帮助我知道我的代码是否有问题,

谢谢你。

4

1 回答 1

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 实施通知以告诉它重新呈现。

public class YourClass : INotifyPropertyChanged

同样,我没有使用饼图

于 2015-03-26T10:36:36.503 回答