作者:hyc_erasme | 来源:互联网 | 2022-11-21 15:22
我正在尝试使用ember-chart设置简单的Ember应用程序:https:
//www.npmjs.com/package/ember-cli-chart
我有我的charts.hbs文件:
{{#toggle-section}}
{{ember-chart type=CHARTTYPE data=CHARTDATA optiOns=CHARTOPTIONS width=CHARTWIDTH height=CHARTHEIGHT}}
{{/toggle-section}}
和我的chart.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
我试图寻找答案,但似乎没有任何效果.
1> mistahenry..:
该函数是小写的: Ember.computed
使用此导入也会更好:
import { computed } from '@ember/object';
避免必须引入所有Ember框架只是为了访问计算函数.