Populating Google combo chart with multidimensional PHP array -
i have php array info on students. looks this:
array(5) { ["question1"]=> array(30) { ["2014, 03, 02"]=> array(10) { ["student1"]=> int(54) ["student2"]=> int(43) ... etc. ... ["median"]=> string(2) "49" } each day students answers 5 questions value 1 100. each day median value answers single question calculated. answers , median value stored above.
now want populate google charts combo chart info can't work.
i visualise info date on x-axis, 1-100 value on y-axis , each reply point. info median value should displayed curve on points. points , curves each question should have own colour.
but i'm pretty much stuck. can't figure out how insert data. have tried approach:
var jsondata = (<?= json_encode($data)?>); var info = new google.visualization.arraytodatatable(jsondata); but next error message:
uncaught error: not array format+da,default+da,ui+da,corechart+da.i.js:181 lda format+da,default+da,ui+da,corechart+da.i.js:181 gp format+da,default+da,ui+da,corechart+da.i.js:183 drawchart ?side=graf:4888
you need alter format of data. visualization api expects info in tabular format, x-axis info in first column , each info series (a set of colored points) own column of data. can either build json representation of datatable (for utilize datatable constructor) or array of arrays of info (for utilize arraytodatatable function).
since using arraytodatatable function, construction need have:
$data = array( array('date', 'question 1', array('type' => 'number', 'role' => 'interval', 'id' => 'q1median'), 'question 2', array('type' => 'number', 'role' => 'interval', 'id' => 'q2median') /* repeat other questions */), // format array(date, q1 score, q1 median, q2 score, q2 median...) // set median in first row day, leave null other rows array('2014, 03, 02', 54, 49, /* repeat other questions */), array('2014, 03, 02', 43, null, /* repeat other questions */), // repeat 1 row each pupil each day ); the median values set in "interval" role column, can style display curved line in chart options:
interval: { // utilize column id of interval set options interval q1median: { style: 'line' }, q2median: { style: 'line' } // etc... } options styling intervals documented here.
php arrays multidimensional-array google-visualization json
No comments:
Post a Comment