Edit in JSRUN

console 命令行工具 X clear

                    
>
console
var mychart=echarts.init(document.getElementById('chart'));


var data = [
    [[28604,77,17096869,'Australia',1990],[31163,77.4,27662440,'Canada',1990],[1516,68,1154605773,'China',1990],[13670,74.7,10582082,'Cuba',1990],[28599,75,4986705,'Finland',1990],[29476,77.1,56943299,'France',1990],[31476,75.4,78958237,'Germany',1990],[28666,78.1,254830,'Iceland',1990],[1777,57.7,870601776,'India',1990],[29550,79.1,122249285,'Japan',1990],[2076,67.9,20194354,'North Korea',1990],[12087,72,42972254,'South Korea',1990],[24021,75.4,3397534,'New Zealand',1990],[43296,76.8,4240375,'Norway',1990],[10088,70.8,38195258,'Poland',1990],[19349,69.6,147568552,'Russia',1990],[10670,67.3,53994605,'Turkey',1990],[26424,75.7,57110117,'United Kingdom',1990],[37062,75.4,252847810,'United States',1990]],
    [[44056,81.8,23968973,'Australia',2015],[43294,81.7,35939927,'Canada',2015],[13334,76.9,1376048943,'China',2015],[21291,78.5,11389562,'Cuba',2015],[38923,80.8,5503457,'Finland',2015],[37599,81.9,64395345,'France',2015],[44053,81.1,80688545,'Germany',2015],[42182,82.8,329425,'Iceland',2015],[5903,66.8,1311050527,'India',2015],[36162,83.5,126573481,'Japan',2015],[1390,71.4,25155317,'North Korea',2015],[34644,80.7,50293439,'South Korea',2015],[34186,80.6,4528526,'New Zealand',2015],[64304,81.6,5210967,'Norway',2015],[24787,77.3,38611794,'Poland',2015],[23038,73.13,143456918,'Russia',2015],[19360,76.5,78665830,'Turkey',2015],[38225,81.4,64715810,'United Kingdom',2015],[53354,79.1,321773631,'United States',2015]]
];

var dataA=[];

 var option = {
        title:{
            text:"各种浏览器的统计",
            subtext:"点击可看详细",
         //   textAlign:"center",
         //   right:"100",
            x:'center',
            y:'bottom'
        },
        tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient : 'vertical',
            x : 'left',
            data:['直达','营销广告','搜索引擎','邮件营销','联盟广告','视频广告','百度','谷歌','必应','其他']
        },
        toolbox: {
            show : true,
            feature : {
                mark : {show: true},
                dataView : {show: true, readOnly: false},
                magicType : {
                    show: true,
                    type: ['pie', 'funnel',"line"]
                },
                restore : {show: true},
                saveAsImage : {show: true}
            }
        },
        calculable : false,
        series : [
            {
                name:'访问来源',
                type:'pie',
                selectedMode: 'single',
                radius : [0, 70],

                // for funnel
                x: '20%',
                width: '40%',
                funnelAlign: 'right',
                max: 1548,

                itemStyle : {
                    normal : {
                        label : {
                            position : 'inner'
                        },
                        labelLine : {
                            show : false
                        }
                    }
                },
                data:[
                    {value:335, name:'直达'},
                    {value:679, name:'营销广告'},
                    {value:1548, name:'搜索引擎'}
                ]
            },
            {
                name:'访问来源',
                type:'pie',
                radius : [100, 140],

                // for funnel
                x: '60%',
                width: '35%',
                funnelAlign: 'left',
                max: 1048,

                data:dataA
                /*[
                   {value:335, name:'直达'},
                    {value:310, name:'邮件营销'},
                    {value:234, name:'联盟广告'},
                    {value:135, name:'视频广告'},
                    {value:1048, name:'百度'},
                    {value:251, name:'谷歌'},
                    {value:147, name:'必应'},
                    {value:102, name:'其他'}
                ]*/
            }
        ]
    };
 var data0=[
        {value:335, name:'直达'},
        {value:310, name:'邮件营销'}

    ];
    var data1=[

        {value:234, name:'联盟广告'},
        {value:135, name:'视频广告'}

    ];
    var data2=[
        {value:1048, name:'百度'},
        {value:251, name:'谷歌'},
        {value:147, name:'必应'},
        {value:102, name:'其他'}];
    var data=[];
    data[0]=data0;
    data[1]=data1;
    data[2]=data2;
mychart.setOption(option);
 mychart.on('click', function (params) {
            // window.open('https://www.baidu.com/s?wd=' + encodeURIComponent(params.name));
            console.log(params);

            if(params.seriesIndex==0){
                myChart.setOption( {
                    series: [{},{
                        data:[]
                    }]
                });
          //      $('#main').echarts().option.series[1].data=[];
            /*  switch (params.dataIndex){
                  case 0:dataA=data0;break;
                  case 1:dataA=data1;break;
                  case 2:dataA=data2;break;

              }*/

                for(var i=0;i<option.series[0].data.length;i++){
                    option.series[0].data[i].selected=false;
                }
                var selected=params.data;
             //   selected.push("selected");
                selected.selected=true;
                console.log(selected);
                console.log( option.series[0].data[params.dataIndex]);
                option.series[0].data[params.dataIndex]=selected;
               // option.series[1].data=dataA;
                option.series[1].data=data[params.dataIndex];
                console.log(option);
                myChart.clear();
                myChart.setOption(option);
            }


        });
<div id="chart" style="width:100%;height:500px;">

</div>

本项目引用的自定义外部资源