I have a graph which works fine manually (data I put by myself).
$(function () {
// Use Morris.Area instead of Morris.Line
Morris.Area({
element: 'graph-area',
padding: 10,
behaveLikeLine: true,
gridEnabled: false,
gridLineColor: '#dddddd',
axes: true,
fillOpacity:.7,
data: [
{period: '1', Visites: 10},
{period: '2', Visites: 78},
{period: '3', Visites: 97},
{period: '4', Visites: 45},
],
lineColors:['#E67A77'],
xkey: 'period',
ykeys: ['Visites'],
labels: ['Visites'],
pointSize: 0,
lineWidth: 0,
hideHover: 'auto'
});
});
But then I want to display the data dynamically with a foreach. I can't get this to work :
$(function () {
// Use Morris.Area instead of Morris.Line
Morris.Area({
element: 'graph-area',
padding: 10,
behaveLikeLine: true,
gridEnabled: false,
gridLineColor: '#dddddd',
axes: true,
fillOpacity:.7,
data: [<?php
foreach($ga->getResults() as $result)
{
echo "{period: '".$result."',";
echo " Visites: ".$result->getVisitors()."},</br>";
}
?>],
lineColors:['#E67A77','#79D1CF','#79D1CF'],
xkey: 'period',
ykeys: ['Visites'],
labels: ['Visites'],
pointSize: 0,
lineWidth: 0,
hideHover: 'auto'
});
});
I have this in console error : Uncaught SyntaxError: Unexpected token <
When I echo my foreach, I get the the following thing with the same symthax. It should work but it's not.
{period: '01', Visites: 1},
{period: '02', Visites: 1},
{period: '03', Visites: 3},
{period: '04', Visites: 4},
{period: '05', Visites: 1},
{period: '06', Visites: 5},
{period: '07', Visites: 4},
{period: '08', Visites: 2},
{period: '09', Visites: 6},