Highchart Drilldown with data call when clicked - highcharts

I want to create a drill down chart but when a certain bar or label is click the next chart to display will be load/get data from Database first. It means that 2nd level drill down is not yet preloaded. I don't know how to do it or the right functions to search.
Thank you.

In drilldown event you can get data and use addSeriesAsDrilldown method:
Highcharts.chart('container', {
chart: {
type: 'column',
events: {
drilldown: function(e) {
if (!e.seriesOptions) {
var chart = this,
source = {
Animals: 'https://api.myjson.com/bins/100f5h',
Fruits: 'https://api.myjson.com/bins/csik5',
Cars: 'https://api.myjson.com/bins/sxd1x'
};
chart.showLoading('Waiting for data...');
$.get(source[e.point.name], function(data) {
chart.hideLoading();
chart.addSeriesAsDrilldown(e.point, data[e.point.name]);
});
}
}
}
},
...
series: [{
...,
data: [{
name: 'Animals',
y: 5,
drilldown: true
}, {
name: 'Fruits',
y: 2,
drilldown: true
}, {
name: 'Cars',
y: 4,
drilldown: true
}]
}],
drilldown: {
series: []
}
});
Live demo: http://jsfiddle.net/BlackLabel/7r2z3t85/
API Reference: https://api.highcharts.com/class-reference/Highcharts.Chart#addSeriesAsDrilldown
Docs: https://www.highcharts.com/docs/chart-concepts/drilldown

Related

Highcharts histogram drilldown: set options for drilldown + first and last column cut-off

I have a game with 3 difficulties and I show their averages in a first graph. Now I want to use drilldown to show a spread of the scores for each difficulty in a histogram. I managed to get this working but I have two problems. First of all I use update to change the setting for the drilldown graphs, but then these settings also change for the first graph and thus I was wondering what the better way would be to do this.
My other problem is that in my histogram the first and last column are cut in half and only half is shown, but I cant seem to find a way to solve this. I tried min- and maxPadding but this did not work.
chart of the tree difficulties
Histogram of one difficulty
https://jsfiddle.net/vlovlo/sng4jwv8/36/
Here is my code
Highcharts.chart('skippedPatients', {
chart: {
events: {
drilldown: function (e) {
this.update({
title: {text: "Skipped patient: " + e.point.name},
xAxis:{
title:{text: "Nr of skipped patients"},
tickmarkPlacement: 'on',
},
yAxis:{title:{text: "Nr of players"}},
plotOptions:{series:{pointPlacement: 'on'}},
});
if (!e.seriesOptions) {
var chart = this,
drilldowns = {
'Histogram: Easy': {
name: 'Easy',
type: 'histogram',
baseSeries: 'avgSkippedEasy'
},
'Easy': {
id: 'avgSkippedEasy',
visible: false,
type: 'column',
data: skippedPatientsList
}
},
series = [drilldowns['Histogram: ' + e.point.name], drilldowns[e.point.name]];
chart.addSingleSeriesAsDrilldown(e.point, series[0]);
chart.addSingleSeriesAsDrilldown(e.point, series[1]);
chart.applyDrilldown();
}
}
}
},
title: {
text: 'Skipped patients'
},
xAxis: {
type: 'category',
},
legend: {
enabled: false
},
plotOptions: {
series: {
borderWidth: 0,
dataLabels: {
enabled: true
},
},
histogram: {
binWidth: 1
}
},
series: [{
name: 'Averages per difficulty',
colorByPoint: true,
type: 'column',
data: [{
name: 'Easy',
y: 5,
drilldown: true
}, {
name: 'Moderate',
y: 2,
drilldown: true
}, {
name: 'Hard',
y: 4,
drilldown: true
}]
}],
drilldown: {
series: []
}
});
You should define your initial options as a variable and attach them again in the drillup callback due to you did a chart update with changed the initial options.
Demo: https://jsfiddle.net/BlackLabel/5d1atnh7/

Highcharts stacked column how to use different label on each category

Hi guys I want to achieve something like this using HighCharts Stacked Column
This is my current code
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
}
}
},
xAxis: {
categories: ['Cukai Semasa', 'Tunggakan Cukai']
},
series: [{
name: 'Baki Cukai Semasa',
data: [69000000, 60000000]
}, {
name: 'Kutipan Semasa',
data: [69000000, 60000000]
}]
Which resulting this chart
As you can see, my generated chart dont have the label for Tunggakan Cukai category (Baki Kutipan Tunggakan and Kutipan Tunggakan).
How to achieve this using Stacked Column?
Thanks
Another way is to use series.legendType: 'point'.
Code:
Highcharts.chart('container', {
chart: {
type: 'column'
},
plotOptions: {
column: {
legendType: 'point',
stacking: 'normal',
dataLabels: {
enabled: true,
}
}
},
xAxis: {
categories: ['Cukai Semasa', 'Tunggakan Cukai']
},
series: [{
data: [{
name: 'Baki Cukai Semasa',
y: 69000000,
color: '#72AD4D'
}, {
name: 'Baki Kutipan Tunggakan',
y: 60000000,
color: '#FC3D45'
}]
}, {
data: [{
name: 'Kutipan Semasa',
y: 69000000,
color: '#AAD092'
}, {
name: 'Kutipan Tunggakan',
y: 60000000,
color: '#FD7C82'
}]
}]
});
Demo:
https://jsfiddle.net/BlackLabel/9xmnrqp2/
One way of achieving this and showing all points in legend is by making them individual series:
series: [{
name: 'Baki Cukai Semasa',
data: [69000000, null]
}, {
name: 'Kutipan Semasa',
data: [60000000, null]
}, {
name: 'Baki Kutipan Tunggakan',
data: [null, 69000000]
}, {
name: 'Kutipan Tunggakan',
data: [null, 60000000]
}]
See this JSFiddle demonstration of it in use.

