QuickChart JavaScript Client

3.1.3 · active · verified Sun Apr 19

quickchart-js is the official JavaScript client library for QuickChart.io, a web service that renders static Chart.js images from a URL or POST request. It allows developers to programmatically generate highly customizable charts for various applications like email, SMS, or chat platforms. The library wraps the QuickChart API, simplifying the process of setting chart configurations (based on Chart.js syntax), dimensions, formats, and retrieving either long encoded URLs, short shareable URLs, or saving charts directly to a file. The current stable version is 3.1.3, with updates released periodically, typically every few months, reflecting active maintenance. A key differentiator is its ability to convert dynamic Chart.js configurations into static images, offering robust integration options where dynamic JavaScript charting is not feasible.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure a Chart.js bar chart, customize its properties, retrieve both long and short URLs, and save the generated image to a local file.

import { QuickChart } from 'quickchart-js';
import * as fs from 'fs/promises';

const myChart = new QuickChart();
myChart.setConfig({
  type: 'bar',
  data: {
    labels: ['January', 'February', 'March', 'April', 'May'],
    datasets: [
      { label: 'Dogs', data: [50, 60, 70, 180, 190] },
      { label: 'Cats', data: [100, 200, 300, 400, 500] }
    ],
  },
  options: {
    plugins: {
      legend: { position: 'top' },
      title: { display: true, text: 'Monthly Pet Counts' },
    },
  },
});

myChart.setWidth(800);
myChart.setHeight(400);
myChart.setFormat('png');
myChart.setBackgroundColor('#f8f8f8');

async function generateCharts() {
  // Get the direct URL
  console.log('Direct Chart URL:', myChart.getUrl());

  // Get a short, fixed-length URL (requires network request)
  try {
    const shortUrl = await myChart.getShortUrl();
    console.log('Short Chart URL:', shortUrl);
  } catch (error) {
    console.error('Failed to get short URL:', error);
  }

  // Write the chart to a file
  const filePath = './mychart.png';
  try {
    await myChart.toFile(filePath);
    console.log(`Chart saved to ${filePath}`);
  } catch (error) {
    console.error('Failed to save chart to file:', error);
  }
}

generateCharts();

view raw JSON →