Struggling to create a graph using a JSON object generated in PHP. Despite following the documentation example, I keep encountering a TypeError: b.value is undefined in the JS log. The data seems to be structured correctly.
for($i = 0; $i < 10; $i++){
$da=date("Y-m-d", strtotime('-'. $i .' days'));
$a=mt_rand(150,200);
$b=mt_rand(100,150);
$ar["date"][]=$da;
$ar["Score"][]=$a;
$ar["ScoreB"][]=$b;
}
$all=json_encode($ar);
<script>
var arr=<?php echo $all; ?>;
var chart = c3.generate({
bindto: '#scoring',
data: {
json: arr,
type: 'spline',
keys:{
x:'date'
}
},
color: {
pattern: ['red', 'orange']
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d'
}
}
}
});
The Object:
{"date":"2016-05-09","2016-05-08","2016-05-07","2016-05-06","2016-05-05","2016-05-04","2016-05-03","2016-05-02","2016-05-01","2016-04-30"],"Score":[182,163,196,153,180,154,170,177,191,173],"ScoreB":[121,149,138,113,104,107,111,109,119,132]}
Tried reformatting the object as follows:
[{"date":"2016-05-09","Score":191,"ScoreB":119},{"date":"2016-05-08","Score":166,"ScoreB":140},{"date":"2016-05-07","Score":172,"ScoreB":103},{"date":"2016-05-06","Score":187,"ScoreB":139},{"date":"2016-05-05","Score":162,"ScoreB":100},{"date":"2016-05-04","Score":197,"ScoreB":121},{"date":"2016-05-03","Score":167,"ScoreB":145},{"date":"2016-05-02","Score":160,"ScoreB":137},{"date":"2016-05-01","Score":175,"ScoreB":100},{"date":"2016-04-30","Score":156,"ScoreB":127}]
However, the same error persists.
Spent a whole day trying to solve this seemingly simple issue but no luck so far. When inputting the same data in "columns" format, it works fine. Need to get this JSON structure working for future use.