Highcharts pie tooltip cuts off - highcharts

I am using Highcharts to generate a pie chart. It is generating it fine but the problem is that I have a fixed area to display the chart and the tooltip has large amount of text.
The tooltip is too large to fit inside the chart div, how can I fix this?
$(function () {
var chart;
$(document).ready(function () {
chart = new Highcharts.Chart({
chart: {
renderTo: 'ER_inpatient_stay',
plotBackgroundColor: null,
plotBorderWidth: null,
marginTop: 0,
plotShadow: false,
backgroundColor: 'none',
},
legend: {
layout: 'vertical',
align: 'left',
borderColor: '#fff',
itemMarginTop: 30,
verticalAlign: 'top',
x: 70,
y: 0
},
title: {
text: ''
},
tooltip: {
userHTML: true,
style: {
padding: 10,
width: 250,
height: 60,
},
formatter: function () {
return this.point.residents;
},
},
exporting: {
enabled: false
},
credits: {
enabled: false
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
formatter: function () {
return this.point.y;
},
color: 'white',
distance: -10
},
showInLegend: true,
tooltip: {}
}
},
series: [{
type: 'pie',
size: 80,
name: '',
data: [{
'name': 'E/R Visits',
'y': 1,
'residents': "fMonroe Monroe",
'color': '#FA3D19'
}, {
'name': 'Inpatient Stay',
'y': 21,
'residents': "fGinanni Ginanni, fJobs Jobs, fMonroe Monroe, fDickerson Dickerson, fBrown Brown, fHerter Herter, fDavidson Davidson, fFernbach Fernbach, fGentry Gentry, fJones Jones, fKostic Kostic, fnewresident lnewresident, fLogger Logger, fMaxwell Maxwell, fMcGuire McGuire, fMiller Miller, fO'Farrell O'Farrell, fProgram Program, fProgram2 Program2, frer rer",
'color': 'orange'
}]
}]
});
});
})
Fiddle: http://jsfiddle.net/faridu86/syrF6/

Please take look at the workaournd with using CSS
.highcharts-container {
overflow: visible !important;
}
.tooltip {
position: relative;
z-index: 50;
border: 2px solid rgb(0, 108, 169);
border-radius: 5px;
background-color: #ffffff;
padding: 5px;
font-size: 9pt;
}
http://jsfiddle.net/G4NLn/8/

There's the solution that worked for me, inspired by Sebastian's one :
.highcharts-container,
.highcharts-container svg {
overflow: visible !important;
}
Only takes care of the overflow though, you still need to clip the content of the tooltip.

Issue has been resolved for me, by changing the svg and highchart-container size dynamically as following
$('.highcharts-series-group').mouseover(function(){
setTimeout(function() {
$('.highcharts-tooltip').css({'height': 'auto !important'});
var tspans = $('tspan').length;
var svg_height = 150;
if( (tspans * 16 ) > 150 ){
svg_height = tspans * 16;
}
$('.highcharts-container').css({'height': svg_height+'px'});
$('svg').height(svg_height);
},100);
});
fiddle : http://jsfiddle.net/faridu86/syrF6/2/

I used the answer bellow but its not working for me. The problem for me is the tooltip is coming normally but when the mouse is out the tooltip doesn't dissapear. Here is my solution and it works fine for me. Hope that it will help
$('.highcharts-series-group').mouseenter(function(){
$('.highcharts-tooltip').css({'height': 'auto !important'});
var tspans = $('tspan').length;
var svg_height = 150;
if( (tspans * 16 ) > 150 ){
svg_height = tspans * 16;
}
$('.highcharts-container').css({'height': svg_height+'px'});
$('svg').height(svg_height);
defect_chart.redraw()
});
$('.highcharts-series-group').mouseleave(function(){
defect_chart.tooltip.hide()
});

Related

highcharts x axis categories not updating dynamically vuejs

