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

@skinio/node-chartist

v1.0.7

Published

SVG Charts on the server.

Downloads

4

Readme

node-chartist

SVG Charts on the server.

Travis

Node Chartist is a functional server-side wrapper for the popular Chartist library. It generates static svg charts and adds support for a few useful features such as axis titles and chart legends.

Installation

npm install node-chartist

The accompanying CSS can be found at dist/main.css after installation.

Usage

const co = require('co');
const generate = require('node-chartist');

co(function * () {

  // options object
  const options = {width: 400, height: 200};
  const data = {
    labels: ['a','b','c','d','e'],
    series: [
      [1, 2, 3, 4, 5],
      [3, 4, 5, 6, 7]
    ]
  };
  const bar = yield generate('bar', options, data); //=> chart HTML


  // options function
  const options = (Chartist) => ({width: 400, height: 200, axisY: { type: Chartist.FixedScaleAxis } });
  const data = {
    labels: ['a','b','c','d','e'],
    series: [
      [1, 2, 3, 4, 5],
      [3, 4, 5, 6, 7]
    ]
  };
  const bar = yield generate('bar', options, data); //=> chart HTML

});

API

generate ( type , options , data )

A curried function that generates a static svg chart.

Returns a Promise that is fulfilled with the static chart HTML.

Arguments

  • type - A string used to determine what type of chart to generate. Supported values are:

    • bar
    • line
    • pie
  • options - An object or a function that returns an object of chart options. If a function is used, it will be called with the Chartist object.

    Options are dependent on the chart type. All options in the Chartist Api Documentation are supported. In addition to those, the following options are supported by node-chartist:

    • axisX.title - A string to use as the x axis title.

    • axisY.title - A string to use as the y axis title.

    • legend - A boolean used to determine whether a legend should be generated. Defaults to true.

  • data - An object containing data used to generate the chart. The structure of this object depends on chart type. Please refer to the Chartist Api Documentation for complete details.

    For bar and line charts, this object contains the following properties

    • labels - An array of string labels to apply to each value.

    • series - An array of arrays or objects containing the values to plot. If objects are used, the following properties are supported:

      • name - A string specifying the name of the series. The name will be used in the legend and will be set as the ct:series-name attribute on the series group.

      • value - An array of values for the series.

      • className - A string to override the CSS class name for the series group.

      • meta - Meta data is serialized and written to a ct:meta attribute on the series group.

      Examples:

      const data = {
        labels: ['a', 'b', 'c', 'd', 'e'],
        series: [
          [1, 2, 3, 4, 5],
          [3, 4, 5, 6, 7]
        ]
      };
      const data = {
        labels: ['a', 'b', 'c', 'd', 'e'],
        series: [
          {name: 'Series 1', value: [1, 2, 3, 4, 5]},
          {name: 'Series 2', value: [3, 4, 5, 6, 7]}
        ]
      };

    For pie charts, this object contains the following properties:

    • series - An array of values or objects containing values to plot. If objects are used, the following properties are supported:

      • name - A string specifying the name of the series. The name will be used in the legend and will be set as the ct:series-name attribute on the series group.

      • value - An array of values for the series.

      • className - A string to override the CSS class name for the series group.

      • meta - Meta data is serialized and written to a ct:meta attribute on the series group.

      Examples:

      const data = {
        series: [ 15, 25 ]
      };
      const data = {
        series: [
          {name: 'Series 1', value: 15 },
          {name: 'Series 2', value: 25 }
        ]
      };

Examples

Bar:

co(function * () {
  const options = {
    width: 400,
    height: 200,
    axisX: { title: 'X Axis (units)' },
    axisY: { title: 'Y Axis (units)' }
  };

  const bar = yield generate('bar', options, {
    labels: ['a', 'b', 'c', 'd', 'e'],
    series: [
      {name: 'Series 1', value: [1, 2, 3, 4, 5]},
      {name: 'Series 2', value: [3, 4, 5, 6, 7]}
    ]
  });
})

Line:

co(function * () {
  const options = {
    width: 400,
    height: 200,
    axisX: { title: 'X Axis (units)' },
    axisY: { title: 'Y Axis (units)' }
  };

  const line = yield generate('line', options, {
    labels: ['a', 'b', 'c', 'd', 'e'],
    series: [
      {name: 'Series 1', value: [1, 2, 3, 4, 5]},
      {name: 'Series 2', value: [3, 4, 5, 6, 7]}
    ]
  });
})

Pie:

co(function * () {
  const options = { width: 400, height: 200 };

  const pie2 = yield generate('pie', options, {
    series: [
      {name: 'Series 1', value: 15 },
      {name: 'Series 2', value: 25 }
    ]
  });
})