admin管理员组文章数量:1325510
I am trying to use charts from chartist.js link: .html#simple-line-chart
When I try to use them in my code I am getting Chartist to defined how can I import it in my ponent ?
Code:
import React, { Component } from 'react';
import chartistGraph from "react-chartist";
const simpleLineChartData = {
labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
series: [
[12, 9, 7, 8, 5],
[2, 1, 3.5, 7, 3],
[1, 3, 4, 5, 6]
]
}
class Chart extends Component {
render(){
return(
<div>
<chartistGraph data={simpleLineChartData} type={'Line'} />
</div>
)}
}
export default Chart;
Above code gives error saying Chartist not define. How to import some library and use it in reactjs.
I am trying to use charts from chartist.js link: https://gionkunz.github.io/chartist-js/examples.html#simple-line-chart
When I try to use them in my code I am getting Chartist to defined how can I import it in my ponent ?
Code:
import React, { Component } from 'react';
import chartistGraph from "react-chartist";
const simpleLineChartData = {
labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
series: [
[12, 9, 7, 8, 5],
[2, 1, 3.5, 7, 3],
[1, 3, 4, 5, 6]
]
}
class Chart extends Component {
render(){
return(
<div>
<chartistGraph data={simpleLineChartData} type={'Line'} />
</div>
)}
}
export default Chart;
Above code gives error saying Chartist not define. How to import some library and use it in reactjs.
Share Improve this question edited Jun 5, 2018 at 5:28 stone rock asked Jun 5, 2018 at 5:05 stone rockstone rock 1,95310 gold badges45 silver badges76 bronze badges 1- Did you try importing the library? var ChartistGraph = require('react-chartist') try this. It will include chartist library. – AsthaUndefined Commented Jun 5, 2018 at 5:12
2 Answers
Reset to default 6Run
npm install react-chartist --save
One more thing, you need to install chartist also as it is the dependency
npm install chartist --save.
Then you will be able to import Chartist into your application.
import chartistGraph from "react-chartist";
Here is the link how it can be implemented in codesandbox. codesandbox Link
Follow this link for the implementation Link
You can import ChartistGraph from 'react-chartist' as:
import ChartistGraph from 'react-chartist';
or
var ChartistGraph = require('react-chartist')
Also, 'react-chartist' doesn't include the css files for Chartist, so if you want to add the styles then add this in your index.html file:
<link rel="stylesheet" href="//cdn.jsdelivr/chartist.js/latest/chartist.min.css">
<script src="//cdn.jsdelivr/chartist.js/latest/chartist.min.js</script>
Or you can install 'chartist' package
npm install chartist
See this link for decription
本文标签: javascriptHow to import chartist in react componentStack Overflow
版权声明:本文标题:javascript - How to import chartist in react component? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742196517a2431178.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论