一个简单、灵活、美观、强大的.NET图形库

2023-05-16

前言

给大家推荐一个跨平台图表库。Live chart 是一个跨平台的图表库 .Net,要开始使用,请访问https://lvcharts.com并查看目标平台的安装指南,该网站包含此 repo 中提供的所有示例、文档和更多的。

项目简介

这是一个简单、灵活、交互式、强大的跨平台图表库,支持Maui、Uno Platform、Blazor-wasm、WPF、WinForms、Xamarin、Avalonia、WinUI、UWP。

提供超过60多种图表类型,包括:基本图表、柱状图表、饼图、散点分布、股票行情、甘特图、仪表图、热点图、坐标图、地图等。

图表使用灵活、交互体验好、数据支持自动更新可以实时动态变化。

项目结构

697782f2ce43a6737be3ead9fc80cf09.png

使用指南

选择平台

8dfe74547463b51b58898d04d59d62e3.png

安装

1、创建项目

打开Visual studio创建项目,项目选择Windows From。

64b4f8c194da20bc1e19f0f6d2234fe9.png

2、引用插件

Install-Package LiveChartsCore.SkiaSharpView.WinForms

安装插件后,在工具箱就能看到相应的图表控件,直接拖拉便可以开发。

75eb14604c2f296721b482d91bfc05d8.gif

3、第一张图表

基本线图表例子

using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
namespace WinFormsSample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            cartesianChart1.Series = new ISeries[] 
            { 
                new LineSeries<double> 
                { 
                    Values = new double[] { 2, 1, 3, 5, 3, 4, 6 }, 
                    Fill = null 
                } 
            }; 
        }
    }
}

4、配置图表主题

在项目启动入口配置主题,设置代码如下:

using System;
using System.Windows.Forms;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;

namespace WinFormsSample
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            _ = Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

            LiveCharts.Configure(config =>
                config
                    // registers SkiaSharp as the library backend
                    // REQUIRED unless you build your own
                    .AddSkiaSharp()

                    // adds the default supported types
                    // OPTIONAL but highly recommend
                    .AddDefaultMappers()

                    // select a theme, default is Light
                    // OPTIONAL
                    //.AddDarkTheme()
                    .AddLightTheme()

                    // finally register your own mappers
                    // you can learn more about mappers at:
                    // ToDo add website link...
                    .HasMap<City>((city, point) =>
                    {
                        point.PrimaryValue = city.Population;
                        point.SecondaryValue = point.Context.Index;
                    })
                    // .HasMap<Foo>( .... )
                    // .HasMap<Bar>( .... )
                );
        }
    }
}

图表样式

基础线

86cc18636f0c60eaff4e8336ff95f171.jpeg

放大缩小

bb22ea3c45cb2eace243b8959f1b4e83.gif

柱状图

41440c55c51a77d0e9cbc237dd1060ee.jpeg

股票

f84bc1216fd34d4d4143b63ad6760494.jpeg

热点图

c3b14ba76414b1d86ded4da25d73d6a9.jpeg

散点分布

f6dff46bac07fa4d58baa57832762cc5.jpeg

图表整体样式

b2678fbdc46c4ba82477caad811f498e.png b5ac2161894029878214e0b621551024.png b32dbd37f0a655b144b6b3b6ff5c4bbd.png

源码

https://github.com/beto-rodriguez/LiveCharts2

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

一个简单、灵活、美观、强大的.NET图形库 的相关文章

随机推荐