c3js:未捕获的TypeError:c.forEach不是函数

时间:2016-09-24 14:32:57

标签: c3.js

我尝试使用时间序列轴创建一个简单的点线图,但图表没有渲染,我的浏览器控制台显示错误:

var chart = c3.generate({ bindto: '#chart', data: { json: [ {date: "2016-01-01", pageviews: 1}, {date: "2016-01-02", pageviews: 2}, {date: "2016-01-03", pageviews: 3}, {date: "2016-01-04", pageviews: 4}, {date: "2016-01-05", pageviews: 5}], keys: { x: 'date', value: 'pageviews' } }, axis: { x: { type: 'timeseries', tick: { format: '%Y-%m-%d' } } } });

这是我的javascript:

Uncaught TypeError: targetKeys.forEach is not a function

here's a jsfiddle使用D3和C3的未缩小来源并提供以下浏览器控制台错误: data.keys.value

1 个答案:

答案 0 :(得分:2)

'pageviews'期待一个数组,所以只需将var chart = c3.generate({ bindto: '#chart', data: { json: [ {date: "2016-01-01", pageviews: 1}, {date: "2016-01-02", pageviews: 2}, {date: "2016-01-03", pageviews: 3}, {date: "2016-01-04", pageviews: 4}, {date: "2016-01-05", pageviews: 5}], keys: { x: 'date', value: ['pageviews'] // needs to be an array } }, axis: { x: { type: 'timeseries', tick: { format: '%Y-%m-%d' } } } }); 包装在方括号中,如下所示:

 $now = Carbon::now();
 $week = Carbon::now()->addWeek();
 $month=Carbon::now()->addMonth();

Working jsfiddle for completeness