Drilldown multiple levels Highchart

前端 未结 6 2103
清歌不尽
清歌不尽 2020-12-05 05:19

We like to Drilldown on multiple levels in Highchart. Is there already an example in Highchart?

Currently used code:

$(div).highchar         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 05:44

    this.EixoX = ["Jun/2016","Jul/2016","Ago/2016","Set/2016","Out/2016","Nov/2016","Dez/2016"];
    	this.EixoY = "Reais";
    	this.Class = "DivGraficoLinhaDoTempo";
    	this.Titulo = "Média de Vendas por Equipe";
    	this.Subtitulo;
    	this.ValoresBarras =[{
    				name:"ECLEIA",
    				data: [30000, 32000, 54000, 50000, 54000, 50000], //JAN, FEV, MAR, ABR, MAY, JUN
    				vendedores: [{name:"ECLEIAv1",data:[32000,40005,40005,27002,20002,70001]},{name:"ECLEIAv2",data:[30000,55000,45000,22000,32000,33001]}]
    				},{
    				name:"JOANA",
    				data: [43000, 12000, 34000, 4000, 30004, 4000],
    				vendedores: [{name:"JOANAv1",data:[72000,55005,70005,90002,70002,50001]},{name:"JOANAv2",data:[22000,50005,40005,40002,30002,66001]}]
    				},{
    				name:"GABRIELE",
    				data: [22000, 22000, 34000, 20004, 30004, 4000],
    				vendedores: [{name:"GABRIELEv1",data:[11000,30005,60005,40002,30002,30001],vendedores: [{name:"GABRIELEv1SUB1",data:[11000,30005,60005,40002,30002,30001]},{name:"GABRIELEv1SUB2",data:[60000,50005,40005,24502,55502,70001]}]},{name:"GABRIELEv2",data:[60000,50005,40005,24502,55502,70001]}]
    				},{
    				name:"FRANCISCO",
    				data: [54000, 12000, 30004, 4000, 30004, 4000],
    				vendedores: [{name:"FRANCISCOv1",data:[52000,60005,20005,11002,66002,40001]},{name:"FRANCISCOv2",data:[50000,56005,40005,25002,30002,38001]}]
    				}];
            
    	this.ValoresLinha = [{
    				name:"MÉDIA",
    				data: [54000, 12000, 30004, 4000, 30004, 4000]
    			
    				}];
    	//ATRIBUTOS AUXILIARES
    
    	this.nivel;
    	this.indexmes;
    	this.indexvendedor;
    	this.drilldownniveis;
    	var drilldownTitle = "Equipe de ";
    
    
    	///UserCodeRegionStart:[User Functions] (do not remove this comment.)
    	var _this = this;
    	//var vetorNomesX	= [];
    
      var colors = Highcharts.getOptions().colors;
    
    		$(function () {
    			Highcharts.Tick.prototype.drillable = function () {}; //REMOVE LINKS DOS LABELS DO EIXO X(mes), pois cada mes possui "n" vendedores
    			var options = {
    				type:"column",
    				chart: {
    					renderTo: "container",
    					events: {
    							 drilldown: function(e) {
    								 //console.log(e.point);
    									 chart.setTitle({ text: drilldownTitle + e.point.name });
    							 },
    							 drillup: function(e) {
    									 chart.setTitle({ text: _this.Titulo });
    							 }
    					 }
    				},
    				title: {
    					text: _this.Titulo
    				},
    				subtitle: {
    					text: _this.Subtitulo
    				},
    				xAxis: {
    					categories: _this.EixoX
    				},
    				yAxis: {
    					labels: {
    						formatter: function () {
    							return Highcharts.numberFormat(this.value,0);
    						}
    					},
    					title: {
    						text: _this.EixoY
    					}
    				},
    				plotOptions: {
    
    					column: {
    											cursor: "pointer",
    											point: {
    													events: {
    															click: function (e) {
    
    																_this.indexmes = e.point.x;
    																_this.indexvendedor = e.point.series.columnIndex;
    																																//LÓGICA PARA AVANÇO DE NIVEIS
    																if(_this.drilldownniveis){
    																	chart.setTitle({ text: drilldownTitle + _this.drilldownniveis[_this.indexvendedor].name });
    																	_this.drilldownniveis = _this.drilldownniveis[_this.indexvendedor].drilldown;
    																	}else{
    																		chart.setTitle({ text: drilldownTitle + options.series[_this.indexvendedor].name });
    			 														_this.drilldownniveis = options.series[_this.indexvendedor].data[_this.indexmes].drilldown;
    
    																	if(options.series[_this.indexvendedor].data[_this.indexmes].drilldown.length<=0){ //SE drilldown = 0 mesma coisa que não ter (undefined), então seto null!
    																	_this.drilldownniveis = null;
    																	}
    															}
    																//setChart de acordo com novas variaveis
    																		if (_this.drilldownniveis) { // drill down
    																					if(_this.drilldownniveis.length<=0){
    																						_this.drilldownniveis = options.series;
    																					}
    
    																					var media = new Array(0,0,0,0,0,0,0); //ZERA ARRAY PARA PODER SOMAR VALORES
    
    																					for(var x=0;x<_this.EixoX.length;x++){
    																					$(_this.drilldownniveis).each(function(index, el) {
    																						media[x] += el.data[x];
    																						});
    																					}
    																					for(var x=0;x<_this.EixoX.length;x++){
    																							media[x] = media[x]/_this.drilldownniveis.length;
    																					}
    
    																						_this.drilldownniveis.push({
    																								"name": "MÉDIA",
    																								"type":"spline",
    																								"data": media
    																						});
    
    																				setChart(null, _this.EixoX, _this.drilldownniveis, null, 1);
    																				_this.drilldownniveis.pop();
    
    																	} else if(!_this.drilldownniveis){ // restore
    																		chart.setTitle({ text: _this.Titulo });
    																		setChart(null, _this.EixoX,options.series, null,2);
    																	}else if(options.series){ // NÃO VAI ENTRAR AQUI
    																		setChart(null, _this.EixoX,options.series, null,2);
    																	}
    															}
    													}
    											}
    									}
    				},
    				legend: {
    					layout: "horizontal",
    					align: "right",
    					verticalAlign: "bottom",
    					floating: false,
    					borderWidth: 0
    				},
    				credits: {
    					enabled: false
    				},
    				series: []
    				// drilldown: {
    				// 	series: drill_down_data
    				// }
    			};
    
    			function setChart(name, categories, series, color, tipo) {
    
    				if(series.length<=0){
    
    				}else{
    
    			                chart.xAxis[0].setCategories(categories);
    			                while (chart.series.length > 0) {
    			                    chart.series[0].remove(true);
    			                }
    										  for (var i = 0; i < series.length; i++) {
    												var tipocolumn="column";
    												var marcador=[];
    
    												if(i==series.length-1 ){
    													tipocolumn="spline";
    													marcador= {
    														lineWidth: 2,
    														symbol: "circle",
    														lineColor: Highcharts.getOptions().colors[3],
    														fillColor: "white"
    													};
    												}
    							 			//	chart.setTitle({ text: _this.Titulo });
    			                    chart.addSeries({
    														 type: tipocolumn,
    														marker: marcador,
    			                        name: series[i].name,
    			                        data: series[i].data,
    															drilldown: series[i].drilldown,
    			                        color: colors[i]
    			                    });
    			                }
    										}
    
    			            }
    
    //INICIALIZAÇÃO DAS SERIES DO Highcharts
    $(_this.ValoresBarras).each(function(index, el) {
    	var drilldownseries =[];
    
    	var series = {
    		name: el.name,
    		type: "column",
    		data: []
    				};
    			for(var count=0;count<_this.EixoX.length;count++){
    
    				series.data.push({
    						"name": el.name,
    						"y": el.data[count],
    						"colors": colors[index],
    						"drilldown": drilldownseries
    				});
    			}
    
    				$(el.vendedores).each(function(index2, vendedor) {
    					drilldownseries.push({
    			        "name" : vendedor.name,
    			        "data"  : vendedor.data,
    							"drilldown": vendedor.vendedores
    							});
    				});
    
    	options.series.push(series);
    });
    
    $(_this.ValoresLinha).each(function(index, el) {
    		var series = {
    			type: "spline",
    			name: "",
    			data: [],
    			marker: {
    				lineWidth: 2,
    				lineColor: Highcharts.getOptions().colors[3],
    				fillColor: "white",
    			}
    		};
    		series.name = el.name;
    		series.data = el.data;
    		options.series.push(series);
    	});
    
    
    
    			var chart = new Highcharts.Chart(options);
    			/*$("#" + obj).highcharts({
    			});*/
    		});
    
    	///UserCodeRegionEnd: (do not remove this comment.):
    
    
    
    
    
    

    I Create a multi drilldown with multi levels, if anybody needs:

    [http://jsfiddle.net/alissondiel/vNfWk/253/][1]
    

提交回复
热议问题