How to import data from Excel and use in Chart.js
I want to draw a chart in chartjs with excel file:
I use the below code but it doesn't work and I don't know where is my problem:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Chartjs.aspx.vb" Inherits="Chartjs.Chartjs" %>
<!DOCTYPE html>
<script type="text/javascript" src="Chart.js"></script>
<script type="text/javascript" src="xlsx.full.min.js"></script>
<script type="text/javascript" src="chartjs-plugin-datasource.js"></script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<canvas id="myChart"></canvas>
<script>
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
type: 'bar',
plugins: [ChartDataSource],
options: {
daatasource: {
url: 'E:\sample-dataset.xlsx'
}
}
});
data: {
datasets: [{
type: 'line',
yAxisID: 'temperature',
backgroundColor: 'transparent',
borderColor: 'rgb(255, 99, 132)',
pointBackgroundColor: 'rgb(255, 99, 132)',
tension: 0,
fill: false
}, {
yAxisID: 'precipitation',
backgroundColor: 'rgba(54, 162, 235, 0.5)',
borderColor: 'transparent'
}]
}
options: {
scales: {
yAxes: [{
id: 'temperature',
gridLines: {
drawOnChartArea: false
}
}, {
id: 'precipitation',
position: 'right',
gridLines: {
drawOnChartArea: false
}
}]
}
options: {
daatasource: {
url: 'sample-index.xlsx',
rowMapping: 'index'
}
options: {
daatasource: {
url: 'sample-datapoint.xlsx',
rowMapping: 'datapoint',
datapointLabelMapping: {
_dataset: 'dataset',
_index: 'month',
x: 'month',
y: 'value'
}
}
options: {
daatasource: {
url: 'sample-dataset.xlsx',
datasetLabels: 'Sheet1!A2:A3',
indexLabels: 'Sheet1!D1:G1',
data: 'Sheet1!D2:G3'
}
</script>
</form>
</body>
</html>