Windows Forms: How to Create a Geo Chart using LiveCharts in C#

This post shows you How to Create a Geo Chart (GeoHeatMap) using LiveCharts in C# .NET Windows Forms Application.

GeoChart is a control of LiveCharts library that helps you display a geo chart in Windows Forms Application.

Live Chart Tutorial

LiveCharts control is simple, flexible, interactive and powerful data visualization for .Net. It's just data visualization but built and for everyone.

Creating a new Windows Forms Application, then right-click on your project => select Manage Nuget Packages from your Visual Studio.

Geo Chart C#

Next, Search live charts => Install.

c# livecharts

After installing LiveCharts.Winforms, you should rebuild your project. You should see the LiveCharts control automatically added to your Visual Studio Toolbox.

Next, Open your form designer, then add a Form_Load event handler

private void Form1_Load(object sender, EventArgs e)
{
    LiveCharts.WinForms.GeoMap geoMap = new LiveCharts.WinForms.GeoMap();
    Random random = new Random();
    Dictionary<string, double> values = new Dictionary<string, double>();
    values["MX"] = random.Next(0, 100);
    values["CA"] = random.Next(0, 100);
    values["US"] = random.Next(0, 100);
    values["IN"] = random.Next(0, 100);
    values["CN"] = random.Next(0, 100);
    values["JP"] = random.Next(0, 100);
    values["BR"] = random.Next(0, 100);
    values["DE"] = random.Next(0, 100);
    values["FR"] = random.Next(0, 100);
    values["GB"] = random.Next(0, 100);
    geoMap.HeatMap = values;
    geoMap.Source = $"{Application.StartupPath}\\World.xml";
    this.Controls.Add(geoMap);
    geoMap.Dock = DockStyle.Fill;
}

You need to download sample data from GitHub: Link

You can find many countries maps in Live-Charts/Live-Maps/tree/master/Maps.

After downloading sample data, you need to copy the World.xml to your project and don't forget set the Copy to Output Directory property of your World.xml file to Copy always.

First, You need to create a dictionary to help you random data in this example.

Next, We will define the "key" and number pattern, where the key is the ID of the element in the XML where you want to define the numeric value.

Finally, We will fill the specific keys of the countries with a random number.

Through this c# example you will learn how to use live chart winform to display maps. This is a simple live chart demo how to use GeoMap control to display your maps.