我的骨干视图中的实现c3.js图表存在问题。
我在main.js中的代码:
require.config({
paths: {
'jquery': 'libs/jquery/jquery.min',
'underscore': 'libs/lodash/lodash.min',
'backbone': 'libs/backbone/backbone-min',
'd3': 'libs/d3',
'c3': 'libs/c3',
'templates': '../templates',
},
shim: {c3: { deps: ['d3'], exports: 'c3' }}
});
然后在视图中
define([
'underscore',
'backbone',
'collections/reports/ReportsCollection',
'text!templates/reports/reportsTemplate.html',
'd3',
'c3',
], function(_, Backbone, ReportsCollection, reportsTemplate, d3, c3){
console.log(c3); // OUTPUT IS UNDEFINED
var ReportsView = Backbone.View.extend({
el: document.getElementById("content"),
render: function(){
var reports = JSON.parse(localStorage.getItem('reports'));
var reportsCollection = new ReportsCollection(reports);
this.el.innerHTML = _.template( reportsTemplate,{data : productsCollection.toJSON()} );
c3.generate({
bindto: '#chart',
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25]
]
}
});
},
});
return ReportsView;
});
我看到d3js和c3js已正确加载,但在控制台中出现错误Cannot read property 'generate' of undefined
我将非常感谢任何帮助或意见!