Work in Progress: How to add Chart.js to your flow
function output(userData, context) {
setTimeout(() => {
// Savvy setup for displaying the chart
const chartEl = document.createElement("div");
chartEl.innerHTML = '<canvas id="myChart"></canvas>';
document.querySelector(".ComponentKey-chart_container").appendChild(chartEl);
const scriptEl = document.createElement("script");
scriptEl.src = "<https://cdn.jsdelivr.net/npm/chart.js>";
scriptEl.onload = loadChart;
document.body.appendChild(scriptEl);
//Chart.js setup (read the docs!)
const labels = ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"];
const data = {
labels: labels,
datasets: [
{
label: "# of Votes",
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1,
},
],
};
const config = {
type: "bar",
data: data,
options: {
scales: {
y: {
beginAtZero: true,
},
},
},
};
function loadChart() {
const myChart = new Chart(document.getElementById("myChart"), config);
}
}, 500);
}
PreviousWork in Progress: How to Duplicate a Container with All its ContentNextWork in Progress: How to Create Repeatable Button Components, Fetching from a Database
Last updated