Giter Site home page Giter Site logo

dorisoy / xf_chartjs Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 550 KB

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.

C# 100.00%

xf_chartjs's Introduction

Plugin Icon

XamarinChartJS

Nuget .NET

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...)

xf_chartjs's People

Contributors

christophermwood avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

bubdm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.