I am trying to create TreeMap with multiple series, the series are getting plotted on the graph with both series clubbed together, but I want only one series to be displayed at a time. Basically legand can be used but for treemap it's showing values.
This is the jsfiddle I am trying to work on
JavaScript files used
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/heatmap.js"></script>
<script src="https://code.highcharts.com/modules/treemap.js"></script>
<div id="container"></div>
The treemap should be updated as per the series selected.
Highchart Bound Using
Highcharts.chart('container', {
colorAxis: {
minColor: '#FFFFFF',
maxColor: Highcharts.getOptions().colors[0]
},
legend: {
enabled: true,
},
series: [{
name:"Series 1",
stack: 'aeroplanes',
type: 'treemap',
layoutAlgorithm: 'squarified',
data: [{
name: 'A -Series 1',
value: 6,
colorValue: 1
}, {
name: 'B -Series 1',
value: 6,
colorValue: 2
}, {
name: 'C -Series 1',
value: 4,
colorValue: 3
}, {
name: 'D -Series 1',
value: 3,
colorValue: 4
}, {
name: 'E -Series 1',
value: 2,
colorValue: 5
}, {
name: 'F -Series 1',
value: 2,
colorValue: 6
}, {
name: 'G -Series 1',
value: 1,
colorValue: 7
}]
},
// Second Series
{
name:"Series 2",
type: 'treemap',
stack: 'aeroplanes2',
layoutAlgorithm: 'squarified',
visible:true,
data: [{
name: 'AA -Series 2',
value: 16,
colorValue: 2
}, {
name: 'BB -Series 2',
value: 26,
colorValue: 2
}, {
name: 'Cc -Series 2',
value: 14,
colorValue: 2
}, {
name: 'Dd -Series 2',
value: 13,
colorValue: 2
}, {
name: 'Ee -Series 2',
value: 12,
colorValue: 2
}, {
name: 'Ff -Series 2',
value: 12,
colorValue: 2
}, {
name: 'Gg -Series 2',
value: 11,
colorValue: 2
}]
}],
title: {
text: 'Highcharts Treemap'
},
plotOptions: {
treemap: {
stacking: 'percent'
}
},
});
By default showInLegend equals to false for treemap series - it needs to be enabled manually. In legendItemClick event I handled series visibility toggling:
plotOptions: {
treemap: {
showInLegend: true,
events: {
legendItemClick: function() {
this.chart.series.forEach((s) => s.setVisible());
return false;
}
}
}
}
Live demo: http://jsfiddle.net/kkulig/0n49vv74/
API references:
https://api.highcharts.com/highcharts/plotOptions.treemap.events.legendItemClick
https://api.highcharts.com/highcharts/plotOptions.treemap.showInLegend
https://api.highcharts.com/class-reference/Highcharts.Series#setVisible
Related
I'm working on Treemap combined with Heatmap (to get the colorAxis feature) and multi-levels (to drill in the data).
It works fine, can see here the sample result http://jsfiddle.net/vegaelce/q5n4bur3.
colorAxis: {
minColor: "#ffffff",
maxColor: "#0000ff"
},
series: [{
type: "treemap",
layoutAlgorithm: 'sliceAndDice',
allowDrillToNode: true,
alternateStartingDirection: true,
levelIsConstant: false,
dataLabels: {
enabled: false
},
levels: [{
level: 1,
dataLabels: {
enabled: true,
},
borderWidth: 3
},{
level: 2,
borderWidth: 2
},{
level: 3,
borderWidth: 1
}],
data: [
{ name:'Accessories',
id:'Accessories',
value: 6297610.2,
colorValue: 6297610.2,
},
{ name:'Dresses',
value: 1587737.4,
colorValue: 1587737.4,
},
{ name:'City Trousers',
value: 171824.3,
colorValue: 171824.3,
},
{ name:'City Skirts',
value: 171570.4,
colorValue: 171570.4,
},
{
name: '2014', id: 'Accessories_2014', value: 3499307.1, parent: 'Accessories',colorValue: 3499307
},{
name: '2015',value: 1926600.4, parent: 'Accessories',colorValue: 1926600
},{
name: '2016',value: 871702.7, parent: 'Accessories',colorValue: 871702
},
{
name: 'Q1', id: 'Accessories_2014_Q1', value: 6297610.1, parent: 'Accessories_2014',colorValue: 6297610
},
{
name: 'Q2', id: 'Accessories_2014_Q2', value: 171824.1, parent: 'Accessories_2014',colorValue: 171824
},
{
name: 'Q3', id: 'Accessories_2014_Q3', value: 109307.1, parent: 'Accessories_2014',colorValue: 109307
}
]
}]
What I need, to clarify the reading of this kind of chart, is to display on a given level, only one color for each group-node (not the colors of the children values).
For example, in my dataset, I'd like on the first level, see one color for the "Accessories" group (the dark blue we can see when hover the group with the mouse).
When we click on "Accessories", then we can see only one color for "2014"...
Is it possible and if yes, how can I do that ?
Thanks in advance
Take a look at this demo: http://jsfiddle.net/BlackLabel/841Lxsuj/ I used the render callback to update the colorAxis colors after the drilldown event has been triggered.
events: {
render() {
let chart = this;
if (chartForRender) {
chartForRender = false;
if (chart.series[0].drillUpButton) {
chart.update({
colorAxis: {
minColor: "red",
maxColor: "orange"
}
})
} else {
chart.update({
colorAxis: {
minColor: "#ffffff",
maxColor: "#0000ff"
}
})
}
}
chartForRender = true;
}
}
API: https://api.highcharts.com/highcharts/chart.events.render
API: https://api.highcharts.com/class-reference/Highcharts.Chart#update
i like to change the color of the bars in a stacked bar chart in highchart. I did not found the option where i can set the color foreach value. Joe should be red, Jane yellow, and John black.
Highcharts.chart('container', {
chart: {
type: 'bar'
},
title: {
text: 'Stacked bar chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
}
},
legend: {
reversed: true
},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
data: [2, 2, 3, 2, 1]
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5]
}]
});
You can add the field color in your serie like:
series: [{
name: 'John',
color: '#ff8080',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
color: '#ffff00',
data: [2, 2, 3, 2, 1]
}, {
name: 'Joe',
color: '#000000',
data: [3, 4, 4, 2, 5]
}]
while using Highcharts multi level treemap I ran into data labels overflow issue. Data labels overflows to other area. This works fine at level 1 & 2 when I use option overflow: 'crop' but does not work at level 3. Any idea where it is going wrong.
Here in example area with name:F data label overflows but data label with name:C at level 2 does not overflow.
Here is fiddle example.
$(function() {
var H = Highcharts;
$('#container').highcharts({
chart: {
type: 'treemap',
width: 500
},
title: {
text: null
},
plotOptions: {
series: {
layoutAlgorithm: 'stripes',
alternateStartingDirection: true,
levels: [{
level: 1,
dataLabels: {
enabled: true,
align: 'left',
verticalAlign: 'top'
}
}, {
level: 2,
dataLabels: {
formatter: function () {
return this.point.realValue;
},
overflow: 'crop'
}
}, {
level: 3,
dataLabels: {
formatter: function () {
return this.point.realValue;
},
overflow: 'crop'
}
}]
}
},
series: [{
data: [{
name: 'A',
id: 'A',
value: 1,
color: '#FFFFFF'
}, {
name: 'B',
id: 'B',
value: 1,
color: '#FFFFFF'
}, {
name: 'C',
parent: 'A',
id: 'A-1',
value: 10,
realValue: 'thisisveryveryveryveryveryverylongteststring',
color: '#ECEA8E'
}, {
name: 'D',
parent: 'A',
id: 'A-2',
color: '#FFFFFF'
}, {
name: 'E',
parent: 'A-2',
id: 'A-2-1',
value: 10,
realValue: 'A',
color: '#599753'
}, {
name: 'F',
parent: 'A-2',
id: 'A-2-2',
value: 10,
realValue: 'thisisveryveryveryverylongteststring',
color: '#1B3C40'
}, {
name: 'G',
parent: 'B',
id: 'B-1',
value: 10,
realValue: 'A',
color: '#ECEA8E'
}, {
name: 'H',
parent: 'B',
id: 'B-2',
color: '#FFFFFF'
}, {
name: 'I',
parent: 'B-2',
id: 'B-2-1',
value: 10,
realValue: 'A',
color: '#599753'
}, {
name: 'J',
parent: 'B-2',
id: 'B-2-2',
value: 10,
realValue: 'A',
color: '#1B3C40'
}]
}]
});
});
Unfortunately, Highcharts doesn't hide labels when they don't fit treemap point area. As a workaround, you can loop through each data point and check if label related to it is wider. If it is wider just hide it.
Code:
chart: {
type: 'treemap',
width: 500,
events: {
load: function() {
var chart = this,
series = chart.series[0],
pointWidth,
labelWidth;
series.data.forEach(function(point) {
if (point.dataLabel) {
pointWidth = point.shapeArgs.width;
labelWidth = point.dataLabel.width;
if (labelWidth > pointWidth) {
point.dataLabel.hide();
}
}
});
}
}
}
Demo:
https://jsfiddle.net/BlackLabel/h65xm4qb/
API reference:
https://api.highcharts.com/class-reference/Highcharts.SVGElement#hide
I am using Highcharts and would like to combine 2 types of chart.
I would like a Bar with negative stack (changing the chart type to column) combined with Column with negative values so for each category, I have both positive and negative values.
I can't find any example of doing this so I don't even know if this is possible.
I did have a thought about doing something with the series like nested series but again don't know if this is possible and can't find an example.
If what I'm trying to do possible?
Column with negative values
// Age categories
var categories = [
'0-4', '5-9', '10-14', '15-19',
'20-24', '25-29', '30-34', '35-39', '40-44',
'45-49', '50-54', '55-59', '60-64', '65-69',
'70-74', '75-79', '80-84', '85-89', '90-94',
'95-99', '100 + '
];
Highcharts.chart('container', {
chart: {
type: 'bar'
},
title: {
text: 'Population pyramid for Germany, 2015'
},
subtitle: {
text: 'Source: Population Pyramids of the World from 1950 to 2100'
},
xAxis: [{
categories: categories,
reversed: false,
labels: {
step: 1
}
}, { // mirror axis on right side
opposite: true,
reversed: false,
categories: categories,
linkedTo: 0,
labels: {
step: 1
}
}],
yAxis: {
title: {
text: null
},
labels: {
formatter: function () {
return Math.abs(this.value) + '%';
}
}
},
plotOptions: {
series: {
stacking: 'normal'
}
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + ', age ' + this.point.category + '</b><br/>' +
'Population: ' + Highcharts.numberFormat(Math.abs(this.point.y), 0);
}
},
series: [{
name: 'Male',
data: [-2.2, -2.2, -2.3, -2.5, -2.7, -3.1, -3.2,
-3.0, -3.2, -4.3, -4.4, -3.6, -3.1, -2.4,
-2.5, -2.3, -1.2, -0.6, -0.2, -0.0, -0.0]
}, {
name: 'Female',
data: [2.1, 2.0, 2.2, 2.4, 2.6, 3.0, 3.1, 2.9,
3.1, 4.1, 4.3, 3.6, 3.4, 2.6, 2.9, 2.9,
1.8, 1.2, 0.6, 0.1, 0.0]
}]
});
Bar with negative stack
Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'Column chart with negative values'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
credits: {
enabled: false
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
data: [2, -2, -3, 2, 1]
}, {
name: 'Joe',
data: [3, 4, 4, -2, 5]
}]
});
Thanks to #Pawel Fus, I was able to do what I wanted and to remove the duplicate legend labels, I added showInLegend: false, in the series I wanted to hide the legend
Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'Column chart with negative values'
},
colors: Highcharts.getOptions().colors.splice(0, 3),
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
credits: {
enabled: false
},
plotOptions: {
series: {
stacking: true
}
},
series: [{
stack: 'john',
name: 'John',
data: [5, 3, 14, 7, 2]
}, {
stack: 'jane',
name: 'Jane',
data: [2, 12, 3, 2, 1]
}, {
stack: 'joe',
name: 'Joe',
data: [3, 4, 4, 2, 5]
}, {
showInLegend: false,
stack: 'john',
name: 'John',
data: [-5, -3, -4, -7, -2]
}, {
showInLegend: false,
stack: 'jane',
name: 'Jane',
data: [-2, -2, -3, -2, -1]
}, {
showInLegend: false,
stack: 'joe',
name: 'Joe',
data: [-3, -4, -4, -2, -5]
}]
});
I am a total newbie to Highcharts and especially to Javascript. I wonder how to put hyperlinks behind the labels on the y-axis. So far I could not find an answer, neither in the docs nor here. I have something like this:
Highcharts.chart('container', {
chart: {
type: 'bar'
},
title: {
text: ''
},
colors: ['#c83f3f', '#66b257'],
fontFamily: 'Merriweather Sans, sans-serif',
xAxis: {
categories: ['Test 1', 'Test 2', 'Test 3', 'Test 4', 'Test 5', 'Test 6', 'Test 7', 'Test 8']
},
yAxis: {
min: 0,
max: 10,
title: {
text: ''
}
},
legend: {
reversed: true
},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{
name: 'Nicht erfüllte Kriterien',
data: [5, 3, 4, 7, 2, 6, 4, 5]
}, {
name: 'Erfüllte Kriterien',
data: [5, 7, 6, 3, 8, 4, 6, 5]
}]
});
Now I would like to put links to external sites behind the "Test 2", "Test 2" etc. labels. - How would I do that?
Thank you very much!
-Oliver
You can give anchor<a> tags in the categories array of xAxis. With specifying the link in it.like this:
categories: ['<a href="http://stackoverflow.com">Test 2',
'Test 5']
Sample code: I have given links to Test 2 and Test 5 in this sample:
Highcharts.chart('container', {
chart: {
type: 'bar'
},
title: {
text: ''
},
colors: ['#c83f3f', '#66b257'],
fontFamily: 'Merriweather Sans, sans-serif',
xAxis: {
categories: ['Test 1', 'Test 2', 'Test 3', 'Test 4', '<a href="http://stackoverflow.com/questions">Test 5', 'Test 6', 'Test 7', 'Test 8']
},
yAxis: {
min: 0,
max: 10,
title: {
text: ''
}
},
legend: {
reversed: true
},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{
name: 'Nicht erfüllte Kriterien',
data: [5, 3, 4, 7, 2, 6, 4, 5]
}, {
name: 'Erfüllte Kriterien',
data: [5, 7, 6, 3, 8, 4, 6, 5]
}]
});
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>