下面以一个环形图为例,现在想做的效果是图例初始化时默认显示第一个图的文字,上代码

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/echarts.js" ></script>
</head>
<body>
<div id="main" style="width: 800px;height: 500px;"></div>
<script type="text/javascript">
var myChart = echarts.init(document.getElementById(\'main\'));
var ass = {
                normal: {
                    show: false,
                    position: \'center\',
                    textStyle: {
                    fontSize : \'30\',
                    fontWeight: \'bold\'
                    }
                },
                emphasis: {
                    show: true,
                    textStyle: {
                        fontSize: \'30\',
                        fontWeight: \'bold\'
                    }
                }
          };          
var resultData =  [
                {value:335, name:\'直接访问\'},
                {value:310, name:\'邮件营销\'},
                {value:234, name:\'联盟广告\'},
                {value:135, name:\'视频广告\'},
                {value:1548, name:\'搜索引擎\'}
            ];       
var option = {
    legend: {
        orient: \'vertical\',
        x: \'left\',
        data:[\'直接访问\',\'邮件营销\',\'联盟广告\',\'视频广告\',\'搜索引擎\']
    },
    series: [
        {
            name:\'访问来源\',
            type:\'pie\',
            radius: [\'50%\', \'70%\'],
            avoidLabelOverlap: false,
            label: {
                normal: {
                    show: false,
                    position: \'center\',
                    textStyle: {
                    fontSize : \'30\',
                    fontWeight: \'bold\'
                    }
                },
                emphasis: {
                    show: true,
                    textStyle: {
                        fontSize: \'30\',
                        fontWeight: \'bold\'
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false
                }
            },
            data:resultData
        }
    ]
};
function emphasis(){
    var dataLen = option.series[0].data.length; 
    // 高亮当前图形
    myChart.dispatchAction({
        type: \'highlight\',
        seriesIndex: 0,
        dataIndex: 0
    });
}
function unemphasis(){
var dataLen = option.series[0].data.length;
// 取消之前高亮的图形
    myChart.dispatchAction({
        type: \'downplay\',
        seriesIndex: 0,
        dataIndex: 0
    });
}

myChart.setOption(option);
emphasis();
    myChart.on(\'mouseover\', function(a){
    if(a.dataIndex!=0){
    unemphasis();
    }    
    })
    myChart.on(\'mouseout\', function(){
    emphasis();
    })
</script>
</body>

</html>

效果


相关文章: