我正在尝试使用ember-chart用Ember设置简单的应用程序: https://www.npmjs.com/package/ember-cli-chart
我有我的chart.hbs文件:
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
{{#toggle-section}}
<div class="chart-container">
{{ember-chart type=CHARTTYPE data=CHARTDATA options=CHARTOPTIONS width=CHARTWIDTH height=CHARTHEIGHT}}
</div>
{{/toggle-section}}
</div>
</div>
</div>
和我的Charts.js控制器,以及Chart.js文档中的示例:
import Controller from '@ember/controller';
import Ember from "ember";
export default Controller.extend({
CHARTTYPE: 'bar',
CHARTDATA: Ember.Computed('', function () {
return {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
}
}),
CHARTOPTIONS: Ember.Computed('', function () {
return {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
}),
CHARTWIDTH: 500,
CHARTHEIGHT: 500,
});
在index.js路由中,我已重定向到图表路由:
beforeModel() {
this.replaceWith('charts');
}
当我尝试在localhost:4200
之后打开ember s
时,控制台出现错误:
router.js:927 Error while processing route: index Ember.Computed is not a function TypeError: Ember.Computed is not a function
我试图寻找答案,但似乎无济于事。
答案 0 :(得分:5)
该函数为小写字母:Ember.computed
最好使用此导入:
import { computed } from '@ember/object';
避免仅为了访问计算函数而引入所有Ember框架。