Highcharts Legend styles no longer rendering correctly - highcharts

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

Related

Highchart legend customization [duplicate]

I have created a Pie chart and I am placing this Pie chart inside a panel. My panel width can be 600 or 400 depending on the user settings. When the size is 600 Pie and the legend is displayed properly. But when it is 400, the legend is displayed outside of the panel. Is there a way to reduce the size of the pie in that case, also the legend can be displayed at the bottom if the size is not sufficient.
My plnkr
https://plnkr.co/edit/yzXLz7AIDoWa1Pzxxl4k?p=preview
My plot options
plotOptions: {
pie: {
innerSize: 120,
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true,
states: {
hover: {
halo: {
size: 0
}
}
}
}
},
Response code:
responsive: {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
legend: {
align: 'center',
verticalAlign: 'top',
layout: 'horizontal',
labelFormatter: function () {
return '<div style="width:180px"><span class="pull-left" style= "font-weight: 500; padding-bottom: 5px; font-family:Helvetica ">' + this.name +
'</span><span class="pull-right" style= "font-weight: 500" >' + this.value +
'</span></div> ';
}
},
pie: {
size: 100,
innerSize: 40
}
}
}]
}

HighCharts - increase bar height and reduce bar gap

Trying to increase bar height to accommodate series name inside bar and trying to reduce default gap between series group. The section "series: []" is, I assume for the JSON return function to populate. Tried many examples from all the generous JSFiddle examples to no avail. I'm a noob so please be patient. Any ideas? So far I have: http://jsfiddle.net/PeterHanekom/7ue5bkm8/1/
var options = {
chart: {
renderTo: 'container',
type: 'bar'
},
colors: ['#00B9B9', '#527CED', '#A7D36B', '#B9B900', '#0097FF', '#400040', '#EA4D00', '#336699', '#8080C0', '#ADA870'],
title: {
text: 'Cluster Totals',
x: -20 //center
},
subtitle: {
text: 'Dept - Branch',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
min: 0,
max: 100,
title: {
text: 'Percentage'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
align: 'center',
borderWidth: 0
},
plotOptions: {
bar: {
stacking: 'normal',
pointWidth: 20,
pointPadding: 0,
cursor: 'pointer',
point: {
events: {
click: function() {
alert('later drilldown events');
}
}
dataLabels: {
enabled: true,
inside:true,
useHTML: true,
align: 'left',
color: 'white',
style: {
fontWeight: 'bold'
},
verticalAlign: 'middle',
formatter: function () {
if (this.series.name)
return '<span style="color:black; height: 25px;">' + this.series.name + ' = ' + this.y + '</span>';
else return '';
}
}
}
},
series: []
}
$.getJSON("./services/get360Pivot.php?s_Search=" + sOperatorSearch, function(json)
{
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
options.series[1] = json[2];
options.series[2] = json[3];
options.series[3] = json[4];
chart = new Highcharts.Chart(options);
});
I think you options you need are groupPadding and pointWidth. e.g.
groupPadding:0.1,
pointWidth:20,
http://jsfiddle.net/s3t2pL94/

How do you add text to the bottom center of legend and bottom center of chart under legend?

I have a custom HighCharts that have totals in the legend. I need to add one line of custom text centered under the totals "in the legend". Also I need to add text center at the bottom of the chart "under the legend".
See fiddle:
http://jsfiddle.net/no1uknow/cvsTB/
[EDIT]
I did figure this much out but don't know how to get text centered under legend.
http://jsfiddle.net/no1uknow/cvsTB/1/
$(function () {
var chart;
$(document).ready(function() {
var container_chartFreqAtaTailNum = new Highcharts.Chart({
chart: {
renderTo: 'container_chartFreqAtaTailNum',
type: 'bar',
height: 795
},
title: {
text: 'Frequency by Tail Number'
},
subtitle: {
text: 'Fact ATA (25)'
},
xAxis: {
categories: ['235','245','402','411','432','442','493','703','714','720','730','745','756','767','772','792'],
title: {
text: 'Tail Number'
},
labels: {
style: {
width: '12000px'
}
}
},
yAxis: {
min: 0,
title: {
text: 'Count',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
formatter: function() {
return ''+ this.series.name +': '+ this.y +' Count';
}
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
},
series: {
pointWidth:10,
groupPadding: .05,
shadow: true
}
},
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom',
floating: false,
borderWidth: 1,
backgroundColor: '#FFFFFF',
shadow: true,
labelFormatter: function() {
return '<div class="' + this.name + '-arrow"></div><span style="font-family: \'Advent Pro\', sans-serif; font-size:12px">' + this.name +'</span><br/><span style="font-size:10px; color:#ababaa"> Total: ' + this.options.total + '</span>';
}
},
credits: {
enabled: false
},
exporting: {
enabled: true
},
series: [{
name: 'Heavy',
total: '5421',
data: [117,102,698,640,251,115,269,279,260,309,328,427,316,754,239,317]
},{
name: 'Intermediate',
total: '4888',
data: [299,169,448,532,210,256,241,295,226,368,319,420,272,243,313,277]
},{
name: 'Line',
total: '659',
data: [29,38,50,47,33,27,22,67,57,44,36,53,41,37,35,43]
},{
name: 'Lite',
total: '2172',
data: [101,116,139,124,123,139,148,249,168,141,122,136,91,154,105,116]
}]
});
});
});
spacingBottom is what you need to add, and also you need to take care of the offset:
chart: {
events: {
load: function () {
var label = this.renderer.label("How do I move this center and under the legend.")
.css({
width: '450px',
color: '#222',
fontSize: '16px'
})
.attr({
'stroke': 'silver',
'stroke-width': 2,
'r': 5,
'padding': 10
})
.add();
label.align(Highcharts.extend(label.getBBox(), {
align: 'center',
x: 0, // offset
verticalAlign: 'bottom',
y: 50 // set the right offset
}), null, 'spacingBox');
}
},
renderTo: 'container_chartFreqAtaTailNum',
type: 'bar',
height: 895,
spacingBottom: 100 // The space between the bottom edge of the chart and the content (plot area, axis title and labels, title, subtitle or legend in top position).
}
Here is the fiddle: http://jsfiddle.net/uMBHf/1/

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

Change tooltip position where mouse found

I am using highcharts pie chart and needs to change the tooltip position
to where the mouse is on while it's over the chart.
Currently I tried to change it's position but it's not working.
Here is how i tried to create and use the chart:
chartObj = new Highcharts.Chart({
chart: {
renderTo: container,
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
animation: false,
backgroundColor: '#e4e6e1',
height: 300
},
colors: colors,
title: {
text: title
},
tooltip: {
positioner: function (boxWidth, boxHeight, point) {
return { x: point.plotX + this.chart.plotLeft, y: point.plotY + this.chart.plotTop };
},
pointFormat: '<b>{point.percentage}%</b>',
percentageDecimals: 1,
style: {
color: '#333333',
fontSize: '12px',
padding: '8px',
opacity: 1
}
},
plotOptions: {
pie: {
allowPointSelect: false,
cursor: 'pointer',
dataLabels: {
enabled: width < 1500 ? false : true,
color:'#000000',
useHTML: true,
formatter: function () { return this.percentage.toFixed(2) + "%"; },
connectorWidth: 0,
distance: 5
},
showInLegend: true,
color: '#000000',
connectorColor: '#000000',
point: {
events: {
legendItemClick: function () {
return false;
}
}
},
},
},
series: [{ type: 'pie',
name: title,
visible: chart_visible,
data: data,
}],
credits: {
enabled: false
},
legend: {
layout: 'horizontal',
backgroundColor: '#FFFFFF',
align: 'center',
verticalAlign: 'bottom',
x: 0,
y: 0,
floating: false,
shadow: true
},
exporting: {
enabled: false
}
});
chartObj.series[0].setData(data);
return chartObj;
Unfortunately point.x and point.y are always the same for pie slice - they are not mouse position.
Possible workaroud is to use points.event.mouseOver and mouseOut and create your own tooltip (display some absolute with values from that event).

Resources