Below is the highchart application iam working.In mounted i will call axios post that will fetch x axis lables as array.But the x axis categories of highchart is not updating with the given array
Below is the code
<template>
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="container" style="min-width: 100%; max-width:100%; height: 600px; margin: 0 auto"></div>
</div>
</div>
</div>
</template>
<script>
var $ = require('../../node_modules/jquery/dist/jquery.js')
var Highcharts = require('highcharts')
// Load module after Highcharts is loaded
require('highcharts/modules/exporting')(Highcharts)
// Create the chart
$(function () {
Highcharts.chart('container', {
chart: {
marginTop: 120,
marginBottom: 100,
type: 'bar'
},
credits: {enabled: false},
exporting: {enabled: false},
legend: {
enabled: true,
layout: 'vertical',
backgroundColor: '#FFFFFF',
floating: true,
align: 'right',
verticalAlign: 'bottom',
margin: 50,
reversed: true
},
title: {text: null},
tooltip: {},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{
name: 'viewers',
color: '#006666',
pointWidth: 40,
data: [8, 16]
}, {
name: 'calls',
color: '#00FF00',
pointWidth: 40,
data: [7, 14]
}, {
name: 'chats',
color: '#FF8C00',
pointWidth: 40,
data: [8, 16]
}],
xAxis: {
categories: [],
labels: {
overflow: 'right',
display: 'block',
align: 'left',
x: 5,
style: {
fontSize: '1em',
color: '#000',
width: '500px'
}
}
},
yAxis: {
min: 0,
allowDecimals: false,
title: {
text: ''
}
}
})
})
export default {
data () {
return {
}
},
mounted () {
//will fetch labels from db
var arr = ['computers', 'games']
this.catList = arr
}
}
</script>
<style scoped>
.container{
margin: 0 auto;
}
#container{
margin: 0 auto;
min-width: 100%;
padding: 0;
max-width:100%;
height: 400px;
margin: 0 auto;
}
</style>
Please give solution to above problem.
To make categories reactive, you should put Highchart code inside component
Note that in xAxis config, we need to put categories: this.categories
new Vue({
el: '#app',
data() {
return {
chart: null,
categories: []
}
},
mounted() {
this.drawChart()
// example after pull data
var arr = ['computers', 'games']
const vm = this;
setTimeout(function() {
vm.categories = arr
vm.drawChart()
}, 2000)
},
methods: {
drawChart() {
if (this.chart) {
this.chart.destroy();
}
this.chart = Highcharts.chart('container', {
chart: {
marginTop: 120,
marginBottom: 100,
type: 'bar'
},
credits: {
enabled: false
},
exporting: {
enabled: false
},
legend: {
enabled: true,
layout: 'vertical',
backgroundColor: '#FFFFFF',
floating: true,
align: 'right',
verticalAlign: 'bottom',
margin: 50,
reversed: true
},
title: {
text: null
},
tooltip: {},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{
name: 'viewers',
color: '#006666',
pointWidth: 40,
data: [8, 16]
}, {
name: 'calls',
color: '#00FF00',
pointWidth: 40,
data: [7, 14]
}, {
name: 'chats',
color: '#FF8C00',
pointWidth: 40,
data: [8, 16]
}],
xAxis: {
categories: this.categories,
labels: {
overflow: 'right',
display: 'block',
align: 'left',
x: 5,
style: {
fontSize: '1em',
color: '#000',
width: '500px'
}
}
},
yAxis: {
min: 0,
allowDecimals: false,
title: {
text: ''
}
}
})
}
}
})
Working example: https://jsfiddle.net/a9eqd8th/

How to customize a legend in highcharts as the image and while clicking on the leg end appears lines inside linechart

