示例代码
<script src="https://cdn.bootcss.com/echarts/4.0.4/echarts.js"></script>
<div id="main" style="width: 600px;height:400px;"></div>
<script>
$(function () {
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '某站点用户访问来源',
subtext: '纯属虚构',
x: 'center'
},
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
legend: {
orient: 'vertical',
left: 'left',
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: 500,
name: '蓝色',
itemStyle: {
color: '#2756c2' //这里可以设置颜色
}
},
{
value: 800,
name: '绿色',
itemStyle: {
color: '#2ec23a'
}
},
{
value: 200,
name: '红色',
itemStyle: {
color: '#c2220a'
}
},
],
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
});
</script>