2👍
The easiest way is to use chartjs-plugin-datasource, which is leveraging SheetJS (js-xlsx).
Save the following excel file as mydata.xlsx
in the same directory as your html file.
+--------------+-------+-------+-------+-------+-------+-------+
| | Dia 1 | Dia 2 | Dia 3 | Dia 4 | Dia 5 | Dia 6 |
+--------------+-------+-------+-------+-------+-------+-------+
| OEE Real (%) | 60 | 30 | 65 | 59 | 58 | 49 |
+--------------+-------+-------+-------+-------+-------+-------+
| OEE Meta (%) | 30 | 45 | 62 | 47 | 55 | 11 |
+--------------+-------+-------+-------+-------+-------+-------+
Then, specify it in your script.
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
<script src="https://cdn.jsdelivr.net/npm/xlsx@0.14.3/dist/xlsx.full.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datasource@0.1.0"></script>
<div>
<canvas class="line-chart"></canvas>
</div>
<script>
var ctx = document.getElementsByClassName("line-chart");
//Type, data, options
var chartGraph = new Chart (ctx, {
type: 'line',
data: {
datasets: [{
borderWidth: 6,
borderColor: 'rgba(146, 242, 42, 0.85)',
fill: false
}, {
borderWidth: 6,
borderColor: 'rgba(207, 0, 15, 0.85)',
fill: false
}
]},
plugins: [ChartDataSource],
options: {
title: {
display: true,
fontSize: 20,
text: 'ENCARTUCHAMENTO 05'
},
scales: {
yAxes: [{
ticks: {
max: 100,
min: 0,
}
}]
},
plugins: {
datasource: {
url: 'mydata.xlsx'
}
}
}
});
</script>
Source:stackexchange.com