var chartColors = {
red: 'rgb(255, 99, 132)',
blue: 'rgb(54, 162, 235)'
};
var color = Chart.helpers.color;
var config = {
type: 'bar',
data: {
datasets: [{
type: 'line',
yAxisID: 'temperature',
backgroundColor: 'transparent',
borderColor: chartColors.red,
pointBackgroundColor: chartColors.red,
tension: 0,
fill: false
}, {
yAxisID: 'precipitation',
backgroundColor: color(chartColors.blue).alpha(0.5).rgbString(),
borderColor: 'transparent'
}]
},
plugins: [ChartDataSource],
options: {
title: {
display: true,
text: 'JSON Lines data source (index) sample'
},
scales: {
xAxes: [{
scaleLabel: {
display: true,
labelString: 'Month'
}
}],
yAxes: [{
id: 'temperature',
gridLines: {
drawOnChartArea: false
},
scaleLabel: {
display: true,
labelString: 'Temperature (°C)'
}
}, {
id: 'precipitation',
position: 'right',
gridLines: {
drawOnChartArea: false
},
scaleLabel: {
display: true,
labelString: 'Precipitation (mm)'
}
}]
},
plugins: {
datasource: {
type: 'jsonl',
url: 'sample-index.jsonl',
rowMapping: 'index',
indexLabels: '*.label',
data: '*.data.*'
}
}
}
};
window.onload = function() {
var ctx = document.getElementById('myChart').getContext('2d');
window.myChart = new Chart(ctx, config);
};
{"label": "January", "data": {"Temperature": 7, "Precipitation": 8.1}}
{"label": "February", "data": {"Temperature": 7, "Precipitation": 14.9}}
{"label": "March", "data": {"Temperature": 10, "Precipitation": 41.0}}
{"label": "April", "data": {"Temperature": 15, "Precipitation": 31.4}}
{"label": "May", "data": {"Temperature": 20, "Precipitation": 42.6}}
{"label": "June", "data": {"Temperature": 23, "Precipitation": 57.5}}
{"label": "July", "data": {"Temperature": 26, "Precipitation": 36.0}}
<head>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datasource@0.1.0"></script>
</head>
<body>
<div>
<canvas id="myChart"></canvas>
</div>
</body>