json - Passing data to rickshaw with php -
i'm having trouble integrating data rickshaw graph.
i'm getting values database via php, converting output json array.
json string:
[{"x":"1431002979","y":"1079.547"},{"x":"1431007200","y":"1079.5468"},{"x":"1431010800","y":"1079.5469"},{"x":"1431014400","y":"1079.5469"},{"x":"1431018000","y":"1079.5472"},{"x":"1431021600","y":"1079.5473"},{"x":"1431025200","y":"1079.5475"},{"x":"1431028800","y":"1079.5478"},{"x":"1431032400","y":"1079.5479"}] i parse json this:
var data=json.parse('<?php echo json_encode($data); ?>'); if try load data folling error
uncaught exception: x , y properties of points should numbers instead of undefined , undefined so figured there s.th wrong data type , did this
for(var i=0;i<data.length;i++) { data[i]=[parseint(data[i]['x']),parsefloat(data[i]['y'])]; } i still same error though.
this code graph:
var graph = new rickshaw.graph( { element: document.queryselector("#chart"), width: 580, height: 250, series: [ { data: data, color: 'rgba(255, 0, 0, 0.4)' } ] } ); graph.render(); greetings david
try only
<?php echo json_encode($data,json_numeric_check)); ?> var graph = new rickshaw.graph( { element: document.queryselector("#chart"), width: 580, height: 250, series: [ { color: 'rgba(255, 0, 0, 0.4)', data: <?php echo json_encode($data,json_numeric_check)); ?> } ] } ); graph.render();
Comments
Post a Comment