饼图tooltip

时间:2024-10-25 16:04:20
@{
ViewBag.Title = "pie";
} <h2>pie</h2> <div id="main" style="width: 1000px;height:800px;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'), 'shine', { width: }); option = {
tooltip: {
trigger: 'item',
//formatter: "{a} <br/>{b}: {c} ({d}%)"
formatter: function (params) {
var s = params.name + '<br />';
for (var i = ; i < option.series.length; i++) {
s += option.series[i].name + ': ' + option.series[i].data[params.dataIndex].value + '(' + (option.series[i].data[params.dataIndex].value / jehj[i] * ).toFixed() + '%)<br />';
}
return s;
}
},
legend: {
orient: 'vertical',
x: 'left',
data: ['直达', '营销广告', '搜索引擎', '邮件营销', '联盟广告', '视频广告', '百度', '谷歌', '必应', '其他']
},
series: [
{
name: '2016年',
type: 'pie',
selectedMode: 'single',
radius: [, '30%'], label: {
normal: {
position: 'inner',
formatter: "{b}({d}%)"
}
},
labelLine: {
normal: {
show: false
}
},
data: [
{ value: , name: '直达' },
{ value: , name: '邮件营销' },
{ value: , name: '联盟广告' },
{ value: , name: '视频广告' },
{ value: , name: '百度' },
{ value: , name: '谷歌' },
{ value: , name: '必应' },
{ value: , name: '其他' }
]
},
{
name: '2017年',
type: 'pie',
radius: ['40%', '55%'], data: [
{ value: , name: '直达' },
{ value: , name: '邮件营销' },
{ value: , name: '联盟广告' },
{ value: , name: '视频广告' },
{ value: , name: '百度' },
{ value: , name: '谷歌' },
{ value: , name: '必应' },
{ value: , name: '其他' }
],
label: {
normal: {
//position: 'inner',
formatter: "{b}: {c} ({d}%)"
}
}
}
]
};
var jehj = new Array();
for (var i = ; i < option.series.length; i++) {
var hj = ;
for (var j = ; j < option.series[i].data.length; j++) {
hj += option.series[i].data[j].value;
}
jehj[i] = hj;
}
myChart.setOption(option); </script>

饼图tooltip