Xamarin.Forms - Microcharts App
In this article, we are going to learn how to display micro-charts in single line code for Xamarin.Forms.
Introduction
Displaying charts in mobile apps has always been a great way to offer users a clear overview of numerical data. I want this task to be as easy as writing a few lines of code, but I couldn't find a straight-forward way to achieve this. This is why I started exploring SkiaSharp and created Microcharts.
Displaying charts in mobile apps has always been a great way to offer users a clear overview of numerical data. I want this task to be as easy as writing a few lines of code, but I couldn't find a straight-forward way to achieve this. This is why I started exploring SkiaSharp and created Microcharts.
nuGet package : Xamarin.Forms = search "Microcharts.Forms"
This simple plugin can display microcharts in Xamarin.Forms.
![](/article/xamarin-forms-microcharts-app/Images/result.gif)
Available charts Microcharts.Forms Plugin
- Barchart
- PointChart
- LineChart
- DonutChart
- RadialGaugeChart
- RadarChart
Chart Types
BarChart
- Chartview.Chart = new BarChart(){Entries = entries};
![](/article/xamarin-forms-microcharts-app/Images/BarChartNew.jpg)
PointChart
- Chartview.Chart = new PointChart(){Entries = entries};
![](/article/xamarin-forms-microcharts-app/Images/PointChartNew.jpg)
LineChart
- Chartview.Chart = new LineChart(){Entries = entries};
![](/article/xamarin-forms-microcharts-app/Images/LineChartNew.jpg)
DonutChart
- Chartview.Chart = new DonutChart(){Entries = entries};
![](/article/xamarin-forms-microcharts-app/Images/DonutChartNew.jpg)
RadialGaugeChart
- Chartview.Chart = new RadialGaugeChart(){Entries = entries};
![](/article/xamarin-forms-microcharts-app/Images/RadiaGuageChartNew.jpg)
RadarChart
- Chartview.Chart = new RadartChart(){Entries = entries};
![](/article/xamarin-forms-microcharts-app/Images/RadarChartNew.png)
Step 1
You can create Xamarin.Forms app by going to File >> New >> Visual C# >> Cross Platform >> Cross Platform App (Xamarin.Native or Xamarin.Forms), give the application name and press OK.
(Project name: MicrochartsApp)
You can create Xamarin.Forms app by going to File >> New >> Visual C# >> Cross Platform >> Cross Platform App (Xamarin.Native or Xamarin.Forms), give the application name and press OK.
(Project name: MicrochartsApp)
Step 2
Now, add the following NuGet Package for your projects.
Now, add the following NuGet Package for your projects.
- Microcharts.Forms
For that, go to Solution Explorer and select your solution. Right-click and select "Manage NuGet Packages for the Solution". Now, select the following NuGet Package, select your project, and install it.
- Microcharts.Forms
Step 3
To display a chart, we'll need to host it in a ChartView.
To display a chart, we'll need to host it in a ChartView.
After installing NuGet packages, add a ChartView control to your project. For that, go to Solution Explorer >> MicrochartsApp(PCL) >>> Double-click on MainPage.xaml. After opening this, you can add assembly and XAML code to your project. Here is the code for this page.
Assembly
- xmlns:forms="clr-namespace:Microcharts.Forms;assembly=Microcharts.Forms"
XAML code
- <?xml version="1.0" encoding="utf-8" ?>
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- xmlns:local="clr-namespace:MicrochartsApp"
- x:Class="MicrochartsApp.MainPage"
- xmlns:forms="clr-namespace:Microcharts.Forms;assembly=Microcharts.Forms">
- <ScrollView>
- <StackLayout Orientation="Vertical">
- <forms:ChartView x:Name="Chart1"
- HeightRequest="150"/>
- <forms:ChartView x:Name="Chart2"
- HeightRequest="150"
- />
- <forms:ChartView x:Name="Chart3"
- HeightRequest="150"/>
- <forms:ChartView x:Name="Chart4"
- HeightRequest="150"/>
- <forms:ChartView x:Name="Chart5"
- HeightRequest="150"/>
- <forms:ChartView x:Name="Chart6"
- HeightRequest="160"/>
- </StackLayout>
- </ScrollView>
- </ContentPage>
![](/article/xamarin-forms-microcharts-app/Images/MainXaml.png)
Step 4
In this step, add data entries. For that, open Solution Explorer >> MicrochartsApp(PCL) >>click open MainPage.xaml.cs. This class code is given below.
Every chart displays via Microcharts and consumes a set of data entries. They will always have the same structure regardless of the chart type that you want to display.
In this step, add data entries. For that, open Solution Explorer >> MicrochartsApp(PCL) >>click open MainPage.xaml.cs. This class code is given below.
Every chart displays via Microcharts and consumes a set of data entries. They will always have the same structure regardless of the chart type that you want to display.
Each entry
- Floating number representing it's value is required.
- Label - what your entry is associated with.
- ValueLabel - format your value
- Color - entry
- using Microcharts;
- using SkiaSharp;
- using Microcharts.Forms;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- using Entry = Microcharts.Entry;
- namespace MicrochartsApp
- {
- public partial class MainPage : ContentPage
- {
- List<Entry> entries = new List<Entry>
- {
- new Entry(200)
- {
- Color=SKColor.Parse("#FF1943"),
- Label ="January",
- ValueLabel = "200"
- },
- new Entry(400)
- {
- Color = SKColor.Parse("00BFFF"),
- Label = "March",
- ValueLabel = "400"
- },
- new Entry(-100)
- {
- Color = SKColor.Parse("#00CED1"),
- Label = "Octobar",
- ValueLabel = "-100"
- },
- };
- public MainPage()
- {
- InitializeComponent();
- Chart1.Chart = new RadialGaugeChart() { Entries = entries };
- Chart2.Chart = new LineChart() { Entries = entries };
- Chart3.Chart = new DonutChart() { Entries = entries };
- Chart4.Chart = new BarChart() { Entries = entries };
- Chart5.Chart = new PointChart() { Entries = entries };
- //Chart6.Chart = new RadarChart() { Entries = entries };
- }
- }
- }
Step 5
Now, go to "Build" menu and configure your startup project. After configuring, run your project. You will have the result like below.
![](/article/xamarin-forms-microcharts-app/Images/result.gif)
Finally, we have successfully created Xamarin.Forms Microcharts application.
View Previous Comments
Press Esc key to cancel
![](https://csharpcorner-mindcrackerinc.netdna-ssl.com/UploadFile/AuthorImage/DefaultAuthorImage.jpg.ashx?width=56&height=56)
![Loading...](/images/csharp/ajax-loader-small.gif)
![florent SERFAS florent SERFAS](https://www.c-sharpcorner.com/UploadFile/AuthorImage/DefaultAuthorImage.jpg.ashx?width=56&height=56)
Hi all, is it possible with microchart to do a real time chart ?
May 31, 2019
florent SERFAS
1805 7 0
![Logesh Palani Logesh Palani](https://www.c-sharpcorner.com/UploadFile/AuthorImage/384a1020180606031226.jpg.ashx?width=56&height=56)
Sure. Just Bind the real time data, its works
Jun 02, 2019
Logesh Palani
278 6.8k 669.7k
![divya morampudi divya morampudi](https://www.c-sharpcorner.com/UploadFile/AuthorImage/DefaultAuthorImage.jpg.ashx?width=56&height=56)
Hi all,how to get label value by clicking on that.i mean do we have any click event for label?.i need to navigate to another page when i click on that valuelabel
Feb 13, 2019
divya morampudi
1805 7 0
![Logesh Palani Logesh Palani](https://www.c-sharpcorner.com/UploadFile/AuthorImage/384a1020180606031226.jpg.ashx?width=56&height=56)
You just use Tapped gesture event to navigate or perform operations
May 22, 2019
Logesh Palani
278 6.8k 669.7k
![Ajithkumar J Ajithkumar J](https://www.c-sharpcorner.com/UploadFile/AuthorImage/088f8620180119110328.jpg.ashx?width=56&height=56)
Copied from https://www.youtube.com/watch?v=tmymWdmf1y4&list=PLpbcUe4chE794tJySgk0EiqSWp4o2yFdY&index=6 :)
Jan 14, 2019
Ajithkumar J
280 6.7k 392.6k
![satya m satya m](https://www.c-sharpcorner.com/UploadFile/AuthorImage/DefaultAuthorImage.gif.ashx?width=56&height=56)
Is it possible in Visual studio 2017 professional
Jan 04, 2019
satya m
1657 155 1.5k
![Logesh Palani Logesh Palani](https://www.c-sharpcorner.com/UploadFile/AuthorImage/384a1020180606031226.jpg.ashx?width=56&height=56)
You can use any version of visual studio but need to want your Xamarin.Forms version
May 22, 2019
Logesh Palani
278 6.8k 669.7k
![Terry Chen Terry Chen](https://www.c-sharpcorner.com/UploadFile/AuthorImage/DefaultAuthorImage.jpg.ashx?width=56&height=56)
Hi, can this charts do live updates?
Dec 05, 2018
Terry Chen
1810 2 0
![Sandeep Kumar Sandeep Kumar](https://www.c-sharpcorner.com/UploadFile/AuthorImage/18585c20150223032909.png.ashx?width=56&height=56)
Yes It can
Jan 24, 2019
Sandeep Kumar
415 4.3k 522.8k
![SHRUTI SHARMA SHRUTI SHARMA](https://www.c-sharpcorner.com/UploadFile/AuthorImage/DefaultAuthorImage.jpg.ashx?width=56&height=56)
I did try already, but this didnt work buddy
Aug 22, 2018
SHRUTI SHARMA
1797 15 0
![Sandeep Kumar Sandeep Kumar](https://www.c-sharpcorner.com/UploadFile/AuthorImage/18585c20150223032909.png.ashx?width=56&height=56)
What the problem you are facing ? Can you please describe here regarding the problem which you are facing. For reference regarding the problem u can refer the below link
Jan 24, 2019
Sandeep Kumar
415 4.3k 522.8k
![Sandeep Kumar Sandeep Kumar](https://www.c-sharpcorner.com/UploadFile/AuthorImage/18585c20150223032909.png.ashx?width=56&height=56)
Https://github.com/aloisdeniel/Microcharts
Jan 24, 2019
Sandeep Kumar
415 4.3k 522.8k
![SHRUTI SHARMA SHRUTI SHARMA](https://www.c-sharpcorner.com/UploadFile/AuthorImage/DefaultAuthorImage.jpg.ashx?width=56&height=56)
Hi can you let us know how to reduce diameter of pie chart
Aug 21, 2018
SHRUTI SHARMA
1797 15 0
![Logesh Palani Logesh Palani](https://www.c-sharpcorner.com/UploadFile/AuthorImage/384a1020180606031226.jpg.ashx?width=56&height=56)
Edit your height and width request <forms:ChartView x:Name="Chart6" HeightRequest="160"/>
Aug 22, 2018
Logesh Palani
278 6.8k 669.7k
![Maitri Palkhiwala Maitri Palkhiwala](https://www.c-sharpcorner.com/uploadfile/authorimage/defaultauthorimage.jpg.ashx?width=56&height=56)
Hi, Can u pls suggest how to implement two bar chart?
Aug 21, 2018
Maitri Palkhiwala
1802 10 0
![Logesh Palani Logesh Palani](https://www.c-sharpcorner.com/UploadFile/AuthorImage/384a1020180606031226.jpg.ashx?width=56&height=56)
Maitri Palkhiwala you can use various values to use no.of Bar Chart's [Code ] - Chart.Chart = new BarChart() { Entries = entries };
Aug 21, 2018
Logesh Palani
278 6.8k 669.7k
![Maitri Palkhiwala Maitri Palkhiwala](https://www.c-sharpcorner.com/uploadfile/authorimage/defaultauthorimage.jpg.ashx?width=56&height=56)
Thanks for Reply.. But I have a need for dual bar chart(two series..)
Aug 22, 2018
Maitri Palkhiwala
1802 10 0
![Sandeep Kumar Sandeep Kumar](https://www.c-sharpcorner.com/UploadFile/AuthorImage/18585c20150223032909.png.ashx?width=56&height=56)
Hi, Can u explain how to implement tap event in microcharts and how to work with dynamic data too
Dec 25, 2017
Sandeep Kumar
415 4.3k 522.8k
![Logesh Palani Logesh Palani](https://www.c-sharpcorner.com/UploadFile/AuthorImage/384a1020180606031226.jpg.ashx?width=56&height=56)
Https://github.com/aloisdeniel/Microcharts/tree/develop?files=1
Dec 25, 2017
Logesh Palani
278 6.8k 669.7k
![Sandeep Kumar Sandeep Kumar](https://www.c-sharpcorner.com/UploadFile/AuthorImage/18585c20150223032909.png.ashx?width=56&height=56)
They have not used the tap event at all...
Jan 24, 2019
Sandeep Kumar
415 4.3k 522.8k
![Ravishankar Velladurai Ravishankar Velladurai](https://www.c-sharpcorner.com/UploadFile/AuthorImage/89610f20190326115854.jpg.ashx?width=56&height=56)
Wow nice article bro..
Dec 11, 2017
Ravishankar Velladurai
259 7.2k 500.6k