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 🙏

© 2025 – Pkg Stats / Ryan Hefner

chartist-to-image

v1.2.1

Published

Renders images from 'chartist' charts

Downloads

65

Readme

chartist-to-image

Build Status

Generating chart images from "Chartist" charts was a bit of challange, but now by using this module you can render images of your chartist chart without any hassle.

Installation

$ npm install chartist-to-image --save

Usage

Following will describes to how to use chartist-to-image on Angular 2-5, but also you can take insight from following to implement in js

Import

import chartist2image from 'chartist-to-image';
or
import * as chartist2image from 'chartist-to-image';

Calling

chartistChart = new Chartist.Line/Pie('chart name',data,chartOptions);
let options = {
  outputImage: {
    quality: 0.35,
    bgcolor: '#000000',
    name: 'my-chartist-charts'
  },
  format: 'jpeg',
  download: true,
  log: true,

};
let base64;
async genImage(){
this.chartist2image = chartist2image;
await chartist2image.toJpeg('**HTML div ID which contains chartist chart**',options,chartistChart).then(
  (res) => {
    base64 = res;
    console.log('Logged >>>>>>>>',base64);
  }
);
}

It is better to use chartist-to-image with async and wait since it takes some time to render the image.

After it generates the 'base64' value you can easily use it on an HTML like

<img src=base64-string><img>

Currently chartist-to-image generates only .jpeg's, but in future we will add other formats as well.

Attention!

(if you are passing the Chartist instance to chartist2image.toJpeg() you don't want to worry about this) Most of the image rendering packages not compatible with "Chartist" because chartist uses <foreignObject> in their svgs. So becuase of that you have to replace <foreignObject> by using <text> This can be easily done like,

var chartistLineChart = new Chartist.Line('.ct-chart', data, options); chartistLineChart.supportsForeignObject = false;

if you are using angular 2-5

this.chartistLineChart = new Chartist.Line('.ct-chart', data, options); this.chartistLineChart.supportsForeignObject = false;

Or you can pass your Chartist chart instance to chartist2image function, it will do that for you.

chartistChart = new Chartist.Line/Pie('chart name',data,options);
async genImage(){
this.chartist2image = chartist2image;
await chartist2image.toJpeg('pie-chart-content',options,chartistChart).then(
(res) => {
base64 = res;
console.log('Logged >>>>>>>>',base64)
});}

Options

'chartist-to-image' accepts a 'json' object which is having following attributes

| Attribute | Default |Other | |----------------|-------------------------------|-----------------------------| |outputImage|json Attributes quality: 1.00,bgcolor: '#000000', name: 'Chart Image' |'quality: 0-1 bgcolor: {#anyColor} name: {your's name to chart} | |format |`.jpeg |More formats in further releases | |download |true auto download the image after rendering|false|

Credits

The rendering of the image done suing 'dom-to-image' library. It is a great module to render images from HTML and SVGs. 'chartist-to-image' has been modified according to support for Chartist charts rendering. Since the source is embedded to this module, you don't have to download it as a dependency.