Xamarin Pack Programmer's Guide
Getting Started with Charting Library

1. Select File -> New -> Solution in the Xamarin Studio menu. Then select Multiplatform App -> Xamarin.Forms (Forms App). Click 'Next'. Type in the name of your application, say, MyChartApp, select the target platforms - Android, iOS and/or UWP - and click 'Next'. Choose the location of your solution and click 'Create'.

2. Expand the shared project MyChartApp and add references to the MindFusion.Common.dll, MindFusion.Charting.dll and MindFusion.Licensing.dll assemblies. Open the MyChartAppPage.xaml file located in the same project. In the root ContentPage tag declare a new XML namespace to MindFusion.Charting, as follows:

XAML  Copy Code

xmlns:calendar="clr-namespace:MindFusion.Charting.Controls;assembly=MindFusion.Charting;"

3. Now you can add dashboards or charts to the page. Dashboard lets you display multiple plots and axes in dynamic layout. Chart controls display a single plot and type of graphics by default, but new ones can be added to them as well. For example, create a bar chart:

XAML  Copy Code

<calendar:BarChart x:Name="myChart" />

4. You can now add data to the chart's Series collection. Open the code behind file MyChartAppPage.xaml.cs and add data series using either ones of the pre-defined series classes (such as SimpleSeries, Series2D, XmlSeries, DataBoundSeries) or by implementing the Series interface in your own model class. For example:

C#  Copy Code

myChart.Series = new ObservableCollection<Series>
{
    new BarSeries(
        new List<double> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 },
        new List<string> { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve" },
        null
    )
    { Title = "Series 1" }
};

Don't forget to add the necessary namespace at the top of the file:

C#  Copy Code

using System.Collections.Generic;
using System.Collections.ObjectModel;
using MindFusion.Charting;

5. Now, add references to the core assemblies MindFusion.Common.dll and MindFusion.Charting.dll followed by the respective platform assemblies to the individual platform projects. More specifically, add MindFusion.Common.Android.dll and MindFusion.Charting.Android.dll to MyChartApp.Droid and MindFusion.Common.iOS.dll and MindFusion.Charting.iOS.dll to MyChartApp.iOS, and MindFusion.Common.Universal.dll and MindFusion.Charting.Universal.dll to MyChartApp.Universal.

Android

If targeting Android:

  1. Add a reference to MindFusion.Charting.dll, MindFusion.Charting.Android.dll, MindFusion.Common.dll and MindFusion.Common.Android.dll to your solution's Android project.
  2. In MainActivity.cs, call MindFusion.Charting.Android.Platform.Init after Xamarin initialization code.

C#  Copy Code

protected override void OnCreate(Bundle savedInstanceState)
{
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;

    base.OnCreate(savedInstanceState);

    Xamarin.Essentials.Platform.Init(this, savedInstanceState);
    global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
    MindFusion.Charting.Android.Platform.Init();

    LoadApplication(new App());
}

iOS

If targeting iOS:

  1. Add a reference to MindFusion.Charting.dll, MindFusion.Charting.iOS.dll, MindFusion.Common.dll and MindFusion.Common.iOS.dll to your solution's iOS project.
  2. In AppDelegate.cs, call MindFusion.Charting.iOS.Platform.Init after Xamarin initialization code.

C#  Copy Code

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init();
    MindFusion.Charting.iOS.Platform.Init();

    LoadApplication(new App());

    return base.FinishedLaunching(app, options);
}

Universal Windows

If targeting UWP:

  1. Add a reference to MindFusion.Charting.dll, MindFusion.Charting.Universal.dll, MindFusion.Common.dll and MindFusion.Common.Universal.dll assemblies to your solution's UWP project.
  2. In App.xaml.cs, call MindFusion.Charting.Universal.Platform.Init after Xamarin initialization code.

C#  Copy Code

Frame rootFrame = Window.Current.Content as Frame;

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
    // Create a Frame to act as the navigation context and navigate to the first page
    rootFrame = new Frame();

    rootFrame.NavigationFailed += OnNavigationFailed;

    Xamarin.Forms.Forms.Init(e);
    MindFusion.Charting.Universal.Platform.Init();
   ...
}

6. Build and run the solution to see the result.

7. If you need to build a more complex dashboard, follow Tutorial 1.