Chart.jsで折れ線グラフを表示
code:script.js
/* Chart.js(Scrapbox上にソースは上げた)を使って、折れ線グラフを描画・表示する */
// debugger;
(function(){
async function loadScript(src) {
const script = document.createElement('script');
script.src = src;
const promise = new Promise(resolve => {
script.addEventListener('load', resolve);
});
document.body.appendChild(script);
return promise;
}
async function drawChartJS() {
let chartElm = document.createElement('div');
chartElm.id = 'chart1';
document.body.appendChild(chartElm);
document.querySelector('#chart1').innerHTML = `
<div><canvas id="myChart"></canvas></div>
`;
const ctx = document.getElementById('myChart');
new Chart(ctx, {
type: 'bar',
data: {
datasets: [{
label: '# of Votes',
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
// });
}
console.info('7');
setTimeout(()=> drawChartJS(), 2000);
})();