首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LiveCharts库和VB.net

LiveCharts库和VB.net
EN

Stack Overflow用户
提问于 2018-03-22 12:03:04
回答 1查看 2.4K关注 0票数 -1

我想在我的VB.net代码中使用windows-form和visual studio 2015的实时图表库来实现笛卡尔图表,但是我找不到任何VB.net代码示例。

谁能给我提供一个工作的笛卡尔图表的vb.net代码样本。

和部

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-04 08:22:38

我在Visual Studio 2017中使用VB并创建了一个WPF-App。

我假设您已经使用Nuget包管理器在Visual Studio项目中安装了LiveCharts和LiveCharts.WPF。下面的示例绘制了一个包含两个系列的笛卡尔条形图。第一个序列的值是在代码中静态输入的。第二个系列显示通过一个简单的方程计算的动态数据。这应该能让你振作起来。

我用下面的XAML代码创建了一个WPF窗口:

代码语言:javascript
复制
<Window 
     x:Class="Mycolumn"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <lvc:CartesianChart Name="Mychart" Series="{Binding MySeriesCollection}" LegendLocation="Left" Margin="25,29,21,10">
            <lvc:CartesianChart.AxisX>
                <lvc:Axis Title="Size" Labels="{Binding MyLabels}">
                    <lvc:Axis.Separator>
                        <lvc:Separator IsEnabled="False" Step="1"></lvc:Separator>
                    </lvc:Axis.Separator>
                </lvc:Axis>
            </lvc:CartesianChart.AxisX> 
            <lvc:CartesianChart.AxisY>
                <lvc:Axis Title="Frequency" LabelFormatter="{Binding MyFormatter}"></lvc:Axis>
            </lvc:CartesianChart.AxisY>
        </lvc:CartesianChart>
    </Grid>
</Window>

然后在VB代码隐藏中我添加了这个(不需要"Imports“语句):

代码语言:javascript
复制
  Public Class Mycolumn
    '---Need to declare binding properties here so that XAML can find them---
    '---Remember XAML is case sensitive---
    Public Property MySeriesCollection As LiveCharts.SeriesCollection
    Public Property MyLabels As New List(Of String)
    Public Property MyFormatter As Func(Of Double, String)

    Public Sub New()
        InitializeComponent()
        '---Create a seriescollection and add first series as a columnseries (index 0) and some static values to show---
        '---The first series will show just 4 columns---
        MySeriesCollection = New LiveCharts.SeriesCollection From {
                New LiveCharts.Wpf.ColumnSeries With {
                    .Title = "Granite",
                    .Values = New LiveCharts.ChartValues(Of Double) From {
                        110,
                        350,
                        239,
                        550
                    }
                }
            }
        '---Add a second columnseries(index 1) with nothing in it yet---  
        MySeriesCollection.Add(New LiveCharts.Wpf.ColumnSeries With {
                .Title = "Marble",
                .Values = New LiveCharts.ChartValues(Of Double)})
        '---Now add some dynamic values to columnseries (1) - will show 10 columns of results ---
        '---These values can come from a list or array of double calculated elsewhere in the program---
        For i = 1 To 10
            MySeriesCollection(1).Values.Add(CDbl(i + (2 * i) ^ 2))
        Next
        '---Add 10 labels to show on the x-axis---
        For i = 1 To 10
            MyLabels.Add(CStr(i))
        Next
        '---Define formatter to change double values on y-axis to string labels---
        MyFormatter = Function(value) value.ToString("N")
        DataContext = Me
    End Sub
End Class
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49420336

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档