【发布时间】:2017-01-03 16:47:34
【问题描述】:
我目前正在尝试使用 Chart.js 在 ReactJS 中呈现条形图
信息:
官方页面-http://www.chartjs.org/docs/
gitHub - https://github.com/reactjs/react-chartjs
我遇到的问题是,即使我的终端没有给我任何错误,我的本地服务器也没有呈现任何东西。
这是我的代码:
var React = require('react');
var BarChart = require('../../node_modules/chart.js/Chart.js');
var styles = require('./Styles.js');
var 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
}]
};
var options={
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
};
var Graphs = React.createClass({
render: function() {
return (
<div id='graphDiv'>
<BarChart type='bar' data={data} options={options} />
</div>
);
}
});
module.exports = Graphs;
如果我犯了一些愚蠢的错误,请多多包涵,这是我编写的第一个 React 应用程序,所以我还有很多东西要学。
不过,我有多个问题:
我是否将库安装在正确的位置? - 我使用了 npm,它现在位于 node_modules 文件夹中
-
文件的路径是否正确写入?正如 gitHub 所说,它应该是这样的:
var LineChart = require("react-chartjs").Line;
可以将数据和选项作为全局变量吗?
如果我没有从终端收到任何错误消息,我的代码有什么问题?
祝你有美好的一天
【问题讨论】:
标签: javascript node.js reactjs chart.js