admin管理员组文章数量:1326304
I want to implement charts in my project, and I decided to use react-chart.js
I'm at the very beginning trying to add an example in my ponents, so I added this code :
var MyChart = React.createClass({
render: function() {
console.log(chartData)
return <LineChart data={chartData} options={null} width="600" height="250"/>
}
});
module.exports = MyChart;
chartData is an object
I have an err:
core.js:64 Uncaught TypeError: (intermediate value)[chartType] is not a function
I also tried other charts, but none of them did work, so I probably do something wrong, but I can't find what
I want to implement charts in my project, and I decided to use react-chart.js
I'm at the very beginning trying to add an example in my ponents, so I added this code :
var MyChart = React.createClass({
render: function() {
console.log(chartData)
return <LineChart data={chartData} options={null} width="600" height="250"/>
}
});
module.exports = MyChart;
chartData is an object
I have an err:
core.js:64 Uncaught TypeError: (intermediate value)[chartType] is not a function
I also tried other charts, but none of them did work, so I probably do something wrong, but I can't find what
Share Improve this question edited Nov 21, 2017 at 6:46 Shubham Khatri 282k58 gold badges431 silver badges411 bronze badges asked Apr 6, 2017 at 4:42 ElenaElena 6493 gold badges9 silver badges19 bronze badges 2- r u using ReCharts ?? from where u r importing LineChart ? – Mayank Shukla Commented Apr 6, 2017 at 4:48
- Refer to this. It may help. github./reactjs/react-chartjs/issues/112 – AryanJ-NYC Commented Apr 6, 2017 at 4:58
1 Answer
Reset to default 6React Chartjs
has a dependency on Chart.js
too.
Install it like
npm install --save chart.js@^1.1.1 react react-dom
Also since Line
is a named export
you need to import it as
import {Line as LineChart} from 'react-chartjs';
Also make sure your chartData is an object like
{
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "My First dataset",
fill: false,
pointHoverRadius: 5,
pointRadius: 1,
pointHitRadius: 10,
data: [65, 59, 80, 81, 56, 55, 40],
spanGaps: false,
}
]
};
本文标签: javascriptChartjs with ReactStack Overflow
版权声明:本文标题:javascript - Chart.js with React - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742208202a2433212.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论