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

dr-niels-google-charts

v1.1.1

Published

ES6 Google Charts Module that allows asynchronous loading

Downloads

1

Readme

These are some minor adjustments to the google-charts element from mmathias01 (https://github.com/mmathias01/google-charts), trying to get it working with Polymer 3. The readme was not updated and is still the one from the original google-charts element!

google-charts

NPM

ES6 Google Charts Module that allows asynchronous loading

Installation

yarn add -D google-charts

or

npm i -D google-charts

Quick Start

import {GoogleCharts} from 'google-charts';

//Load the charts library with a callback
GoogleCharts.load(drawChart);

function drawChart() {

    // Standard google charts functionality is available as GoogleCharts.api after load
    const data = GoogleCharts.api.visualization.arrayToDataTable([
        ['Chart thing', 'Chart amount'],
        ['Lorem ipsum', 60],
        ['Dolor sit', 22],
        ['Sit amet', 18]
    ]);
    const pie_1_chart = new GoogleCharts.api.visualization.PieChart(document.getElementById('chart1'));
    pie_1_chart.draw(data);
}

Advanced Usage

import {GoogleCharts} from 'google-charts';

//Load the 'corecharts'. You do not need to provide that as a type.
GoogleCharts.load(drawCharts);

/* 
* Load a specific type(s) of chart(s). You can call this as many times as you need from anywhere in your app
* GoogleCharts is a singleton and will not allow the script to be loaded more than once
*/
GoogleCharts.load(drawGeoChart, 'geochart');

function drawCharts() {

    /* Pie chart 1 */
    const pie_1_data = GoogleCharts.api.visualization.arrayToDataTable([
        ['Chart thing', 'Chart amount'],
        ['Lorem ipsum', 60],
        ['Dolor sit', 22],
        ['Sit amet', 18]
    ]);
    const pie_1_options = {
        pieHole: 0.8,
        pieSliceTextStyle: {
            color: 'black',
        },
        slices: {
            0: {color: '#7ec252'},
            1: {color: '#a4ce57'},
            2: {color: '#cfe4ad'}
        },
        legend: {
            position: 'bottom',
            textStyle: {
                color: 'black',
                fontSize: 13,
                fontName: 'EncodeSans'
            }
        },
        title: 'Chart 1',
        titleTextStyle: {
            color: 'black',
            fontSize: 13,
            fontName: 'EncodeSans'
        },
        chartArea: {left: 0, top: 0, width: '100%', height: '80%'},
        pieSliceText: 'none'
    };
    const pie_1_chart = new GoogleCharts.api.visualization.PieChart(document.getElementById('chart1'));
    pie_1_chart.draw(pie_1_data, pie_1_options);

    /* Column chart 1 */
    const col_1_data = GoogleCharts.api.visualization.arrayToDataTable([
        ['Chart 1', 'Lorem ipsum', 'Dolor sit', 'Sit amet'],
        ['Chart 1', 22, 10, 68]
    ]);
    
    const col_1_options = {
        legend: {
            position: 'bottom',
            textStyle: {
                color: 'black',
                fontSize: 13,
                fontName: 'EncodeSans'
            }
        },
        bar: {groupWidth: '25%'},
        colors: ['#808e97', '#b9c3ca', '#dde4e8'],
        isStacked: true,
        chartArea: {left: 0, top: 0, width: '100%', height: '80%'},
        axisTitlesPosition: 'none',
        hAxis: {textPosition: 'none', gridlines: {color: 'transparent'}, baselineColor: 'transparent'},
        vAxis: {textPosition: 'none', gridlines: {color: 'transparent'}, baselineColor: 'transparent'},
    };
    
    const col_1_chart = new GoogleCharts.api.visualization.ColumnChart(document.getElementById('chart2'));
    col_1_chart.draw(col_1_data, col_1_options);
}

function drawGeoChart() {

    /* Geo Chart */
    const geo_1_data = GoogleCharts.api.visualization.arrayToDataTable([
        ['State', 'Spend'],
        ['ID', {v:120000, f: '$120,000'}],
        ['CO', {v:567135, f: '$567,135'}],
        ['FL', {v:220000, f: '$220,000'}],
        ['NY', {v:1120000, f: '$1,120,000'}],
        ['CA', {v:5120000, f: '$5,120,000'}],
        ['AK', {v:101000, f: '$101,000'}],
        ['AZ', {v:311030, f: '$311,030'}]
    ]);
    const geo_1_options = {
        region: 'US',
        resolution: 'provinces',
        is3D: true,
        legend: {
            numberFormat:'$###,###'
        }
    }
    const geo_1_chart = new GoogleCharts.api.visualization.GeoChart(document.getElementById('geo_1_chart'));
    geo_1_chart.draw(geo_1_data, geo_1_options);
}