Skip to main content

Chart

A chart Node that imports ChartJS and uses it to render a nice bar chart.

Features used in this example:

  • NPM imports.
  • View rendering using various frameworks.

Example

A chart node without using any external libraries.

 

manifest.yaml
name: ChartJS
description: Chart powered by ChartJS!
properties.yaml
view:
datatype: web-view
src/main.jsx
import Chart from 'chart.js/auto';

function renderChart(canvas) {
new Chart(canvas, {
type: 'bar',
data: {
labels: ['S', 'M', 'T', 'W', 'T', 'F'],
datasets: [
{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1,
},
],
},
options: {
plugins: {
legend: {
display: false,
},
},
scales: {
y: {
beginAtZero: true,
},
},
},
});
}

function render(element) {
const canvas = document.createElement('canvas');

element.appendChild(canvas);
renderChart(canvas);
}

context.set('view', render);