highchart图表drilldown钻取功能及event点击事件添加--补充钻取多图显示(2)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<!-- <script src="js/jquery-3.1.1.min.js"></script> -->
<script src="js/highcharts.js"></script>
<script src="js/drilldown.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<script>

	var result;

// Create the chart
Highcharts.chart('container', {
    chart: {
        type: 'bar',   
        events: {
            drilldown: function (e) {

                if (!e.seriesOptions) {
                    var chart = this,
                        drilldowns = result,
                        series = drilldowns[e.point.id];
                        console.info(drilldowns[e.point.id]);
                        console.info(drilldowns[2]);

                    // Show the loading label
                    chart.showLoading('Simulating Ajax ...');
                    setTimeout(function () {
                        chart.hideLoading();
                        if(series.length>1){//多图显示                      	
                        	chart.addSingleSeriesAsDrilldown(e.point, series[0]);
                        	chart.addSingleSeriesAsDrilldown(e.point, series[1]);
                        	chart.applyDrilldown();
                    	}else{
                    		chart.addSeriesAsDrilldown(e.point, series[0]);
                    	}
                    }, 1000);
                }
            }
        }
    },
    title: {
        text: 'Async drilldown'
    },
    xAxis: {
        type: 'category'
    },

    legend: {
        enabled: true
    },

    plotOptions: {
    	pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                enabled: true,
                format: '{point.name}: {point.percentage:.1f}%'
                },
                showInLegend: true
            },
        series: {
            borderWidth: 0,
            dataLabels: {
                enabled: true
            },
            events:{
        	click:function(e){
        		if(e.point.toDetail){
        			result={
        				'22': [{
                            	"center": ["200", null],
                            	"id":'Fruitsid',
                                "name": 'Fruits',
                                "data": [
                                    ['Apples', 5],
                                    ['Oranges', 7],
                                    ['Bananas', 2]
                                ],
                                "type": 'pie',
        						"size":300,       										                
                            },
                            {
                            	"id":'Carsid',
                                "name": 'Cars',
                                "type": 'pie',
                                "center": ["900", null],
        						"size":300,
                                "data": [
                                    ['Toyota', 1],
                                    ['Volkswagen', 2],
                                    ['Opel', 5]
                                ]
                            }]
                        }
        		}else{
        			result={
                            '1': [{
                            	id:'Animalsid',
                                name: 'Animalsn',
                                data:[{
                                	id:'22',
                                	name:'Cows',
                                	toDetail:true,
                                	y:2,
                                	drilldown: true
                                },{
                                	id:'2',
                                	name:'Sheep',
                                	y:3,
                                	drilldown: true
                                }
                                ]
                                
                            }]
                        }
        		}        		
        		}
       		 }	
        }
        
    },

    series: [{
        name: 'Things1',
        colorByPoint: true,
        center: [200, null],
        size:300,
        data: [{
        	id:'1',
            name: 'Animals',
            y: 5,
            drilldown: true
        }, {
        	id:'2',
            name: 'Fruits',
            y: 2,
            drilldown: true
        }, {
        	id:'3',
            name: 'Cars',
            y: 4,
            drilldown: true
        }]
    }
    ],

    drilldown: {
        series: [2]
    }
});


	
</script>

结果图:





  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值