Highcharts heatmap specific drilldown on axis - highcharts

I build a drillable heatmap with Highchart. It's working well but I need to enhance the capabilities of drilldown on it.
You can see the demo here : https://jsfiddle.net/vegaelce/7wc6t2ex/
I would like to be able to drill on the Y Axis and on the X Axis on specific series.
In the example, by clicking on "California" axis label, I would like the chart drill on 'California_years' drilldown serie.
In the same way, I'd like to be able to click on X-Axis, in the example, by clicking on '2015' label value, the chart would drill to 'States_2015' drilldown serie.
Notice that I use axe_x and axe_y values in each serie to change the axis of the chart on drilldown/drillup event :
events:{
drilldown: function(e) {
var chart = this;
chart.yAxis[0].update({
type: 'category',
categories: y_axes[e.seriesOptions.axe_y]
});
chart.xAxis[0].update({
type: 'category',
categories: x_axes[e.seriesOptions.axe_x]
});
},
drillup: function(e) {
var chart = this;
chart.yAxis[0].update({
type: 'category',
categories: y_axes[e.seriesOptions.axe_y]
});
chart.xAxis[0].update({
type: 'category',
categories: x_axes[e.seriesOptions.axe_x]
});
}
}
How can I achieve these features ?
Thanks

You can check if e.category is defined, if it is, the drilldown was triggered by clicking on axis label. Next, you need to only bind the category with proper drilldown options. For example:
chart: {
type: 'heatmap',
events: {
drilldown: function(e) {
if (typeof e.category !== 'undefined') {
if (e.category === 0) {
e.seriesOptions = this.options.drilldown.series[3];
} else if (e.category === 3) {
e.seriesOptions = this.options.drilldown.series[2]
}
}
var chart = this;
chart.yAxis[0].update({
type: 'category',
categories: y_axes[e.seriesOptions.axe_y]
});
chart.xAxis[0].update({
type: 'category',
categories: x_axes[e.seriesOptions.axe_x]
});
},
...
}
}
Live demo: https://jsfiddle.net/BlackLabel/186mdyfx/

Related

Highcharts drilldown treemap legend

I'm working on a drilldown treemap and the render is exactly what I want.
My problem is about the legend.
I used colorAxis for the drilldown level and I would like to hide the legend on the main level (one color by tile) but display the graduate color axis legend on the sub level, only for the sub-serie displayed.
I made an example here : http://jsfiddle.net/vegaelce/4dLopjwv
I used the property legend to display it :
legend: {
enabled: true
},
but it displays the legend of each colorAxis on the sublevel.
How can I hide all the legend except the one corresponding to the sub-serie displayed ?
Thanks in advance
You can use drilldown and drillup events and update the visible property of the right color axis.
chart: {
type: 'treemap',
events: {
drilldown: function(e) {
const colorAxis = this.colorAxis[e.seriesOptions.colorAxis];
if (colorAxis) {
colorAxis.update({
visible: true
}, false);
}
},
drillup: function() {
this.colorAxis.forEach(function(cAxis){
if (cAxis.visible) {
cAxis.update({
visible: false
}, false);
}
});
}
}
}
Live demo: http://jsfiddle.net/BlackLabel/vtg7fdn6/
API Reference: https://api.highcharts.com/class-reference/Highcharts.Axis#update

Use RangeSelector in Highcharts without Date

