Available charts Microcharts.Forms Plugin
  • Barchart
  • PointChart
  • LineChart
  • DonutChart
  • RadialGaugeChart
  • RadarChart
Step 1

You can create Xamarin.Forms apps by going to File >> New >> Visual C# >> Android >> Blank App. Just give the application a name and press OK.

Step 2

Now, add the following NuGet Package for your projects.

nuGet package : search "Microcharts" and not "Microcharts.Forms"

Step 3 Main.axml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5. <LinearLayout
  6. android:orientation="vertical"
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content">
  9. <microcharts.droid.ChartView
  10. android:id="@+id/chartView"
  11. android:layout_width="match_parent"
  12. android:layout_height="160dp" />
  13. <microcharts.droid.ChartView
  14. android:id="@+id/Chart2"
  15. android:layout_width="match_parent"
  16. android:layout_height="160dp"/>
  17. <microcharts.droid.ChartView android:id="@+id/Chart3"
  18. android:layout_width="match_parent"
  19. android:layout_height="160dp"/>
  20. <microcharts.droid.ChartView android:id="@+id/Chart4"
  21. android:layout_width="match_parent"
  22. android:layout_height="160dp"/>
  23. <microcharts.droid.ChartView android:id="@+id/Chart5"
  24. android:layout_width="match_parent"
  25. android:layout_height="160dp"/>
  26. <microcharts.droid.ChartView android:id="@+id/Chart6"
  27. android:layout_width="match_parent"
  28. android:layout_height="160dp"/>
  29. </LinearLayout>
  30. </ScrollView>
Step 4

In this step, add data entries. For that, open Solution Explorer >> click open MainPage.xaml.cs.
  1. using Android.App;
  2. using Android.Widget;
  3. using Android.OS;
  4. using System.Collections.Generic;
  5. using Microcharts;
  6. using SkiaSharp;
  7. using Entry = Microcharts.Entry;
  8. using Microcharts.Droid;
  9. namespace App1
  10. {
  11. [Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")]
  12. public class MainActivity : Activity
  13. {
  14. List<Entry> entries = new List<Entry>
  15. {
  16. new Entry(200)
  17. {
  18. Color=SKColor.Parse("#FF1943"),
  19. Label ="January",
  20. ValueLabel = "200"
  21. },
  22. new Entry(400)
  23. {
  24. Color = SKColor.Parse("00BFFF"),
  25. Label = "March",
  26. ValueLabel = "400"
  27. },
  28. new Entry(-100)
  29. {
  30. Color = SKColor.Parse("#00CED1"),
  31. Label = "Octobar",
  32. ValueLabel = "-100"
  33. },
  34. };
  35. protected override void OnCreate(Bundle bundle)
  36. {
  37. base.OnCreate(bundle);
  38. // Set our view from the "main" layout resource
  39. SetContentView (Resource.Layout.Main);
  40. var chartView = FindViewById<ChartView>(Resource.Id.chartView);
  41. var chartview2 = FindViewById<ChartView>(Resource.Id.Chart2);
  42. var chartview3 = FindViewById<ChartView>(Resource.Id.Chart3);
  43. var chartview4 = FindViewById<ChartView>(Resource.Id.Chart4);
  44. var chartview5 = FindViewById<ChartView>(Resource.Id.Chart5);
  45. var chartview6 = FindViewById<ChartView>(Resource.Id.Chart6);
  46. var chart = new RadialGaugeChart() { Entries = entries };
  47. var chart2 = new LineChart() { Entries = entries };
  48. var chart3 = new DonutChart() { Entries = entries };
  49. var chart4 = new PointChart() { Entries = entries };
  50. var chart5 = new RadarChart() { Entries = entries };
  51. var chart6 = new BarChart() { Entries = entries };
  52. chartView.Chart = chart;
  53. chartview2.Chart = chart2;
  54. chartview4.Chart = chart3;
  55. chartview3.Chart = chart4;
  56. chartview5.Chart = chart5;
  57. chartview6.Chart = chart6;
  58. // https://stackoverflow.com/questions/47407895/exception-while-loading-assemblies-system-io-filenotfoundexception-could-not-l
  59. }
  60. }
  61. }
Step 5

If you find any error like Tuple, please follow the below link.

https://stackoverflow.com/questions/47407895/exception-while-loading-assemblies-system-io-filenotfoundexception-could-not-l
If you need multiple colors, then use the below code.
  1. var entries = new[]
  2. {
  3. new Entry(200)
  4. {
  5. Label = "January",
  6. ValueLabel = "200",
  7. Color = SKColor.Parse(HexConverter())
  8. },
  9. new Entry(400)
  10. {
  11. Label = "February",
  12. ValueLabel = "400",
  13. Color = SKColor.Parse(HexConverter())
  14. },
  15. new Entry(-100)
  16. {
  17. Label = "March",
  18. ValueLabel = "-100",
  19. Color = SKColor.Parse(HexConverter())
  20. }
  21. };
  22. //var chart = new BarChart() { Entries = entries };
  23. var chartView = view.FindViewById<ChartView>(Resource.Id.chartView1);
  24. var chartview2 = view.FindViewById<ChartView>(Resource.Id.chartView2);
  25. var chartview3 = view.FindViewById<ChartView>(Resource.Id.chartView3);
  26. var chartview4 = view.FindViewById<ChartView>(Resource.Id.chartView4);
  27. var chartview5 = view.FindViewById<ChartView>(Resource.Id.chartView5);
  28. var chartview6 = view.FindViewById<ChartView>(Resource.Id.chartView6);
  29. var chart = new RadialGaugeChart() { Entries = entries };
  30. var chart2 = new LineChart() { Entries = entries };
  31. var chart3 = new DonutChart() { Entries = entries };
  32. var chart4 = new PointChart() { Entries = entries };
  33. var chart5 = new RadarChart() { Entries = entries };
  34. var chart6 = new BarChart() { Entries = entries };
  35. chartView.Chart = chart;
  36. chartview2.Chart = chart2;
  37. chartview4.Chart = chart3;
  38. chartview3.Chart = chart4;
  39. chartview5.Chart = chart5;
  40. chartview6.Chart = chart6;
  41. private static string HexConverter()
  42. {
  43. Android.Graphics.Color c = new Android.Graphics.Color((int)(Java.Lang.Math.Random() * 0x1000000));
  44. return "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
  45. }
Finally, we have successfully created Xamarin Android Microcharts application.