0👍
Here’s the fiddle which loads data from ajax and creates a line chart -> http://jsfiddle.net/oxgm493z/9/
Hope it helps!
$(document).ready(function() {
var labels = [];
var dataXXX = [];
var dataYYY = [];
$.ajax({
type: 'GET',
url: 'https://api.myjson.com/bins/1igag',
dataType: 'json',
success: function(field) {
for (var i = 0; i < field.length; i++) {
labels.push(field[i].time);
dataXXX.push(field[i].xxx);
dataYYY.push(field[i].yyy);
}
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'xxx',
data: dataXXX,
fill: false,
backgroundColor: 'red',
borderColor: 'red',
},
{
label: 'yyy',
data: dataYYY,
fill: false,
backgroundColor: 'green',
borderColor: 'green',
},
]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
}
});
})
- Chartjs-How I create a dropdown for radar chartjs from mysql database?
- Chartjs-How to filter Chart JavaScript Dashboard by Year through dropdown after the MySQL count query?
Source:stackexchange.com