So I built a Highcharts application which looks somewhat like this:
https://codesandbox.io/s/angular-opcho
the chart looks like this:
export class ChartComponent implements OnInit {
title = "app";
chart;
updateFromInput = false;
Highcharts = Highcharts;
chartConstructor = "chart";
chartCallback;
data1;
data2;
chartOptions = {
title: {
text: "Global temperature change"
},
subtitle: {
text: "Data input from CSV"
},
plotOptions: {
series: {
marker: {
enabled: false
}
}
},
series: []
}
A highcharts application where you can upload csv data.
If you put in csv data which looks similar to this:
"runs","numbers",differences
"run1","1123",21
"run2","222",7200
"run3","31112",60
"run4","412312",32
you will have a nice graph with x and y axis.
Now, what i am trying to do is to build in a range selector for the y axis so i can sort out really high values and have a better view on the lower values.
My problem is, i can only find range selectors that have something to do with date and time. Is there any range selector for my specific problem?
The basic range selector uses setExtremes method, so you can do the same on yAxis:
var chart = Highcharts.chart('container', {
series: [{
type: 'column',
data: [1, 2, 3, 1, 3, 999, 888, 979]
}]
});
document.getElementById('low').addEventListener('click', function() {
chart.yAxis[0].setExtremes(0, 10);
});
document.getElementById('high').addEventListener('click', function() {
chart.yAxis[0].setExtremes(850, 1000);
});
Live demo: http://jsfiddle.net/BlackLabel/hbf2smoc/
API Reference: https://api.highcharts.com/class-reference/Highcharts.Axis#setExtremes

Highcharts.js - Dynamically disable given category

In Highcharts.js is it possible to disable/enable a given category by clicking on it? In the same way as you can disable/enable a given series in a legend by clicking on it.
If not, what is the next best alternative?
Disabling a category by clicking on it is not supported in Highcharts by default. To acheieve the wanted result you need to add custom code. For example, in render event you can add click event to xAxis labels and update the chart with new categories and data:
var H = Highcharts,
categories = ['one', 'two', 'three'],
data = [1, 2, 3];
chart = Highcharts.chart('container', {
chart: {
events: {
render: function() {
var chart = this;
H.objectEach(chart.xAxis[0].ticks, function(tick) {
if (tick.label) {
H.addEvent(tick.label.element, 'click', function() {
data.splice(tick.pos, 1);
categories.splice(tick.pos, 1);
chart.update({
series: [{
data: data
}],
xAxis: {
categories: categories
}
});
});
}
});
}
}
},
series: [{
type: 'column',
data: data
}],
xAxis: {
categories: categories
}
});
Live demo: http://jsfiddle.net/BlackLabel/8wfx5yve/
API Reference: https://api.highcharts.com/class-reference/Highcharts.Chart#update

How to hide a specific x-axis label programmatically?

Anyone know how to programmatically hide a single xaxis label?
I'm hiding the graphic this way, but I need to do the xaxis label too.
.highcharts().series[0].data[1].graphic.hide()
Here's an example http://jsfiddle.net/2pyzjdch/
I'd like to hide the banana label
You can hide the label you want in this way:
.highcharts().xAxis[0].ticks[1].label.hide();
Live demo: http://jsfiddle.net/BlackLabel/68jyh7so/
You can do this in many ways e. g. updating your xAxis categories on click:
chart: {
type: 'bar',
events: {
load() {
var btnHide = document.getElementById('btnHide'),
btnShow = document.getElementById('btnShow'),
chart = this;
btnHide.addEventListener('click', function() {
chart.update({
xAxis: {
categories: ['Apples', '', 'Oranges']
}
})
})
btnShow.addEventListener('click', function() {
chart.update({
xAxis: {
categories: ['Apples', 'Banaas', 'Oranges']
}
})
})
}
}
},
jsFiddle: http://jsfiddle.net/BlackLabel/n87e9gfr/
API Reference: https://api.highcharts.com/highcharts/chart.events.load
https://api.highcharts.com/class-reference/Highcharts.Chart#update

Wrong x-axis position and formatting when only 1 data series sent to chart

I found out a problem with chart (highcharts 2.3.5) when i enter datetime series with only 1 data entry, it renders it with incorrect placement on x-axis and wrong point formatting.
here is the example: http://jsfiddle.net/LAcSw/
$(function () {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
xAxis: {
type: 'datetime'
},
series: [{
data: [
[Date.UTC(2010, 0, 1), 29.9]
]
}]
});
});
Is there a fix know or something(it was fine on 2.2.5)?
Since you only have a single point HighCharts is making its best guess as to the yAxis range as well as what the label is on the point for the xAxis.
You are not defining any sort of formatting for the xAxis datetime labels - and HighCharts only has one point to work with so it defaults to time. If you assign a formatter for the xAxis labels you can get it to do what you want.
Here is some rough code to show you what this does:
xAxis: {
type: 'datetime',
labels: {
formatter: function() {
return Highcharts.dateFormat('%d %b %Y', this.value);
}
}
},
yAxis: {
min: 0,
max:50
},
And here is your jsFiddle updated.

Resources