【问题标题】:winRT XAML Toolkit Data Visualization Windows Phone 8.1winRT XAML 工具包数据可视化 Windows Phone 8.1
【发布时间】:2016-05-23 15:45:22
【问题描述】:

我尝试实现 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>

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

谢谢。

【问题讨论】:

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


    【解决方案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
    

    再说一次,我还没有使用过饼图

    【讨论】:

    • 您好 Barn,感谢您的帮助 :PieSeries> 我尝试实现这个,它在调试时工作,但是当我发布时我无法导航到该页面,它说:pieseries 不能添加到 collection1 类型的集合/字典中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多