Highcharts.chart('myChart', {
chart:{
backgroundColor: 'transparent',
//polar: true,
height: 615,
type: 'line',
//marginTop: 27 ,
margin: [90, 10, 90, 10]
},
title: {
style: {
display: 'none'
}
},
credits: {
enabled: false
},
exporting: {
enabled: false
},
yAxis: {
tickPixelInterval: 50,
offset: -19,
floor: 0,
ceiling: 100,
gridLineDashStyle: 'dash',
gridLineColor: '#676767',
title: {
text: null
},
labels: {
style: {
color: 'red'
},
y: -8,
x: 0,
format: '{value} %'
},
},
xAxis: {
tickmarkPlacement:'on',
type: 'category',
categories: ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'],
max: 11,
gridLineColor: '#686868',
gridLineWidth: 1,
//offset: 50,
tickLength: 0,
lineColor: 'transparent',
labels: {
style: {
color: 'red'
},
x: 5,
//offset: -50
}
},
legend: {
enabled: false
},
plotOptions: {
series: {
lineWidth: 3,
marker: {
enabled: false
},
label: {
enabled: false
},
states: {
// hover: {
// enabled: true,
// lineWidth: 10
// },
},
events:{
click: function (event) {
lineWidth: 5
//event.point.series.chart.tooltip.refresh(e.point, e)
}
},
}
},
series: [{
name: 'PR',
data: [10,67,88],
color: '#35FEDB',
marker: {
states: {
hover: {
enabled: false
}
}
},
}, {
name: 'PREV',
data: [1, 9,27, 40, 57, 69, 93],
color: '#7EFF75',
marker: {
states: {
hover: {
enabled: false
}
}
},
}, {
name: 'GO',
data: [0, 28, 40, 42, 65, 69, 82],
color: '#EF4556',
marker: {
states: {
hover: {
enabled: false
}
}
},
}, {
name: 'Demo',
data: [0, 30,45, 45, 68, 88, 92],
color: 'white',
marker: {
states: {
hover: {
enabled: false
}
}
},
}],
tooltip: {
shared: false,
useHTML: true,
borderWidth: 0,
backgroundColor:'transparent',
style: {
fontWeight: 'bold',
fontSize: '13px',
padding: 0,
},
formatter: function() {
if (this.series.name == 'PR') {
$('.cyan-tooltip').text('PR '+this.y+'%');
return '<div class="pr-tooltip-head"style="color: black; background: #35FEDB; height: 80px; text-align: center; width: 190px; left: -7px; position: relative; padding: 5px;">' + this.series.name +
'<br/>'+ this.y +'%'+'</div>'
;
}
else if (this.series.name == 'PREV') {
$('.green-tooltip').html('PREVENDAS '+this.y+'%');
return '<div class="prevtooltip-head"style="color: black; background: #7EFF75; height: 80px; text-align: center; width: 190px; left: -7px; position: relative; padding: 5px;">' + this.series.name +
'<br/>'+ this.y +'%'+'</div>'
;
}
else if (this.series.name == 'GOB') {
$('.red-tooltip').html('GO '+this.y+'%');
return '<div class="go-tooltip-head" style="color: $secondary; background: #EF4556; height: 200px; text-align: left; width: 190px; left: -7px; position: relative; padding: 5px;">' + this.series.name +
'<br/>'+'Objetivo\'17'+'<br/>'+ '4.250.000.00'+ '<br/>'+'Objetivo Nov\'17'+'<br/>' + '<span class="seperator"></span><div style="text-align:center">'+ this.y +'%'+'</div>'+'</div>'
;
}
else if (this.series.name == 'Demo') {
return '<div class="demo-tooltip-head"style="color: black; background: $secondary; height: 80px; text-align: center; width: 190px; left: -7px; position: relative; padding: 5px;">' + this.series.name +
'<br/>'+ this.y +'%'+'</div>'
;
}
else return false;
},
},
responsive: {
rules: [{
condition: {
Width: 200
},
}]
}
});
(function (H) {
H.wrap(H.Tooltip.prototype, 'refresh', function (proceed, point, e) {
if (e && e.type !== 'mousemove') {
proceed.call(this, point, e);
}
});
H.addEvent(H.Point.prototype, 'click', function (e) {
e.point.series.chart.tooltip.refresh(e.point, e);
//e.point.series.chart.lineWidth.refresh(10);
});
}(Highcharts));
<div id="myChart"></div>
How to customize a legend in highcharts as given in image.
And place it right to the given line chart
Now I created a line chart using highchart. And it has 3 lines. While loading the chart all lines are visible. And now I want to make:
Invisible each line while clicking on corresponding colors in required legend.That is while clicking on red spot make invisible the red line.
And make visible by clicking again on the red spot.Similarly for rest of lines in the chart.
When red spot is clicked make other spot to see as disabled but not
completely
chart must not be shown empty, minimum accepted 1 line chart
Inside the green region y-axis value to be displayed while hovering green spot after clicking on the green line.Until clicking the line disable the hovering property.This is similar to all other colors
Refer to this live demo: http://jsfiddle.net/kkulig/zp7rjzx3/
I create and configure custom legend in chart.events.load:
chart: {
events: {
load: function() {
// legend box
var div = document.createElement('div');
div.setAttribute('class', 'legend-box');
document.getElementsByClassName('highcharts-container')[0].appendChild(div);
// items
var ul = document.createElement('ul');
ul.setAttribute('class', 'item-list');
div.appendChild(ul);
this.series.forEach(function(s) {
var li = document.createElement('li');
li.setAttribute('class', 'menu-item');
li.style.color = s.color;
ul.appendChild(li);
li.addEventListener('click', function() {
s.setVisible();
});
});
}
}
}
Associated CSS:
#container {
background-color: pink;
width: 600px;
}
.legend-box {
width: 50px;
height: 200px;
background: #455;
position: absolute;
top: 100px;
left: 500px;
border-radius: 25px;
font-size: 30px;
}
.item-list {
margin: 20px 0 0 5px;
}
.menu-item {
margin: 0 0 10px 0;
cursor: pointer
}
setVisible method serves for toggling visibility of a series.
You can easily implement other functionalities using this demo as starting point.
API reference: https://api.highcharts.com/class-reference/Highcharts.Series#setVisible

