偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

使用 ScottPlot 在 .NET WinForms 中快速實(shí)現(xiàn)大型數(shù)據(jù)集的交互式顯示!

開發(fā) 前端
本文我們將一起來學(xué)習(xí)一下如何使用ScottPlot庫在.NET WinForms中快速實(shí)現(xiàn)大型數(shù)據(jù)集的交互式顯示。

前言

在.NET應(yīng)用開發(fā)中數(shù)據(jù)集的交互式顯示是一個(gè)非常常見的功能,如需要?jiǎng)?chuàng)建折線圖、柱狀圖、餅圖、散點(diǎn)圖等不同類型的圖表將數(shù)據(jù)呈現(xiàn)出來,幫助人們更好地理解數(shù)據(jù)、發(fā)現(xiàn)規(guī)律,并支持決策和溝通。本文我們將一起來學(xué)習(xí)一下如何使用ScottPlot庫在.NET WinForms中快速實(shí)現(xiàn)大型數(shù)據(jù)集的交互式顯示。

ScottPlot類庫介紹

ScottPlot是一個(gè)免費(fèi)、開源(采用MIT許可證)的強(qiáng)大.NET交互式繪圖庫,能夠輕松地實(shí)現(xiàn)大型數(shù)據(jù)集的交互式顯示。使用幾行代碼即可快速創(chuàng)建折線圖、柱狀圖、餅圖、散點(diǎn)圖等不同類型的圖表。

ScottPlot類庫支持平臺(tái)和框架

Console Application、WinForms、WPF、Avalonia、Blazor、WinUI等多個(gè)平臺(tái)和框架。

ScottPlot類庫源代碼

新建WinForms項(xiàng)目

新建一個(gè)名為ScottPlotWinFormsExercise的項(xiàng)目。

安裝ScottPlot.WinForms包

搜索ScottPlot.WinForms包安裝:

折線圖實(shí)現(xiàn)

創(chuàng)建名為:LineChart窗體。

將FormsPlot (ScottPlot.WinForms)從工具箱拖到窗體中:

輸入以下代碼:

public partial class LineChart : Form
    {
        public LineChart()
        {
            double[] dataX = GetRandomNum(20).Distinct().OrderByDescending(x => x).ToArray();
            double[] dataY = GetRandomNum(19).Distinct().OrderByDescending(x => x).ToArray();
            formsPlot1.Plot.Add.Scatter(dataX, dataY);
            formsPlot1.Refresh();
        }

        public double[] GetRandomNum(int length)
        {
            double[] getDate = new double[length];
            Random random = new Random(); //創(chuàng)建一個(gè)Random實(shí)例
            for (int i = 0; i < length; i++)
            {
                getDate[i] = random.Next(1, 100); //使用同一個(gè)Random實(shí)例生成隨機(jī)數(shù)
            }
            return getDate;
        }
    }

運(yùn)行效果展示:

柱狀圖實(shí)現(xiàn)

創(chuàng)建名為:BarChart窗體。

將FormsPlot (ScottPlot.WinForms)從工具箱拖到窗體中:

輸入以下代碼:

public partial class BarChart : Form
    {
        public BarChart()
        {
            double[] values = { 5, 10, 7, 13, 22, 18, 33, 16 };
            formsPlot1.Plot.Add.Bars(values);
            formsPlot1.Refresh();
        }
    }

運(yùn)行效果展示:

餅圖實(shí)現(xiàn)

創(chuàng)建名為:PieChart窗體。

將FormsPlot (ScottPlot.WinForms)從工具箱拖到窗體中:

輸入以下代碼:

public partial class PieChart : Form
    {
        public PieChart()
        {
            double[] values = { 3, 2, 8, 4, 8, 10 };
            formsPlot1.Plot.Add.Pie(values);
            formsPlot1.Refresh();
        }
    }

運(yùn)行效果展示:

散點(diǎn)圖實(shí)現(xiàn)

創(chuàng)建名為:ScatterChart窗體。

將FormsPlot (ScottPlot.WinForms)從工具箱拖到窗體中:

輸入以下代碼:

public partial class ScatterChart : Form
    {
        public ScatterChart()
        {
            //從原始數(shù)據(jù)開始
            double[] xs = Generate.Consecutive(100);
            double[] ys = Generate.NoisyExponential(100);

            //對(duì)數(shù)據(jù)進(jìn)行對(duì)數(shù)縮放,并處理負(fù)值
            double[] logYs = ys.Select(Math.Log10).ToArray();

            //將對(duì)數(shù)縮放的數(shù)據(jù)添加到繪圖中
            var sp = formsPlot1.Plot.Add.Scatter(xs, logYs);
            sp.LineWidth = 0;

            //創(chuàng)建一個(gè)次要刻度生成器,用于放置對(duì)數(shù)分布的次要刻度
            ScottPlot.TickGenerators.LogMinorTickGenerator minorTickGen = new();

            //創(chuàng)建一個(gè)數(shù)值刻度生成器,使用自定義的次要刻度生成器
            ScottPlot.TickGenerators.NumericAutomatic tickGen = new();
            tickGen.MinorTickGenerator = minorTickGen;

            //創(chuàng)建一個(gè)自定義刻度格式化程序,用于設(shè)置每個(gè)刻度的標(biāo)簽文本
            static string LogTickLabelFormatter(double y) => $"{Math.Pow(10, y):N0}";

            //告訴我們的主要刻度生成器僅顯示整數(shù)的主要刻度
            tickGen.IntegerTicksOnly = true;

            //告訴我們的自定義刻度生成器使用新的標(biāo)簽格式化程序
            tickGen.LabelFormatter = LogTickLabelFormatter;

            //告訴左軸使用我們的自定義刻度生成器
            formsPlot1.Plot.Axes.Left.TickGenerator = tickGen;

            //顯示次要刻度的網(wǎng)格線
            var grid = formsPlot1.Plot.GetDefaultGrid();
            grid.MajorLineStyle.Color = Colors.Black.WithOpacity(.15);
            grid.MinorLineStyle.Color = Colors.Black.WithOpacity(.05);
            grid.MinorLineStyle.Width = 1;

            formsPlot1.Refresh();
        }
    }

運(yùn)行效果展示:

項(xiàng)目演示入口

private void Btn_ScatterChart_Click(object sender, EventArgs e)
        {
            ScatterChart formScatterChart = new ScatterChart();
            // 顯示目標(biāo)窗體
            formScatterChart.Show();
        }

        private void Btn_PieChart_Click(object sender, EventArgs e)
        {
            PieChart formPieChart = new PieChart();
            // 顯示目標(biāo)窗體
            formPieChart.Show();
        }

        private void Btn_BarChart_Click(object sender, EventArgs e)
        {
            BarChart formbarChart = new BarChart();
            // 顯示目標(biāo)窗體
            formbarChart.Show();
        }

        private void Btn_LineChart_Click(object sender, EventArgs e)
        {
            LineChart formLineChart = new LineChart();
            // 顯示目標(biāo)窗體
            formLineChart.Show();
        }
責(zé)任編輯:武曉燕 來源: 追逐時(shí)光者
相關(guān)推薦

2025-01-16 07:58:53

.NET圖表構(gòu)建

2023-10-31 09:00:00

2023-07-28 14:13:15

Streamlit開源Python庫

2014-07-16 09:32:34

Pinterest

2018-05-21 14:44:33

LinuxshellPython

2024-07-25 08:58:16

GradioPython數(shù)據(jù)應(yīng)用

2024-12-30 07:40:00

WinFormsADO.NET數(shù)據(jù)庫

2023-10-16 16:14:32

數(shù)據(jù)中心

2023-12-18 15:02:00

PyechartsPython數(shù)據(jù)可視化工具

2010-12-09 21:46:26

Scapy

2013-02-18 08:39:15

powershell

2013-09-22 16:22:21

2010-02-24 09:39:25

Python交互式

2025-02-25 10:40:00

圖像生成工具模型

2011-12-27 20:12:56

平板

2020-04-06 20:47:42

FishShellLinux

2023-06-27 13:46:20

2025-05-07 00:35:00

2015-10-14 17:59:53

Google數(shù)據(jù)探索交互開發(fā)

2011-06-13 18:54:12

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)