React 项目中使用Echarts

直接上代码吧:

react 项目中添加Echarts 相关模块

npm install echarts --save

 代码:

import React from 'react'
import * as echarts from 'echarts';
import '../css/EchartsTest.css'

export default class EchartsTest extends React.Component {
	
	constructor() {
	    super()
		this.state={
			myChart:""
		}
	}
	componentDidMount() {
		this.myChart=echarts.init(document.getElementById('main'));
		this.myChart.setOption({
			title: {
				text: '三月份销量统计',
				x:'center',
				y:'top'
			},
			tooltip: {},
			xAxis: {
				data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
			},
			yAxis: {},
			series: [{
				name: '销量',
				type: 'bar',
				data: [5, 20, 36, 10, 10, 20]
			}]
		});
	}
	render() {
		return (
		 
); } }

查看页面效果:

React 项目中使用Echarts_第1张图片

 希望对你有所帮助

你可能感兴趣的:(react,echarts,react.js)