Highcharts Legend styles no longer rendering correctly

I have had these charts built for a couple months, and just today the styles of the legend seem to have shifted about 150px to the left. They were just right-aligned from the pie chart but now render directly over the top of the pie chart and I am unable to figure out why. I can add inline styles to the div's I am creating with margins and padding but that doesn't justify the colored boxes on the legend that correspond with each pie slice. My code/styles have not changed and I do believe this is a functionality issue. Here is my code;
Any help is appreciated.
var options = {
chart:{type:'pie',
renderTo: 'ctl00_ContentPlaceHolder1_Overview1_AssetCategoryChart',
events: {
load: function(event) {
$('#ctl00_ContentPlaceHolder1_Overview1_AssetCategoryChart .highcharts-legend-item').last().append('<br/><div style="width: 200px; margin-left: 170px; height: 2px;">_____</div><br/><div style="width:200px; height: 10px;"><span style="float:right"><b>100%</b></span> </div>');
}
},
spacingTop: 0,
marginTop: 0
},
credits:{enabled: false},
colors:[
'#5485BC', '#AA8C30', '#5C9384', '#981A37', '#FCB319', '#86A033', '#614931', '#00526F', '#594266', '#cb6828', '#aaaaab', '#a89375'
],
title:{text: null},
tooltip:{
enabled: true,
animation: true,
formatter: function(){
return this.point.name + '<br/>' + this.y.toFixed(2) + '%';
}
},
plotOptions: {
pie: {
allowPointSelect: true,
animation: true,
cursor: 'pointer',
showInLegend: true,
dataLabels: {
enabled: false,
formatter: function() {
return this.y.toFixed(2) + '%';
}
}
}
},
legend: {
enabled: true,
layout: 'vertical',
align: 'right',
width: 200,
verticalAlign: 'top',
borderWidth: 0,
useHTML: true,
itemMarginBottom: 4,
labelFormatter: function() {
return '<div style="width:180px; margin-left: 150px;"><span style="float:left">' + this.name + '</span><span style="float:right">' + this.y.toFixed(2) + '%</span></div>';
},
title: {
text: 'Category',
style: {
fontWeight: 'bold'
}
}
},
series: [{
type: 'pie',
dataLabels:{
},
data: [
['Real Estate', 12.55],
['Large-Cap Growth', 12.34],
['Foreign Large-Cap Blend', 12.19],
['Large-Cap Value', 7.51],
['Emerging Markets', 6.51],
['Health',5.59],
['Cash Equivalents',5.23],
['Foreign Large-Cap Value',4.02],
['Large-Cap Blend',3.95],
['World Allocation',3.55],
['Mid-Cap Growth',3.29],
['Remaining', 23.30]
]
}]
}

Highcharts Tooltip cropping

