npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nativescript-community/ui-chart

v2.0.5

Published

A powerful chart / graph plugin, supporting line, bar, pie, radar, bubble, and candlestick charts as well as scaling, panning and animations.

Downloads

1,090

Readme

npm npm GitHub forks GitHub stars

Installation

  • tns plugin add @nativescript-community/ui-chart

Migration to 2.x

In 2.x most methods like setColor/getColor have been changed to properties like color You can either to it manually and update them all (you should get tsc errors for removed or renamed methods), or you can use a regexp like /set([A-Z])(\w*?)\(/ to search and replace (first group should be lowercase in the replace) with something like \L$1$2=( Then use typings to fix potential name change

Usage

For gestures to work, make sure to add the following code block inside main application file (e.g. app.ts):

import { install } from '@nativescript-community/ui-chart';
install();

You can also check Wiki for any useful material.

Plain NativeScript

IMPORTANT: Make sure you include xmlns:ch="@nativescript-community/ui-chart" on the Page element.

XML

<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:ch="@nativescript-community/ui-chart">
    <ScrollView>
        <StackLayout>
            <Label text="Line Chart" fontSize="20"/>
            <ch:LineChart id="line-chart" backgroundColor="lightgray" width="300" height="350" loaded="onLineChartLoaded"/>
        </StackLayout>
    </ScrollView>
</Page>

TypeScript

import { LineChart } from '@nativescript-community/ui-chart/charts/LineChart';
import { LineDataSet } from '@nativescript-community/ui-chart/data/LineDataSet';
import { LineData } from '@nativescript-community/ui-chart/data/LineData';

export function onLineChartLoaded(args) {
    const chart = args.object as LineChart;

    chart.dragEnabled = true;
    chart.scaleEnabled = true;

    const data = new Array(500).fill(0).map((v, i) => ({
        index: i,
        value: Math.random() * 1,
    }));

    const sets = [];
    const set = new LineDataSet(data, 'Legend Label', 'index', 'value');
    set.color = 'blue';
    sets.push(set);

    // Create a data object with the data sets
    const ld = new LineData(sets);

    // Set data
    chart.data = ld;
}

NativeScript + Vue

Vue.registerElement('LineChart', () => require('@nativescript-community/ui-chart').LineChart);
<LineChart ref="chart" width="300" height="400" @loaded="onChartLoaded"> </LineChart>
import { LineChart } from '@nativescript-community/ui-chart/charts/LineChart';
import { LineDataSet } from '@nativescript-community/ui-chart/data/LineDataSet';
import { LineData } from '@nativescript-community/ui-chart/data/LineData';
onChartLoaded() {
    const chart = this.$refs.chart['nativeView'] as LineChart;
    chart.backgroundColor = 'white';

    chart.drawGridBackground = false;

    // enable scaling and dragging
    chart.dragEnabled = true;
    chart.scaleEnabled = true;

    // force pinch zoom along both axis
    chart.petPinchZoomEnabled = true;

    // disable dual axis (only use LEFT axis)
    chart.axisRight.enabled = false;

    const myData = new Array(500).fill(0).map((v, i) => ({
        index: i,
        value: Math.random() * 1,
    }));

    const sets = [];
    const set = new LineDataSet(myData, 'Legend Label', 'index', 'value');
    set.setColor('blue');
    sets.push(set);

    // Create a data object with the data sets
    const ld = new LineData(sets);

    // Set data
    chart.data = ld;
}

NativeScript + Angular

Register the element in app.module.ts

registerElement('LineChart', () => require('@nativescript-community/ui-chart').LineChart);
<LineChart width="300" height="400" (loaded)="onChartLoaded($event)"> </LineChart>
import { LineChart } from '@nativescript-community/ui-chart/charts/LineChart';
import { LineDataSet } from '@nativescript-community/ui-chart/data/LineDataSet';
import { LineData } from '@nativescript-community/ui-chart/data/LineData';
onChartLoaded(args) {
    const chart = args.object as LineChart;
    chart.backgroundColor = 'white';

    chart.drawGridBackground = false;

    // enable scaling and dragging
    chart.dragEnabled = true;
    chart.scaleEnabled = true;

    // force pinch zoom along both axis
    chart.petPinchZoomEnabled = true;

    // disable dual axis (only use LEFT axis)
    chart.axisRight.enabled = false;

    const myData = new Array(500).fill(0).map((v, i) => ({
        index: i,
        value: Math.random() * 1,
    }));

    const sets = [];
    const set = new LineDataSet(myData, 'Legend Label', 'index', 'value');
    set.color = 'blue';
    sets.push(set);

    // Create a data object with the data sets
    const ld = new LineData(sets);

    // Set data
    chart.data = ld;
}

About

This plugin is based on MPAndroidChart, a powerful & easy to use chart library. Therefore, special thanks goes to Philipp Jahoda, the creator of MPAndroidChart and the rest of his team.

Instead of directly importing existing native libraries, this library has been rewritten in TypeScript, using @nativescript-community/ui-canvas plugin API as a basis. Plugin 'ui-canvas' is an extremely powerful tool that converts Android Native Canvas API to a cross-platform API for NativeScript framework. In few words, 'ui-chart' has the same code-base for both Android and iOS.

Additionally, @nativescript-community/gesturehandler plugin is used for handling chart gestures.

In short, these are the benefits of rewriting library into a NativeScript plugin:

  • Same codebase for Android and iOS. Makes maintaining the library very easy.
  • Smaller apps size because there are no native libs or native frameworks to consume space. All done with the power of {N}

Originally, the main goal was to prevent the need for marshalling all datasets. This is extremely heavy, costly and unnecessary!

Upon running demo samples, one can conclude it is the fastest drawing library, in comparison to nativescript-ui-chart and nativescript-mpchart.

That is because:

  • It does not marshal or recreate any subset of the data sets, but directly uses the provided array instead
  • It can share the same data array between multiple datasets
  • It can still use the power of native arrays to NOT marshal arrays of positions while drawing lines with @nativescript-community/ui-canvas

Documentation

The NativeScript 'ui-chart' plugin is based on the MPAndroidChart library. In few words, its API is identical. The possibility to add API reference will be considered in the future.