I used highcharts since a long time to do the line charts, but I would like to make a simple pie charts. I'm looking for a long time on this forum, but I didn't find the solution.
This is my data.php :
Code: Select all
<?php
try {
$db = new SQLite3('../../cost.db');
$reponse = $db->query("SELECT name, sum(total) FROM cost");
$rows = array();
$rows['name'] = 'name';
$rows1 = array();
$rows1['name'] = 'total';
while ($valeur = $reponse->fetchArray())
{
$rows['data'][] = $valeur['name'];
$rows1['data'][] = $valeur['sum(total)'];
}
} catch(Exception $e) {
echo "ERROR DATABASE";
die();
}
$result = array();
array_push($result,$rows);
array_push($result,$rows1);
print json_encode($result, JSON_NUMERIC_CHECK);
?>
This file work well. And this is my JS file (graphe.js)
Code: Select all
$(function () {
$.getJSON('data.php', function (data) {
$('#graphe').highcharts({
chart: {
type: 'pie'
},
title: {
text: 'Cost'
},
credits: {
enabled: false
},
legend: {
enabled: false
},
yAxis: [{
title: {
enabled: false
},
tickAmount: 11,
labels: {
format: '{value}€',
}
}],
plotOptions: {
series: {
borderRadius: 8,
dataLabels: {
enabled: true,
format: '{point.y:,.2f} €',
}
}
},
series: [{
name: 'Cost',
data: [{name: data[0].data, y: data[1].data}]
}]
});
});
});