Chart.js server side rendering example on the node.js environment.
Render various charts using Chart.js into the SVG format.
Chart.js uses the HTML5 Canvas API.
However, the node.js environment does not have the Canvas API by default.
With red-agate-svg-canvas,
you can render the charts on the server side.
This example uses no native modules, so it can be easily installed on various platforms.
Get started
$ git clone https://github.com/shellyln/chart.js-node-ssr-example.git$ cd chart.js-node-ssr-example$ rm -rf ./.git $ npm install$ npm run build$ npm start
Example
;; // Get the global scope.// If running on a node, "g" points to a "global" object.// When running on the browser, "g" points to the "window" object.; // Chart options// https://www.chartjs.org/docs/latest/getting-started/usage.html;
Rendering results
Bar
Donut
Line
Area
Notes
To import the red-agate-svg-canvas, you need to use babel
+ webpack
.
(We have used the import
statements for doing the tree-shaking. The import
statements in the .js
not the .mjs
files cannot import from the vanilla node.js.)