Highcharts - async drill-down in tree-map with thousands of items

I wanted to know if it's possible to use an async drill down on treemap?
I have 7000 items that need to be drawn and it stuck while the treemap is creating.
So I think to create treemap by lazy loading. I didn't find any example of treemap with huge data (while the items are below 1000 it's not a problem like in the example of the large treemap).
I will appreciate any help.
Yes, it can be done exactly the same for any type of series.
Example for treemap:
Highcharts.chart('container', {
chart: {
events: {
drilldown: function(e) {
this.addSeriesAsDrilldown(e.point, {
type: "treemap",
layoutAlgorithm: 'squarified',
data: [{
name: 'A1',
value: 11,
drilldown: true
}, {
name: 'A2',
value: 44
}]
});
}
}
},
series: [{
type: "treemap",
layoutAlgorithm: 'squarified',
data: [{
name: 'A',
value: 6,
drilldown: true
}, {
name: 'B',
value: 2
}]
}]
});
Live demo: http://jsfiddle.net/BlackLabel/knj7bqs5/

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]
]
}]
}
});
});

Sort series per category

I have a chart that looks like this:
http://jsfiddle.net/rtGFm/37/
I would like to have a "sort" button that sorts high to low each category, putting the columns in a different order for each category. Is this possible with HighCharts?
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column'
},
title: {
text: ''
},
subtitle: {
text: ''
},
xAxis: {
categories: [
'foreclosures',
'nuisances',
'distance from city center'
]
},
yAxis: {
min: 0,
title: {
text: ''
}
},
tooltip: {
formatter: function() {
return ''+
this.x +': '+ this.y +' mm';
}
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Alger Heights',
data: [49.9, 71.5, 50]
}, {
name: 'Shawmut Hills',
data: [83.6, 78.8, 67]
}, {
name: 'Baxter',
data: [48.9, 38.8, 100]
}, {
name: 'Midtown',
data: [42.4, 33.2, 80]
}, {
type: 'scatter',
data: [55,60,70],
marker: {
symbol: 'square',
lineColor: '#FFFFFF',
lineWidth: 1,
radius: 8
},
name: 'Average'
}]
});
});
I had the same problem :) highcharts still does not provide any solution for this problem, but it is flexibel enough so that you can sort anyway - just by javascript.
Put your data in a separate value:
var dataMain = [{name:"test1",data:5}, {name:"test1",data:1},{name:"test1",data:2}]
In series you can just add a function which sorts your data:
series: (function(){
for(var i = 0;i<dataMain.length;i++){
dataMain[i].data = dataMain[i].data.sort(function(a,b){
return a[0] - b[0] ;
})
return dataMain;
}
Hope I got everything wright.
Got it to work, I believe. Trick is to add each column in correct order as a new serie with same type (column), reuse colors and hide legend...
Very hackish, the JS code to sort like 8 categories independently will be ugly but the result looks fine.
Edit: Updated fiddle, I see the spacing between the categories grows with series, doesn't look supernice.
My jsfiddle is here
$(function () {
$('#container').highcharts({
chart: {
inverted: true
},
title: {
text: 'Series sorted in within categories'
},
xAxis: {
categories: ['January']
},
series: [{
type: 'column',
name: 'Stockholm',
data: [{x:0, y:95, color: Highcharts.getOptions().colors[0]}]
}, {
type: 'column',
name: 'Göteborg',
data: [{x:0, y:80, color: Highcharts.getOptions().colors[1]}]
}, {
type: 'column',
name: 'Göteborg',
data: [{x: 1, name: 'February', y: 98, color: Highcharts.getOptions().colors[1] // VGR's color
}],
showInLegend: false,
dataLabels: {
enabled: false
}
}, {
type: 'column',
name: 'Stockholm',
data: [{x: 1, name: 'February', y: 80, color: Highcharts.getOptions().colors[0] // VGR's color
}],
showInLegend: false,
dataLabels: {
enabled: false
}
}]
});
});
br,
Jens
I think this can be done,
this may look like a little work around.
since we have a limited number of columns i mean 4 in the given example.
if we have arrays with sorting done with respect to each series then we can handle them.
on button click we can update the chart with new set of data as well as category array.
May be there is no solution from the APi.
According to me this is a possible approach.
Thanks,

Resources