【注1】WinRTXamlToolkit是免费控件,不过很久不更新了,而且网上的资源很少。后来我发现syncfusion控件有免费的community版本,并且有详细文档,所以就转过去使用syncfusion了。继续在WinRT/UWP奋战的亲们可以去围观一下:https://www.syncfusion.com/products/communitylicense
【注2】.Net平台各种免费和收费的包含Chart的控件:WinRTXamlToolkit/ModernUI/Visifire/Telerik/Syncfusion
【注3】WinRTXamlToolkit示例:http://eren.ws/2013/10/15/using-graphs-and-charts-in-windows-store-apps-boredom-challenge-day-11/
xmlns:Charting="using:WinRTXamlToolkit.Controls.DataVisualization.Charting"
public class FinancialStuff
{
public string Name { get; set; }
public int Amount { get; set; }
}
private void LoadChartContents()
{
Random rand = new Random();
List<FinancialStuff> financialStuffList = new List<FinancialStuff>();
financialStuffList.Add(new FinancialStuff() { Name = "MSFT", Amount = rand.Next(, ) });
financialStuffList.Add(new FinancialStuff() { Name = "AAPL", Amount = rand.Next(, ) });
financialStuffList.Add(new FinancialStuff() { Name = "GOOG", Amount = rand.Next(, ) });
financialStuffList.Add(new FinancialStuff() { Name = "BBRY", Amount = rand.Next(, ) });
(PieChart.Series\[\] as PieSeries).ItemsSource = financialStuffList;
(ColumnChart.Series\[\] as ColumnSeries).ItemsSource = financialStuffList;
(LineChart.Series\[\] as LineSeries).ItemsSource = financialStuffList;
(BarChart.Series\[\] as BarSeries).ItemsSource = financialStuffList;
(BubbleChart.Series\[\] as BubbleSeries).ItemsSource = financialStuffList;
}
也可以先将Series弄出来:
public static LineSeries InitChart(List<FinancialStuff> financialStuffList)
{
LineSeries lSeries = new LineSeries();
lSeries.IndependentValuePath = "Name";
lSeries.DependentValuePath = "Amount";
lSeries.ItemsSource = financialStuffList;
return lSeries;
}
LineSeries ls = Functions.WinrtChartHelper.InitChart(financialStuffList);
this.LineChart.Series.Add(ls);
然而,这样子只能实现LineSeries ,PieSeries/ColumnSeries/BarSeries/BubbleSeries等都会有一个UnhandledException出现……
手机扫一扫
移动阅读更方便
你可能感兴趣的文章