Windows Universal 10中的饼图

时间:2015-11-10 15:33:34

标签: c# xaml visual-studio-2015 pie-chart windows-10-mobile

我目前正在使用Windows Universal 10 Mobile App

我想画一个饼图..但我找不到任何图表控件..

有关在Windows 10 Universal App中绘制图表的任何建议吗?

非常感谢!

2 个答案:

答案 0 :(得分:4)

安装WinRT XAML工具包 - 来自Nuget的Windows 10数据可视化控件在程序包管理器控制台中运行以下命令

PM> Install-Package WinRTXamlToolkit.Controls.DataVisualization.UWP

然后,在XAML文件中添加实现图表控件所需的命名空间:

xmlns:Charting="using:WinRTXamlToolkit.Controls.DataVisualization.Charting"

现在,您可以使用图表控件:

例如,我画了一个PieChart

<Charting:Chart 
    x:Name="PieChart" 
    HorizontalAlignment="Left" 
    VerticalAlignment="Top" 
    Margin="0" > 
    <Charting:PieSeries Margin="0" 
         IndependentValuePath="Name" 
         DependentValuePath="Amount" 
         IsSelectionEnabled="True"/>
</Charting:Chart>

在我的.cs文件中:

添加命名空间:

using WinRTXamlToolkit.Controls.DataVisualization.Charting;
public class FinancialStuff
{
    public string Name { get; set; }
    public int Amount { get; set; }
}

public MainPage()
{
    this.InitializeComponent();
    this.Loaded += MainPage_Loaded;
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    LoadChartContents();
}

private void LoadChartContents()
{
    Random rand = new Random();
    List<FinancialStuff> financialStuffList = new List<FinancialStuff>();
    financialStuffList.Add(new FinancialStuff() { Name = "MSFT", Amount = rand.Next(0, 200) });
    financialStuffList.Add(new FinancialStuff() { Name = "AAPL", Amount = rand.Next(0, 200) });
    financialStuffList.Add(new FinancialStuff() { Name = "GOOG", Amount = rand.Next(0, 200) });
    financialStuffList.Add(new FinancialStuff() { Name = "BBRY", Amount = rand.Next(0, 200) });
    (PieChart.Series[0] as PieSeries).ItemsSource = financialStuffList;
    (ColumnChart.Series[0] as ColumnSeries).ItemsSource = financialStuffList;
    (LineChart.Series[0] as LineSeries).ItemsSource = financialStuffList;
}

您可以按照本教程(Windows 8.1) USING GRAPHS AND CHARTS

答案 1 :(得分:3)

Syncfusion为其Essential Studio套件的独立开发者提供免费许可。他们有一些很棒的可视化工具。您可以在此处查看:https://www.syncfusion.com/products/uwp

您可以通过以下链接找到有关其免费许可的更多信息:https://www.syncfusion.com/products/communitylicense

Filip Skakun已经建立了一个很棒的图书馆,有多种图表可供选择!它可以在WinRT中使用它,并且他正在将它移植到UWP(Win 10)。

您可以关注的链接以获取更多信息

https://github.com/xyzzer/WinRTXamlToolkit(完整的lib)https://github.com/xyzzer/WinRTXamlToolkit/tree/master/WinRTXamlToolkit.Controls.DataVisualization/WinRTXamlToolkit.Controls.DataVisualization.Shared/Charting(图表部分)