<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js">
</script>
<div>
<canvas id="canvas"></canvas>
</div>
<script>
let DATE = [];
let PRICE = [];
let csvPath = '************/data_histogram.csv'
let req = new XMLHttpRequest();
req.open('get', csvPath, true);
req.send(null);
req.onload = function() {
makeGraphData();
drawGraph();
function makeGraphData() {
let reqArray = req.responseText.split('\n');
reqArray.forEach((element) => {
let 行データ = element.split(',')
let index_DATE = reqArray[0].split(',').indexOf('CHANGE');
let index_PRICE = reqArray[0].split(',').indexOf('COUNT');
if(行データ[index_DATE] !== undefined) {
DATE.push(Number(行データ[index_DATE]));
};
if(行データ[index_PRICE] !== undefined) {
PRICE.push(Number(行データ[index_PRICE]));
};
});
removeHeader()
function removeHeader() {
DATE.shift();
PRICE.shift();
}
}
function drawGraph() {
let ctx = document.getElementById('canvas').getContext('2d');
let グラフ = new Chart(ctx, {
type: 'bar',
data: {
labels:DATE,
datasets: [{
label: "株価変化率",
data:PRICE,
}],
},
options: {
responsive: false
},
})
}
}
</script>