如何在 UWP VB.NET 中实现 WinRTXamlToolkit.Controls.DataVisualization.Charting

How to implement WinRTXamlToolkit.Controls.DataVisualization.Charting in UWP VB.NET

网上有很多关于这个包的例子。但所有这些都在 C# 中,我似乎无法在 VB.NET 中重现这些示例。任何人都可以 post 一个简单的代码,例如,如何使用 LineSeries。

谢谢!

But all are in C# and I can't seem to reproduce those examples in VB.NET. Could anyone post a simple code on, for example, how to use the LineSeries

我根据此 blog

中的 C# 示例创建了一个 VB.Net 示例

xaml代码与C#一样,添加LineSeries并设置绑定为IndependentValuePath & DependentValuePath:

<Charting:Chart x:Name="LineChart" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="2" Width="400" Height="400">
            <Charting:LineSeries Title="Smartphone Companies" IndependentValuePath="Name" DependentValuePath="Amount" IsSelectionEnabled="True"/>
        </Charting:Chart>

创建数据列表并分配给LineSeries:

Dim rand As New Random()
        Dim financialStuffList As New List(Of FinancialStuff)()
        financialStuffList.Add(New FinancialStuff() With {
                               .Name = "MSFT",
                               .Amount = rand.[Next](0, 200)
                               })
        financialStuffList.Add(New FinancialStuff() With {
                               .Name = "AAPL",
                               .Amount = rand.[Next](0, 200)
                               })
        financialStuffList.Add(New FinancialStuff() With {
                               .Name = "GOOG",
                               .Amount = rand.[Next](0, 200)
                               })
        financialStuffList.Add(New FinancialStuff() With {
                               .Name = "BBRY",
                               .Amount = rand.[Next](0, 200)
                               })
TryCast(LineChart.Series(0), LineSeries).ItemsSource = financialStuffList

查看我完成的样本here