開源免費的圖表庫和環形進度條庫(LiveChart&CircularProgressBar)

這兩個庫均可在Nuget裏搜索到,安裝完之後,編譯一下,然後再將.dll添加到工具箱裏既可使用。

LiveChart官方網站:https://lvcharts.net/  範例網站:https://lvcharts.net/App/examples/v1/wf/Basic%20Line%20Chart

Github地址:https://github.com/Live-Charts/Live-Charts

圖表生成,以及往圖表裏添加數據的程序範例如下:

using System;
using System.Windows.Forms;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Wpf;
 
namespace Winforms.Cartesian.BasicLine
{
    public partial class BasicLineExample : Form
    {
        public BasicLineExample()
        {
            InitializeComponent();
 
            cartesianChart1.Series = new SeriesCollection
            {
                new LineSeries
                {
                    Title = "Series 1",
                    Values = new ChartValues<double> {4, 6, 5, 2, 7}
                },
                new LineSeries
                {
                    Title = "Series 2",
                    Values = new ChartValues<double> {6, 7, 3, 4, 6},
                    PointGeometry = null
                },
                new LineSeries
                {
                    Title = "Series 2",
                    Values = new ChartValues<double> {5, 2, 8, 3},
                    PointGeometry = DefaultGeometries.Square,
                    PointGeometrySize = 15
                }
            };
 
            cartesianChart1.AxisX.Add(new Axis
            {
                Title = "Month",
                Labels = new[] {"Jan", "Feb", "Mar", "Apr", "May"}
            });
 
            cartesianChart1.AxisY.Add(new Axis
            {
                Title = "Sales",
                LabelFormatter = value => value.ToString("C")
            });
 
            cartesianChart1.LegendLocation = LegendLocation.Right;
 
            //modifying the series collection will animate and update the chart
            cartesianChart1.Series.Add(new LineSeries
            {
                Values = new ChartValues<double> { 5, 3, 2, 4, 5 },
                LineSmoothness = 0, //straight lines, 1 really smooth lines
                PointGeometry = Geometry.Parse("m 25 70.36218 20 -28 -20 22 -8 -6 z"),
                PointGeometrySize = 50,
                PointForeground = Brushes.Gray
            });
 
            //modifying any series values will also animate and update the chart
            //注意添加的數據類型和建立的表的數據類型要一致
            cartesianChart1.Series[2].Values.Add(5d);
 
 
            cartesianChart1.DataClick += CartesianChart1OnDataClick;
        }
 
        private void CartesianChart1OnDataClick(object sender, ChartPoint chartPoint)
        {
            MessageBox.Show("You clicked (" + chartPoint.X + "," + chartPoint.Y + ")");
        }
    }
}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章