0๐
function getData() {
return {
a: [{ x: 118, y: 92.82 }, {x: 115.8, y: 92.88 }, {x: 113.03, y: 93.62 } ],
b: [{ x: 218, y: 92.82 }, {x: 215.8, y: 92.88 }, {x: 213.03, y: 93.62 } ]
};
}
var data = getData();
class BuildChart {
constructor() {
var ctx = document.getElementById('myChart');
var myChart = new Chart(ctx, {
type: 'scatter',
data: {
datasets: [
{
label: 'Example',
showLine: true,
backgroundColor: 'red',
data: data.a
},
{
label: 'Example 2',
showLine: true,
backgroundColor: 'green',
data: data.b
}
]
}
});
}
}
new BuildChart();
canvas { max-width: 400px; }
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
<canvas id="myChart"></canvas>
- Chartjs-How to address type errors when removing data with chart.js?
- Chartjs-Chart.js: Updating chart shows wrong time format for a while
Source:stackexchange.com