Package Exports
- chartjs-node-canvas
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chartjs-node-canvas) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
chartjs-node-canvas
A node renderer for Chart.js using canvas.
Usage
const { CanvasRenderService } = require('chartjs-node-canvas');
const width = 400;
const height = 400;
const configuration = {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
callback: (value: number) => '$' + value
} as any
}]
}
}
};
const chartCallback = (ChartJS) => {
ChartJS.defaults.global.responsive = true;
ChartJS.defaults.global.maintainAspectRatio = false;
};
(async () => {
const canvasRenderService = new CanvasRenderService(width, height, chartCallback);
const image = await canvasRenderService.renderToBuffer(configuration);
const dataUrl = await canvasRenderService.renderToDataURL(configuration);
const stream = canvasRenderService.renderToStream(configuration);
})();