c3.js TypeError: b.value is undefined

c3.js TypeError: b.value is undefined

我正在尝试使用在 PHP 中创建的 JSON 对象制作图表。我在 JS 日志中不断收到 TypeError: b.value is undefined 但我的数据似乎与他们文档中的示例格式相同。

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'
                }
            }
        }
    });

对象是

{"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]} 

我也运行它与

格式的对象
[{"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}] 

我仍然有同样的错误。

我卡了一天了,看起来应该很容易,但我想不通。如果我以 "columns" 的格式放置相同的数据,它可以工作,但今后我需要这个 JSON 才能工作。

当剪切'n'粘贴到 http://c3js.org/samples/timeseries.html , see the change in the keys section with the added value field - http://c3js.org/reference.html#data-keys

时,这对我有用

唯一的区别是我更改了绑定 ID 以在 c3 示例页面中工作,并且我直接使用了 json,而不是 php 生成的。

var arr = [{"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}]; ;

var chart = c3.generate({
        bindto: '#chart',
        data: {
            json: arr,
            type: 'spline',
            keys:{
                x:'date',
                value: ['Score', 'ScoreB'], // IMPORTANT
            }
        },
        color: {
            pattern: ['red', 'orange']
        },
        axis: {
            x: {
                type: 'timeseries',
                tick: {
                    format: '%Y-%m-%d'
                }
            }
        }
    });