1.0.27 • Published 3 years ago

charts-rendering v1.0.27

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

Charts Rendering

Module for charts rendering on server-side using front-end libraries(e.g. highcharts, chart.js). It uses Puppeteer, modular and written in TypeScript.

Supported charts libraries

Right now it supports Highcharts and Chart.js out-of-box.

Installation

npm install charts-rendering

Usage

const { render, exporters } = require('charts-rendering');

render(exporters.highcharts, {
  init: {
    // viewport of Puppeteer instance, it's better to be bigger than supposed chart size
    width: 500,
    height: 500,
    // charts-rendering supports injecting javascript code
    // in the form of script tags into rendering environment
    // that could be other libraries for formatting, styles, dates etc
    jsInject: [{
      path: 'path/to/js/file',
    }],
  },
  // You can specify more than one chart config for bunch rendering
  // (with single Puppeteer instance)
  charts: [{
    file: {
      // where to save chart
      path: './output.png',
    },
    // this is simply highcharts creation config
    config: {
      chart: {
        width: 300,
        height: 100,
      },
      title: {
        text: 'My Chart'
      },
      yAxis: {
        labels: {
          // call injected code
          formatter: ({ value }) => { return injectedCode(value) },
        },
      },
      xAxis: {
        categories: ["Jan", "Feb", "Mar", "Apr", "Mar", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
      },
      series: [
        {
            type: 'line',
            data: [1, 3, 2, 4]
        },
        {
            type: 'line',
            data: [5, 3, 4, 2]
        }
      ]
    }
  }]
});

Adding support for other chart libraries

You can check src/exporters/highcharts.ts for example. TBD

1.0.22

3 years ago

1.0.21

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.27

3 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago