You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求VS2015 WinForm环境下VB.NET的LiveCharts笛卡尔图表可运行示例代码

嘿,我懂你找VB.NET版LiveCharts笛卡尔图表示例的难处——官方大多是C#示例,确实有点头疼。下面给你一个能直接在VS2015 WinForms项目里跑起来的完整示例,跟着步骤来就行:

VB.NET LiveCharts 笛卡尔图表可运行示例

第一步:安装依赖

首先在你的VS2015 WinForms项目中,通过NuGet安装两个必要包:

  • LiveCharts
  • LiveCharts.WinForms
    (操作方式:右键项目 → 管理NuGet程序包 → 搜索对应包并安装)

第二步:完整Form代码

新建一个Windows Form,把下面的代码替换掉默认的Form1.vb代码:

Imports LiveCharts
Imports LiveCharts.WinForms
Imports LiveCharts.Defaults

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' 创建笛卡尔图表控件并铺满窗体
        Dim cartesianChart As New CartesianChart()
        cartesianChart.Dock = DockStyle.Fill
        Me.Controls.Add(cartesianChart)

        ' 配置X轴:设置标题和自定义标签
        cartesianChart.AxisX.Add(New Axis With {
            .Title = "工作日",
            .Labels = New List(Of String) From {"周一", "周二", "周三", "周四", "周五"}
        })

        ' 配置Y轴:设置标题和数值格式化规则
        cartesianChart.AxisY.Add(New Axis With {
            .Title = "统计数值",
            .LabelFormatter = Function(value) value.ToString("N2") ' 保留两位小数
        })

        ' 准备折线图数据系列
        Dim salesSeries As New LineSeries With {
            .Title = "产品销量",
            .Values = New ChartValues(Of ObservableValue) From {
                New ObservableValue(120.5),
                New ObservableValue(156.2),
                New ObservableValue(92.8),
                New ObservableValue(205.3),
                New ObservableValue(188.7)
            },
            .StrokeThickness = 2.5,
            .PointGeometry = DefaultGeometries.Circle,
            .PointGeometrySize = 10
        }

        ' 准备柱状图数据系列
        Dim profitSeries As New ColumnSeries With {
            .Title = "单日利润",
            .Values = New ChartValues(Of ObservableValue) From {
                New ObservableValue(32.1),
                New ObservableValue(46.5),
                New ObservableValue(21.3),
                New ObservableValue(62.7),
                New ObservableValue(53.9)
            }
        }

        ' 将数据系列添加到图表
        cartesianChart.Series.Add(salesSeries)
        cartesianChart.Series.Add(profitSeries)

        ' 设置图例位置
        cartesianChart.LegendLocation = LegendLocation.Right
    End Sub
End Class

代码小说明

  • 示例里是动态创建图表控件,你也可以直接从VS工具箱拖入CartesianChart控件(安装NuGet包后工具箱会自动出现LiveCharts相关控件)
  • ObservableValue支持数据实时更新,如果不需要实时刷新,也可以直接用ChartValues(Of Double)简化代码
  • 你可以根据需求替换系列类型,比如换成AreaSeries(面积图)、RowSeries(横向柱状图)等

运行项目后,就能看到一个包含折线+柱状双系列的笛卡尔图表,完全适配VB.NET和VS2015环境。

内容的提问来源于stack exchange,提问作者ンドング 一信 ndong

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:14:00