I need to display 4 arrays into my barchart:
this my file php result:
$.ajax({
url : "http://localhost/amira/php/gettrafic.php",
type : "GET",
success : function(data){
console.log(data);
var session = [];
var pagesvues = [];
for(var i in data) {
session.push(data[i].session);
pagesvues.push(data[i].pagesvues);
}
var multiLineData = {
labels: [ "Direct", "Social","Organic Search", "Referral"],
datasets: [{
label: 'Sessions',
data:session,
backgroundColor:[ 'rgba(68, 122, 116,1)',
'rgba(68, 122, 116,1)',
'rgba(68, 122, 116,1)',
'rgba(68, 122, 116,1)'],
borderColor: ['#569B93','#569B93' ,'#569B93' ,'#569B93'],
borderWidth: 1.5,
fill: false
},
{
label: 'PagesViews',
data: [5,2],
backgroundColor:['#B6E334','#B6E334','#B6E334','#B6E334'],
borderWidth: 1.5,
fill: true
}
]
};
var options = {
scales: {
yAxes: [{
ticks: {
beginAtZero: true strong text } }] },
legend: {
strong text display: true
},
elements: {
point: {
radius: 0
}
}
};
if ($("#barChart").length) {
var barChartCanvas = $("#barChart").get(0).getContext("2d");
// This will get the first returned node in the jQuery collection.
var barChart = new Chart(barChartCanvas, {
type: 'horizontalBar',
data: multiLineData,
options: options
});
}
},
error : function(data) {
}
});