Pie chat dynamic drilldown(3levels) using highchatjs - highcharts

Below is the complete code and , i am unable to do the 2nd level drilldown of pie chats.
How to add multilevel drilldown series? First chat i have 2 sections of data (completed and Fail) , in second chat data will be the dynamic depending upon the selection of the first pie slice. same thing for third level chat as well.
var chartSeriesData = [];
var chartSeriesData1 =[];
var chartDrilldownData = [];
chartSeriesData = [{
name: "Completed",
y: 1,
color: "#1068C7",
drilldown: "Completed"
}, {
name: "Fail",
y: 2,
color: "#11A852",
drilldown: "Fail"
}];
chartSeriesData1 = [{
id: "Completed",
data: [{
name: 'CEVA',
y: 15,
drilldown: 'CEVA-COMPLETED'
},{
name: 'SYNCHRON',
y: 13,
drilldown: 'SYNCHRON-COMPLETED'
},{
name: 'GENCO',
y: 23,
drilldown: 'GENCO-COMPLETED'
}],
}, {
id:"Fail",
data: [{
name: 'CEVA',
y: 45,
drilldown: 'CEVA-FAIL'
},{
name: 'SYNCHRON',
y: 23,
drilldown: 'SYNCHRON-FAIL'
},{
name: 'GENCO',
y: 23,
drilldown: 'GENCO-FAIL'
}],
}];
chartDrilldownData = [
{
id:"CEVA-COMPLETED",
data: [{
name: 'BFC',
y: 19
},{
name: 'BMC',
y: 23
}],
},
{
id:"SYNCHRON-COMPLETED",
data: [{
name: 'qwsh',
y: 1
},{
name: 'adwa',
y: 1
}],
},
{
id:"GENCO-COMPLETED",
data: [{
name: 'qwsh',
y: 1
},{
name: 'adwa',
y: 1
}],
} ,
{ id:"CEVA-FAIL",
data: [{
name: 'BFC',
y: 19
},{
name: 'BMC',
y: 23
}],
},
{
id:"SYNCHRON-FAIL",
data: [{
name: 'qwsh',
y: 1
},{
name: 'adwa',
y: 1
}],
},
{
id:"GENCO-FAIL",
data: [{
name: 'qwsh',
y: 1
},{
name: 'adwa',
y: 1
}],
}
];
console.log('----------------');
console.log(chartSeriesData);
console.log('----------------');
console.log(chartSeriesData1);
console.log('----------------');
console.log(chartDrilldownData);
console.log('-------------------');
// Create the chart
Highcharts.chart('container', {
chart: {
type: 'pie'
},
title: {
text: 'Browser market shares. January, 2018'
},
subtitle: {
text: 'Click the slices to view versions. Source: statcounter.com'
},
plotOptions: {
series: {
allowPointSelect: true,
point: {
events: {
select: function () {
var drilldown = this.drilldown;
console.log('drilldown'+drilldown);
// alert(this.options);
//console.log(this.options)
console.log(this.series.data);
}
}
},
dataLabels: {
enabled: true,
format: '{point.name}: {point.y:.1f}%'
},
drilldown:true
}
},
tooltip: {
headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>'
},
series: [{
name: 'Status',
colorByPoint: true,
data: chartSeriesData
}],
drilldown:{
series: chartSeriesData1
}
});

