React中使用ECharts

若如初见. 提交于 2020-03-01 21:24:17

下载依赖

cnpm i echarts
cnpm i echarts-for-react

React特殊写法

import React,{Component} from 'react';
import ReactEcharts from 'echarts-for-react';

class ECharts extends Component {
    constructor() {
        super()
        this.state = {
            option: {
	            tooltip: {
	                trigger: 'item',
	                formatter: "{a} <br/>{b} : {c} ({d}%)"
	            },
	            series: [{
	                name: '库存情况',
	                type: 'pie',
	                radius: '68%',
	                center: ['50%', '50%'],
	                clockwise: false,
	                data: [{
	                    value: 45,
	                    name: 'CARD'
	                }, {
	                    value: 25,
	                    name: 'SSD'
	                }, {
	                    value: 15,
	                    name: 'U盘'
	                }, {
	                    value: 8,
	                    name: '嵌入式'
	                }, {
	                    value: 7,
	                    name: 'FLASH'
	                }],
	                label: {
	                    normal: {
	                        textStyle: {
	                            color: '#999',
	                            fontSize: 14,
	                        }
	                    }
	                },
	                labelLine: {
	                    normal: {
	                        show: false
	                    }
	                },
	                itemStyle: {
	                    normal: {
	                        borderWidth: 4,
	                        borderColor: '#ffffff',
	                    },
	                    emphasis: {
	                        borderWidth: 0,
	                        shadowBlur: 10,
	                        shadowOffsetX: 0,
	                        shadowColor: 'rgba(0, 0, 0, 0.5)'
	                    }
	                }
	            }],
	            color: [
	                '#00acee',
	                '#52cdd5',
	                '#79d9f1',
	                '#a7e7ff',
	                '#c8efff'
	            ],
	            backgroundColor: '#fff'
	        }
        }
    }
    render() {
        return (
            <div>
                <ReactEcharts option={this.state.option} style={{ height: '400px', width: '400px' }} />
            </div>
        )
    }
}

export default ECharts;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!