I am using high charts but am experiencing an issue with larger tooltip cropping off at the outer elements of the SVG, as per the image below.
The option useHTML is set to true for the tooltip and xAxis, as I am applying some custom CSS these elements.
Is there a way to have the tooltip not to crop?
My highcharts code looks like this:
return {
chart: {
renderTo: this._chartContainer,
type: 'columnrange',
inverted: true
},
title: {
text: this._getTitle(values)
},
xAxis: {
categories: values.rows.labels[0],
labels: {
formatter: function() {
return '<span class="xAxisTruncate" title="' + this.value + '">'+ this.value +'</span>';
},
useHTML: true
}
},
yAxis: {
max: this._getMax(),
min: this._getMin(),
gridLineWidth: 2,
opposite: true,
tickInterval: 31 * 24 * 3600 * 1000,
type: 'datetime',
dateTimeLabelFormats: {
month: '%b %y'
},
title: {
text: yAxisTitleText
},
endOnTick: false,
labels: {
align: 'left'
}
},
plotOptions: {
series: {
borderWidth: 0,
borderColor: 'transparent',
borderRadius: 5,
groupPadding: 0.05
},
columnrange: {
dataLabels: {
enabled: true
},
animation: false,
colorByPoint: false
}
},
legend: {
enabled: false
},
series: columnRangeSeries,
tooltip: {
enabled: true,
useHTML: true,
formatter: function(){
return this.point.toolTip;
}
}
};
Thanks in advance.
I'm pretty sure, that similar topic exists on stack, however I can't find it. In general it is possible to achieve that using HTML tooltip, see: http://jsfiddle.net/7wVDV/147/
CSS:
.highcharts-container {
overflow: visible !important;
}
.MyChartTooltip {
position: relative;
z-index: 50;
border: 2px solid rgb(0, 108, 169);
border-radius: 5px;
background-color: #ffffff;
padding: 5px;
font-size: 9pt;
}

Highcharts Donut Chart text in center change on hover

I'm looking for a way to have text in the center of a donut chart change on hover. When there is no hover state, the center will display the total amount (here I am representing vacation days, so it may be 15 vacation days). When hovering, the text in the center needs to match the segment hovered over (available, requested, and taken vacation days), but I cannot figure out how to change the text in the center based on hover. Does anyone have any ideas? Any help is greatly appreciated!!
http://jsfiddle.net/NVX3S/146/
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container1" style="min-width: 300px; height: 300px; margin: 0 auto"></div>
$(function () {
var colors = ['#8d62a0', '#ceb3d8', '#d5dddd'];
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container1',
type: 'pie',
height: 250,
width: 250,
borderRadius: 0
},
credits: {
enabled: false
},
title: false,
tooltip: false,
plotOptions: {
pie: {
borderWidth: 6,
startAngle: 90,
innerSize: '55%',
size: '100%',
shadow: true,
// {
// color: '#000000',
// offsetX: 0,
// offsetY: 2,
// opacity: 0.7,
// width: 3
// },
dataLabels: false,
stickyTracking: false,
states: {
hover: {
enabled: true
}
}
}
},
series: [{
data: [
{y:65, color: colors[0]},
{y:15, color: colors[1]},
{y:20, color: colors[2]}
]
// data: [
// ['Firefox', 44.2],
// ['IE7', 26.6],
// ['IE6', 20],
// ['Chrome', 3.1],
// ['Other', 5.4]
// ]
}]
},
function(chart) { // on complete
var xpos = '50%';
var ypos = '53%';
var circleradius = 102;
// Render the text
chart.renderer.text('126.5', 103, 127).css({
width: circleradius*2,
color: '#4572A7',
fontSize: '16px',
textAlign: 'center'
}).attr({
// why doesn't zIndex get the text in front of the chart?
zIndex: 999
}).add();
});
});
Use points.events.mouseOver/mouseOut, for example: http://jsfiddle.net/NVX3S/147/
Code:
point: {
events: {
mouseOver: function(){
this.series.chart.innerText.attr({text: this.y});
},
mouseOut: function(){
this.series.chart.innerText.attr({text: 112});
}
}
}
Where innerText is just custom property, created like this:
chart.innerText = chart.renderer.text('112', 112, 125).css({ ... }).add();

Resources