【发布时间】:2017-04-06 01:55:39
【问题描述】:
我在我的流星应用程序中使用官方chart.js atmosphere package。我尝试运行示例图表以查看是否可以将其拉起,但是我遇到了一个问题,提示“ReferenceError: Chart is not defined”
这是我安装大气包和运行代码以生成图表的步骤。
- 使用meteor add chart:chart安装包
- 在我的 HTML 中,我添加了 canvas 标记,以调用图表及其信息
- 在 JS 中,我添加了创建图表及其相关信息的函数
但是,当我转到该页面时,我只得到一个空的 400x400 图像,它是画布,但图表应该在的地方没有内容。有人可以帮我弄清楚我缺少哪一步才能让图表出现吗?
HTML
<template name="Home_page">
<canvas id="myChart" width="400" height="400"></canvas>
</template>
JS
import './home-page.html';
Template.Home_page.onRendered(function homePageOnRendered() {
var ctx = document.getElementById("myChart").getContext("2d");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
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
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
});
【问题讨论】:
标签: javascript jquery html charts meteor-blaze