Malvern Yap Malvern Yap - 2 months ago 30
Vb.net Question

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

There a bunch of examples online regarding this package. 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.

Thanks!

Answer

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

I created a VB.Net sample based on the C# sample in this blog

The xaml code is the same as C# one, add LineSeries and set binding to 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>

Create data list and assign to 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

Check my completed sample here

Comments