React学习系列七Echarts pie
先安装插件
npm install echarts --save
代码
import React, { Component } from 'react';// 引入 ECharts 主模块
import echarts from 'echarts/lib/echarts';
// 引入饼状图
import 'echarts/lib/chart/pie';
// 引入提示框和标题组件
import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/title';
// 引入图例组件
import 'echarts/lib/component/legend';
class Pie extends Component {
constructor(props){
super(props);
this.state = {
data1:8,
data2:12
}
}
componentDidMount(){
let myChart = echarts.init(document.getElementById('pie'));
// 绘制图表
myChart.setOption({
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b}: {c} ({d}%)"
},
legend: {
orient: 'vertical',
x: 'right',
top: 'middle',
data:['已签到','未签到']
},
series: [
{
name:'考勤统计',
type:'pie',
radius: ['50%', '70%'],
avoidLabelOverlap: false,
label: {
normal: {
show: false,
position: 'center'
},
emphasis: {
show: true,
textStyle: {
fontSize: '30',
fontWeight: 'bold'
}
}
},
labelLine: {
normal: {
show: false
}
},
data:[
{
value: this.state.data1,
name:'已签到',
itemStyle: {
normal: {
color: '#3AA0FF'
}
}},
{
value: this.state.data2,
name:'未签到',
itemStyle: {
normal: {
color: '#E56363'
}
}
}
]
}
]
});
};
render() {
return (
<div>
<div id="pie" style={{width: '450px', height:'400px'} }></div>
</div>
)
}
}
export default Pie;
截图
以上是 React学习系列七Echarts pie 的全部内容, 来源链接: utcz.com/z/384224.html