Xamarin.Plugin.ChartJS 1.0.0-beta

This is a prerelease version of Xamarin.Plugin.ChartJS.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Xamarin.Plugin.ChartJS --version 1.0.0-beta
NuGet\Install-Package Xamarin.Plugin.ChartJS -Version 1.0.0-beta
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Xamarin.Plugin.ChartJS" Version="1.0.0-beta" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Xamarin.Plugin.ChartJS --version 1.0.0-beta
#r "nuget: Xamarin.Plugin.ChartJS, 1.0.0-beta"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Xamarin.Plugin.ChartJS as a Cake Addin
#addin nuget:?package=Xamarin.Plugin.ChartJS&version=1.0.0-beta&prerelease

// Install Xamarin.Plugin.ChartJS as a Cake Tool
#tool nuget:?package=Xamarin.Plugin.ChartJS&version=1.0.0-beta&prerelease

XamarinChartJS

An easy to use (or at least intented to be easy) Nuget Package for Xamarin.Forms to use Chart.js in Xamarin with C# configurations. This came about because looking for a full featured charting library that doesn't cost hundreds if not thousands for a license on Mobile is not easy. And when you find an open source native library, they are pretty good but nothing compared to what the Web world has had for so long. In my research I found a proof of concept of the idea of using Charts in WebViews and I extended that idea with Chart.js, one of my favorite Web charting frameworks.

Features

  • 100% C# Configuration
  • Bindings support for View and Chart configuration
  • Runs Offline

Current Target Versions

Platform Version Why
Chart.js 3.2.0 Latest version on initial development. Other versions have not been tested but may work.

Setup

Install Plugin

  • Add Xamarin.Plugin.ChartJS into your Xamarin Shared project only.

Note: The plugin only needs to be installed in the shared project right now. In upcoming versions, the plan is to add custom renderers to enable some extra features and more clean cross platform usage.

Add Local Chart.js File

For the plugin to work, you must add a copy of Chart.js 3.2.0 to both iOS and Android projects as shown below. This is what enables it to work offline. You can download it from here: following link Chart.js 3.2.0 CDN Link

  • Android
    1. Add the file downloaded above to your Assets Android folder and name it chart.min.js
    2. Set the Build Action to AndroidAsset
  • iOS
    1. Add the file downloaded above to your Resources iOS folder and name it chart.min.js
    2. Set the Build Action to BundleResource

How to Use

The best way to see examples is to clone the repo and run the Sample project. A working version of Android and iOS are implemented there with examples of all use cases used during development. As new features are added and bugs found, more examples will be added there for clarity. Below is the TLDR if needed.

TLDR Setup

Add this to your XAML header

xmlns:views="clr-namespace:Plugin.XamarinChartJS;assembly=Xamarin.Plugin.ChartJS"

Add this into your page content

<views:ChartView Config="{Binding ChartConfig}" HeightRequest="200"/>

Add a chart Config that can be binded to in your backend (page or viewModel)

public ChartViewConfig ChartConfig { get; set; }

Note: You can also dynamically add ChartViews purely from code as you would any other view.

Configuring the Chart

The ChartViewConfig object contains two things. The view settings and the Chart.js configuration which is meant to be 1-1 with the Javscript settings provided by Chart.js. All properties in this object are bound to the ChartView so if you change them, the Chart will dynamically update from that.

public Color BackgroundColor    //The views background color
public ChartConfig ChartConfig  //The Chart.js config
// More to be added as needed

To configure the ChartConfig object, refer to the documentation on https://www.chartjs.org/ since it is just an extension of the JSON config specified there.

Helper Values

Where possible, helper constants and values are being added to help prevent typos. Below are some of what is available.

Plugin.XamarinChartJS.ChartTypes   //String constants for all Chart Types (line, bar, etc...)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0-beta 249 5/10/2021
1.1.0-beta 181 5/9/2021
1.0.0 2,563 5/15/2021
1.0.0-beta 314 5/9/2021
1.0.0-alpha 279 5/8/2021