All Projects → typpo → quickchart-js

typpo / quickchart-js

Licence: MIT license
Javascript client for quickchart.io

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to quickchart-js

Chart.qml
Chart.qml like Chart.js
Stars: ✭ 100 (+194.12%)
Mutual labels:  chartjs
Chartbrew
Open-source web platform for creating charts out of different data sources (databases and APIs) 📈📊
Stars: ✭ 199 (+485.29%)
Mutual labels:  chartjs
site
RailroadPM.org 2.x Site
Stars: ✭ 18 (-47.06%)
Mutual labels:  chartjs
Buy All Steam Games
see how much does it cost to buy all steam games
Stars: ✭ 110 (+223.53%)
Mutual labels:  chartjs
Chartjs Plugin Colorschemes
Predefined color schemes for Chart.js
Stars: ✭ 189 (+455.88%)
Mutual labels:  chartjs
Autoline
建议你使用更新的AutoLink平台
Stars: ✭ 227 (+567.65%)
Mutual labels:  chartjs
Yii2 Chartjs Widget
ChartJs Widget For Yii2
Stars: ✭ 95 (+179.41%)
Mutual labels:  chartjs
kafkaESK
An event-driven monitoring tool that can consume messages from Apache Kafka clusters and display the aggregated data on a dashboard for analysis and maintenance.
Stars: ✭ 79 (+132.35%)
Mutual labels:  chartjs
Chartjs Node
Create Chart.js Charts Server-side
Stars: ✭ 204 (+500%)
Mutual labels:  chartjs
vue3-chartjs
Vue3 wrapper for ChartJS
Stars: ✭ 122 (+258.82%)
Mutual labels:  chartjs
Django Jchart
📈 A Django package for plotting charts using the excellent Chart.JS library.
Stars: ✭ 115 (+238.24%)
Mutual labels:  chartjs
Stellar
Stellar is completely based on the latest version of Bootstrap 4. Stellar Admin is designed to reflect the simplicity and svelte of the components and UI elements and coded to perfection with well-organized code.
Stars: ✭ 176 (+417.65%)
Mutual labels:  chartjs
tailwind-dashboard-template
Mosaic Lite is a free admin dashboard template built on top of Tailwind CSS and fully coded in React. Made by
Stars: ✭ 1,662 (+4788.24%)
Mutual labels:  chartjs
Sysmon
A B/S mode system monitor for linux (demo http://199.247.1.240:2048)
Stars: ✭ 110 (+223.53%)
Mutual labels:  chartjs
quickchart-python
Python client for quickchart.io image charts web service
Stars: ✭ 31 (-8.82%)
Mutual labels:  chart-api
Gitpedia
A web application to 🔍 view a github's user profile in a more simple and beautiful way. Built using React, Chart JS 📊 , styled components 💅 and more 📦
Stars: ✭ 98 (+188.24%)
Mutual labels:  chartjs
Material Admin
Free Material Admin Template
Stars: ✭ 219 (+544.12%)
Mutual labels:  chartjs
Covid19-Tracker
The situation of the Coronavirus epidemic data around the World and details info in Vietnam.
Stars: ✭ 15 (-55.88%)
Mutual labels:  chartjs
robo-chart-web
📊 Transform Google sheets to pretty charts!
Stars: ✭ 28 (-17.65%)
Mutual labels:  chartjs
Chartboard
Simple dashboard to show widget chart
Stars: ✭ 23 (-32.35%)
Mutual labels:  chartjs

QuickChart for Javascript

npm npm Build Status

This is a Javascript client for quickchart.io, a web service for generating static charts. View the main QuickChart repository here.

Installation

If you are using npm:

npm install quickchart-js

Usage

This library provides a QuickChart object. Import it, instantiate it, and set your Chart.js config:

const QuickChart = require('quickchart-js');

const myChart = new QuickChart();
myChart.setConfig({
  type: 'bar',
  data: { labels: ['Hello world', 'Foo bar'], datasets: [{ label: 'Foo', data: [1, 2] }] },
});

Use getUrl() on your quickchart object to get the encoded URL that renders your chart:

console.log(myChart.getUrl());
// Prints:  https://quickchart.io/chart?c=%7Btype%3A%27bar%27%2Cdata%3A%7Blabels%3A%5B%27Hello+world%27%2C%27Foo+bar%27%5D%2Cdatasets%3A%5B%7Blabel%3A%27Foo%27%2Cdata%3A%5B1%2C2%5D%7D%5D%7D%7D&w=500&h=300&bkg=transparent&f=png

If you have a large or complicated chart, use getShortUrl() on your quickchart object to get a fixed-length URL using the quickchart.io web service:

const url = await myChart.getShortUrl();
console.log(url);
// Prints: https://quickchart.io/chart/render/f-a1d3e804-dfea-442c-88b0-9801b9808401

Or write it to disk:

myChart.toFile('/tmp/mychart.png');

The URLs produce this chart image:

Creating a QuickChart object

If you have an account ID and API key, authenticate using the QuickChart constructor:

const qc = new QuickChart(apiKey, accountId);

To use the free (community) version, leave it blank:

const qc = new QuickChart();

Customizing your chart

setConfig(chart: Object | string)

Use this config to customize the Chart.js config object that defines your chart. You must set this before generating a URL!

setWidth(width: int)

Sets the width of the chart in pixels. Defaults to 500.

setHeight(height: int)

Sets the height of the chart in pixels. Defaults to 300.

setFormat(format: string)

Sets the format of the chart. Defaults to png. svg is also valid.

setBackgroundColor(color: string)

Sets the background color of the chart. Any valid HTML color works. Defaults to #ffffff (white). Also takes rgb, rgba, and hsl values.

setDevicePixelRatio(ratio: float)

Sets the device pixel ratio of the chart. This will multiply the number of pixels by the value. This is usually used for retina displays. Defaults to 1.0.

setVersion(version: string)

Sets the Chart.js version to use (e.g. 2.9.4 or 3.4.0). Valid options are shown in the documentation.

setHost(host: string)

Sets the host of generated URLs. quickchart.io by default.

setScheme(scheme: string)

Sets the scheme of generated URLs. https by default.

Getting outputs

There are two ways to get a URL for your chart object.

getUrl(): string

Returns a URL that will display the chart image when loaded.

getShortUrl(): Promise

Uses the quickchart.io web service to create a fixed-length chart URL that displays the chart image. The Promise resolves with a URL such as https://quickchart.io/chart/render/f-a1d3e804-dfea-442c-88b0-9801b9808401.

Note that short URLs expire after a few days for users of the free service. You can subscribe to keep them around longer.

getSignedUrl(): string

Returns a URL that displays the chart image. It is signed with your user account to bypass rate limitations.

toBinary(): Promise

Creates a binary buffer that contains your chart image.

toDataUrl(): Promise

Returns a base 64 data URL beginning with data:image/png;base64.

toFile(pathOrDescriptor: PathLike | FileHandle): Promise

Given a filepath string or a writable file handle, creates a file containing your chart image.

More examples

Check out the examples/ directory to see other usage. Here's a simple test that uses some of the custom parameters:

const qc = new QuickChart();

qc.setConfig({
  type: 'bar',
  data: { labels: ['Hello world', 'Foo bar'], datasets: [{ label: 'Foo', data: [1, 2] }] },
});
qc.setWidth(500).setHeight(300).setBackgroundColor('transparent');

console.log(qc.getUrl());
// https://quickchart.io/chart?c=%7Btype%3A%27bar%27%2Cdata%3A%7Blabels%3A%5B%27Hello+world%27%2C%27Foo+bar%27%5D%2Cdatasets%3A%5B%7Blabel%3A%27Foo%27%2Cdata%3A%5B1%2C2%5D%7D%5D%7D%7D&w=500&h=300&bkg=transparent&f=png

Here's a more complicated chart that includes some Javascript:

qc.setConfig({
  type: 'bar',
  data: {
    labels: ['January', 'February', 'March', 'April', 'May'],
    datasets: [
      {
        label: 'Dogs',
        data: [50, 60, 70, 180, 190],
      },
    ],
  },
  options: {
    scales: {
      yAxes: [
        {
          ticks: {
            callback: function (value) {
              return '$' + value;
            },
          },
        },
      ],
    },
  },
});
qc.setWidth(500).setHeight(300).setBackgroundColor('#0febc2');

console.log(qc.getUrl());
// https://quickchart.io/chart?c=%7Btype%3A%27bar%27%2Cdata%3A%7Blabels%3A%5B%27January%27%2C%27February%27%2C%27March%27%2C%27April%27%2C%27May%27%5D%2Cdatasets%3A%5B%7Blabel%3A%27Dogs%27%2Cdata%3A%5B50%2C60%2C70%2C180%2C190%5D%7D%5D%7D%2Coptions%3A%7Bscales%3A%7ByAxes%3A%5B%7Bticks%3A%7Bcallback%3Afunction+%28value%29+%7B%0A++return+%27%24%27+%2B+value%3B%0A%7D%7D%7D%5D%7D%7D%7D&w=500&h=300&bkg=%230febc2&f=png

As we customize these charts, the URLs are getting a little long for my liking. There's a getShortUrl function that uses the QuickChart.io web service to generate a short(er), fixed-length URL:

// Fill the chart with data from 0 to 100
const data = [...Array(100).keys()];
qc.setConfig({
  type: 'bar',
  data: { labels: ['Hello world', 'Foo bar'], datasets: [{ label: 'Foo', data }] },
});

async function printShortUrl() {
  const url = await qc.getShortUrl();
  console.log(url);
}
printShortUrl();
// https://quickchart.io/chart/render/f-a1d3e804-dfea-442c-88b0-9801b9808401

Using built-in QuickChart functions

QuickChart has builtin functions: getImageFill, getGradientFill, getGradientFillHelper, and pattern.draw. These functions can be accessed via the QuickChart class. For example:

const qc = new QuickChart();
qc.setConfig({
  type: 'bar',
  data: {
    labels: ['Hello world', 'Foo bar'],
    datasets: [
      {
        label: 'Foo',
        data: [1, 2],
        backgroundColor: QuickChart.getGradientFillHelper('horizontal', ['red', 'green']),
      },
    ],
  },
});

Building the library

To build this library locally, run:

yarn build

To run tests:

yarn test

If you're editing the library and running examples, you may want to continuously build the library in the background:

yarn build:watch

# ...

node examples/simple_example.js
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].