This tutorial shows you how to use Live Charts control in C#.NET Windows Forms Application.
The live charts control is a library support WPF, UWP and Winforms. It's simple, flexible, interactive and powerful data visualization for winforms application.
To play the demo, you need to create a windows forms application project, then install live charts from the Manage Nuget Packages.
You can design a simple UI allows you to load data to chart control from a datagridview as shown below
Create a dataset, then add a binding source to the datagridview control
Add code to handle your button click event as shown below
using System;
using System.Windows.Forms;
using LiveCharts;
using LiveCharts.Wpf;
namespace LiveChartDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1})", chartPoint.Y, chartPoint.Participation);
private void Form1_Load(object sender, EventArgs e)
{
pieChart1.LegendLocation = LegendLocation.Bottom;
}
private void btnLoad_Click(object sender, EventArgs e)
{
SeriesCollection series = new SeriesCollection();
foreach (var obj in data.Revenue)
series.Add(new PieSeries() { Title = obj.Year.ToString(), Values = new ChartValues<int> { obj.Total }, DataLabels = true, LabelPoint = labelPoint });
pieChart1.Series = series;
}
}
}
If you don't see the live charts control in your visual studio toolbox. You need to create a new tab, then add a reference to the live charts library or you can drag the live charts library into your visual studio toolbox
From your visual studio toolbox drag a pie chart control to your windows forms application
You can also add a material design to the Charts that match the Material Design style
Or create a high performance chart with 20k points, following multi thread practices
Or create 2 charts with many points to navigate through records easily