You created chartDrilldownData but never use it in the chart parameters, so the second level never trigger on click.
Just remove this code :
];
chartDrilldownData = [
And the working Fiddle

Related

Highcharts (9.0.1): drilldown problem after change chart type dynamically

I'm an highcharts beginner...and this is my problem:
I have a 3 level drilldown chart with the possibility to change graph using buttons.
Start with a 'column' chart and drilldown to the first level; now if I change the chart type to 'pie' and try to drilldown, this last action does not work correctly
Can you help me?
Thks
var series = [{
name: 'Nascite',
id: 'Nascite',
data: [{
name: '2018',
y: 1000,
drilldown: 'Nascite 2018'
},{
name: '2019',
y: 200,
drilldown: 'Nascite 2019'
}]
}];
var drilldown = {
series: [{
name: 'Nascite 2018',
id: 'Nascite 2018',
data: [{
name: 'USA',
y: 800,
drilldown: 'Nascite 2018 USA'
}, {
name: 'ITALY',
y: 900,
drilldown: 'Nascite 2018 ITALY'
}]
}, {
name: 'Nascite 2019',
id: 'Nascite 2019',
data: [{
name: 'USA',
y: 200,
drilldown: 'Nascite 2019 USA'
}]
},{
name: 'Nascite 2018 USA',
id: 'Nascite 2018 USA',
data: [{
name: 'Texas',
y: 100
},{
name: 'California',
y: 500
}]
},{
name: 'Nascite 2018 ITALY',
id: 'Nascite 2018 ITALY',
data: [{
name: 'TrentinoAA',
y: 400,
drilldown: 'Nascite 2018 ITALY TrentinoAA'
}]
},{
name: 'Nascite 2019 USA',
id: 'Nascite 2019 USA',
data: [{
name: 'Texas',
y: 200
}]
},{
name: 'Nascite 2018 ITALY TrentinoAA',
id: 'Nascite 2018 ITALY TrentinoAA',
data: [{
name: 'Trento',
y: 300
},{
name: 'Bolzano',
y: 100
}]
}]
};
const chart = Highcharts.chart('container', {
chart: {
type: 'column',
events: {
drillup: function(e){},
drilldown: function(e){}
}
},
drillInventory: [],
title: {
text: 'Chart.update'
},
subtitle: {
text: 'Plain'
},
xAxis: {
type: 'category'
},
yAxis: {},
series: series,
drilldown: drilldown
});
document.getElementById('plain').addEventListener('click', () => {
chart.update({
chart: {
type: 'column'
}
});
});
document.getElementById('pie').addEventListener('click', () => {
chart.update({
chart: {
type: 'pie'
}
});
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://github.highcharts.com/modules/drilldown.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<button id="plain">Plain</button>
<button id="pie">Pie</button>
It looks like a bug - I reproted it on the Highcharts Github issue channel where you can follow this thread - https://github.com/highcharts/highcharts/issues/15496

Highcharts datalabels getting scrambled on drilldown

This is a follow-up issue I'm having to this answered problem. I needed help with keeping series grouped together, but spaced apart between categories. I've added drilldown to the chart, and there is an issue with the datalabels when drilling down - they don't center over the columns anymore. The more you drill up and down, the more off they become. I've figured out the reason has to do with resetting the category names, although I have no idea why or what to do about it. But in the drilldown event, if you comment out where the categories are getting reset, the datalabels are centered again.
Here's a fiddle to show what I mean -- any suggestions?
var redrawEnabled = true;
var refChart = new Highcharts.chart('ctReferralsDetail', {
chart: {
backgroundColor: 'whiteSmoke',
type: 'column',
width: 800,
events: {
drilldown: function() {
refChart.xAxis[0].setCategories(["Ballard", "Butler", "Central", "Doss", "Iroquois", "Male", "Pleasure Ridge"]);
refChart.xAxis[0].update({
max: categoriesAA.length - 1
}, true);
this.update({
scrollbar: {
enabled: true,
}
}, false);
redraw(this);
},
drillupall: function() {
this.update({
scrollbar: {
enabled: false
}
}, false);
redraw(this);
},
render: function() {
redraw(this);
},
}
},
title: {
text: "# Referrals"
},
subtitle: {
text: 'subTitle'
},
xAxis: {
categories: ['Elementary 1', 'Elementary 2', 'Elementary 3', 'Middle', 'High'],
min: 0,
max: 4,
},
yAxis: [{
title: {
useHtml: true,
text: '<strong># Referrals</strong>'
}
}],
tooltip: {
shared: true,
},
plotOptions: {
column: {
borderRadius: 5,
dataLabels: {
enabled: true,
allowOverlap: true
},
grouping: false,
pointWidth: 45
}
},
series: [{
name: "2017-18",
data: [{
drilldown: 'py1',
y: 5513
}, {
drilldown: 'py2',
y: 5403
}, {
drilldown: 'py3',
y: 3132
}, {
drilldown: 'py4',
y: 12385
}, {
drilldown: 'py5',
y: 22679
}]
}, {
name: "2018-19",
data: [{
drilldown: 'cy1',
y: 5738
}, {
drilldown: 'cy2',
y: 4397
}, {
drilldown: 'cy3',
y: 3508
}, {
drilldown: 'cy4',
y: 10811
}, {
drilldown: 'cy5',
y: 22743
}]
}],
drilldown: {
allowPointDrilldown: false,
series: [{
name: "2017-18",
id: "py1",
data: [93, 41, 410, 84, 76, 120, 11, 525]
}, {
name: "2018-19",
id: "cy1",
data: [84, 48, 423, 78, 76, 123, 19, 502]
}]
}
})
function redraw(parm) {
var series = parm.series;
if (redrawEnabled) {
if (parm.chartWidth > 600) {
if (parm.options.plotOptions.column.grouping) {
redrawEnabled = false;
parm.update({
plotOptions: {
column: {
grouping: false
}
}
});
redrawEnabled = true;
}
series.forEach(function(s, i) {
s.points.forEach(function(p) {
if (i === 0) {
p.graphic.attr({
translateX: 25
});
p.dataLabel.attr({
translateX: p.dataLabel.translateX + 25
});
} else {
p.graphic.attr({
translateX: -25
});
p.dataLabel.attr({
translateX: p.dataLabel.translateX - 25
});
}
});
});
} else {
if (!parm.options.plotOptions.column.grouping) {
redrawEnabled = false;
this.update({
plotOptions: {
column: {
grouping: true
}
}
});
redrawEnabled = true;
}
}
}
}
In my opinion, you don't need your own function to position the columns as you did. The easiest solution is to remove the pointWidth and then set appropriate pointPadding and groupPadding to create greater space between categories. Then drilldown works as expected. Check demo I posted you below.
Code:
var refChart = new Highcharts.chart('ctReferralsDetail', {
chart: {
backgroundColor: 'whiteSmoke',
type: 'column',
width: 800
},
title: {
text: "# Referrals"
},
subtitle: {
text: 'subTitle'
},
xAxis: {
categories: ['Elementary 1', 'Elementary 2', 'Elementary 3', 'Middle', 'High'],
min: 0,
max: 4,
},
yAxis: [{
title: {
useHtml: true,
text: '<strong># Referrals</strong>'
}
}],
tooltip: {
shared: true,
},
plotOptions: {
column: {
borderRadius: 5,
dataLabels: {
enabled: true,
allowOverlap: true
},
groupPadding: 0.15,
pointPadding: 0.05
}
},
series: [{
name: "2017-18",
data: [{
drilldown: 'py1',
y: 5513
}, {
drilldown: 'py2',
y: 5403
}, {
drilldown: 'py3',
y: 3132
}, {
drilldown: 'py4',
y: 12385
}, {
drilldown: 'py5',
y: 22679
}]
}, {
name: "2018-19",
data: [{
drilldown: 'cy1',
y: 5738
}, {
drilldown: 'cy2',
y: 4397
}, {
drilldown: 'cy3',
y: 3508
}, {
drilldown: 'cy4',
y: 10811
}, {
drilldown: 'cy5',
y: 22743
}]
}],
drilldown: {
allowPointDrilldown: false,
series: [{
name: "2017-18",
id: "py1",
data: [93, 41, 410, 84, 76, 120, 11, 525]
}, {
name: "2018-19",
id: "cy1",
data: [84, 48, 423, 78, 76, 123, 19, 502]
}]
}
});
Demo:
https://jsfiddle.net/BlackLabel/7ok69jbq/1/

Highcharts multi-level drilldown with scroll bar only draw partial of the columns

I need to draw a chart with multi-level drilldowns. Because each level has different number of columns, I will update max of x-axis inside drilldown/drillup events. Then I noticed, some drilldown graph are messed up. The bar only draw the top parts. For example, y=3068. The graph only draws from 1500 to 3068.The bottom part is cut off.
$(function () {
// Create the chart
Highcharts.chart('container', {
chart: {
type: 'column',
events: {
load: function (e) {
this.xAxis[0].update({ max: 5 });
},
drilldown: function (e) {
this.xAxis[0].update({ min: 0 });
this.yAxis[0].update({ min: 0 });
if (e.seriesOptions.data.length > 14)
this.xAxis[0].update({ max: 15 });
else {
this.xAxis[0].update({ max: e.seriesOptions.data.length - 1 });
}
},
drillup: function (e) {
this.xAxis[0].update({ min: 0 });
this.yAxis[0].update({ min: 0 });
if (e.seriesOptions.data.length > 14)
this.xAxis[0].update({ max: 15 });
else {
this.xAxis[0].update({ max: e.seriesOptions.data.length - 1 });
}
}
}
},
title: {
text: 'Basic drilldown'
},
scrollbar: {
enabled: true
},
xAxis: {
type: 'category'
},
legend: {
enabled: false
},
plotOptions: {
series: {
borderWidth: 0,
dataLabels: {
enabled: true
}
}
},
series: [{
name: 'Daily Data',
colorByPoint: true,
data: [{
name: '11/14/2016',
y: 5850,
drilldown: '11/14/2016'
}
]
}],
drilldown: {
series: [{
id: '11/14/2016',
data: [
{name: 'Customer Advocacy',
y: 8,
drilldown: 'Customer Advocacy0'},
{name: 'General Information',
y: 3068,
drilldown: 'General Information0'},
{name: 'Surcharge',
y: 98,
drilldown: 'Surcharge0'},
{name: 'Suspension And Restoration',
y: 2676,
drilldown: 'Suspension And Restoration0'}
]
}, {
id: 'Customer Advocacy0',
data: [
['Belinda Arduini',2],
['Deann Avery',2],
['Michele Rahilly',3],
['Tonia Lacey',1]
]
}, {
id: 'General Information0',
data: [
['Alicia Richardson',44],
['Angela Gash',86],
['Angela Migliaccio',125],
['Ashonti Sweat',178],
['Ayesha Walker',119],
['Brandon Steen',76],
['Charesse Yarbrough',101],
['Denise Davis',2],
['Dominicia Brown',65],
['Eldora Thompson',105],
['Essie Davis',2],
['Isa Martinez',17],
['Joanne Hendricks',102],
['Kenyell Kelley',149],
['Kiara Watkins',93],
['Kimberly Barlow',109],
['Lee Palma',30],
['Leslie Caceros',155],
['Lisa Fischer',184],
['Lisa Poliziana',139],
['Malisa Stanisclaus',116],
['Michael Carlisi',145],
['Miguel Rivera',85],
['Natacha Perez-Mendez',130],
['Patricia Bell',119],
['Sandra Buchanan',99],
['Sharae Donalson',140],
['Shawn Gribbin',120],
['Tara Damico',233]
]
},
{
id: 'Surcharge0',
name: '11/14/2016:Surcharge',
data: [
['Ernestine Bunche',17],
['Janice Avent',17],
['Sabrina Moses',20],
['Veronica Gibson',44]
]
},
{
id: 'Suspension And Restoration0',
name: '11/14/2016:Suspension And Restoration',
data: [
['Angel Deleon',95],
['Catherine Lynch',81],
['Colby Tobin',212],
['Coreena Contreras',158],
['Crystal Marshall',83],
['Dane Powell',144],
['Darrell Jones',98],
['Denise Campi',166],
['Denise Manners',32],
['Diane Koval',114],
['Eugenia Kostis',24],
['Jeanne Cheeseman',136],
['Jennifer Hiel',167],
['Jennifer Rodriguez',102],
['Lasonda Swinney',83],
['Latina Mason',53],
['Sherry Tartaglia',254],
['Susan Pasteur',43],
['Tomeka Ramocan',49],
['Tracey Green',155],
['Tracy Paulin',111],
['Tricia Palazzone',86],
['Ursula Covington',55],
['Virginia Dardis',175]
]
}]
}
});
});

Set Additional Data to highcharts series in Area Chart with Line

I can't seem to figure out how to add an additional data point to the series data in Highcharts when running an area chart with line.
Here's the chart that I'd like to add an additional data point to:
http://jsfiddle.net/localman/uL8rwu6f/
$(function () {
var ranges = [
[1246406400000, 14.3, 27.7],
[1246492800000, 14.5, 27.8],
[1246579200000, 15.5, 29.6]
],
averages = [
[1246406400000, 21.5],
[1246492800000, 22.1],
[1246579200000, 23]
];
$('#container').highcharts({
title: {
text: 'July temperatures'
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
text: null
}
},
tooltip: {
crosshairs: true,
shared: true,
valueSuffix: '°C'
},
legend: {
},
series: [{
name: 'Temperature',
data: averages,
zIndex: 1,
marker: {
fillColor: 'white',
lineWidth: 2,
lineColor: Highcharts.getOptions().colors[0]
}
}, {
name: 'Range',
data: ranges,
type: 'arearange',
lineWidth: 0,
linkedTo: ':previous',
color: Highcharts.getOptions().colors[0],
fillOpacity: 0.3,
zIndex: 0
}]
});
});
I can display the additional data in a single series, but not with the above for some reason http://jsfiddle.net/localman/dWDE6/859/
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
tooltip: {
formatter: function () {
return 'Extra data: <b>' + this.point.myData + '</b>';
}
},
series: [{
name: 'Foo',
data: [{
y: 3,
myData: 'firstPoint'
}, {
y: 7,
myData: 'secondPoint'
}, {
y: 1,
myData: 'thirdPoint'
}]
}]
});
Any suggestions on how to combine these?

Highcharts {Pie} - Remove slice pieces out onclick

How can I remove slice out of pie chart pieces?
Online Demo
Reference
You can control this animation with plotOptions.pie.slicedOffset property.
So, just by setting slicedOffset: 0, you will get desired behavior.
series: [{
states: {
hover: {
enabled: false,
}
},
name: 'Brands',
slicedOffset: 0,
colorByPoint: true,
data: [{
name: 'IE',
y: 56.33
}, {
name: 'Chrome',
y: 24.03,
sliced: true,
selected: true
}, {
name: 'Firefox',
y: 10.38
}, {
name: 'Others',
y: 0.2
}]
}]
Live example: jsFiddle.

Resources