Highcharts - Small column not clickable when covered with a (sp)line serie - highcharts

We are using Highcharts to display data in column series combined with some spline series. All columns are clickable (to perform a drilldown) but some columns become unclickable because they are somewhat small and are entirely covered by the mouse tracking layer of the spline series.
It can be solved partially by disabling the mouse tracking in the spline series, but then the tooltip is not available for that series, and we need that.
What we need is that the column should be clickable through the mouse tracking layer of the spline series.
I've put an example on JS-fiddle to demonstrate the issue.
events: {
click: function ()
{
alert('I\'m Jane');
}
}
In this example, all 'Jane' columns are clickable, except for the second one (oranges) because it's too small and get's covered by the invisible mouseTracking layer of the spline series
Any suggestions?

As you mentionned, you need to disable the moustracking event for the spline series.
To retrieve all series in the tooltip you can use the following code:
tooltip: {
useHTML: true,
formatter: function () {
var s = '';
s += '<table style="border-style: hidden;border-collapse: collapse;">';
//get the chart object
var chart = this.points[0].series.chart;
//get the categories array
var categories = chart.xAxis[0].categories;
var index = 0;
//compute the index of corr y value in each data arrays
while (this.x !== categories[index]) { index++; }
//loop through series array
$.each(chart.series, function (i, series) {
s += '<tr><td style="color:' + series.color + '">' + series.name + ':</td>';
s += '<td style="text-align:right;color:' + series.color + '">';
s += series.data[index].y.toFixed();
s += '</td></tr>';
});
s += "</table>";
return s;
},
shared: true
}

Related

In Highcharts, how do I make my piechart label text the same color as the pie part?

I am using the latest version (9.3.2) of Highcharts as for now.
And I would like to know whether it is possible to make the text color of the two labels the same as the related pie has.
I didn't set any color in the settings and I believe it's a default color value created by highcharts itself.
You can use dataLabels.formatter function and define color for the data label as the same as for the point.
series: [{
...,
dataLabels: {
formatter: function() {
const point = this.point;
return '<span style="color: ' + point.color + '">' +
point.name + ': ' + point.y + '%</span>';
}
}
}]
Live demo: http://jsfiddle.net/BlackLabel/qnjevg7c/
API Reference: https://api.highcharts.com/highcharts/series.pie.dataLabels.formatter

Highcharts: closest point on chart gets highlights and shows tooltip instead of the point where mouse in pointing

I am running into an issue of incorrect point's tooltip on synchronised charts. On the synchronised charts the crosshair is shown and using ordinal:false I am plotting equidistance ticks.
The issue occurs when the crosshair moves along with mouse-move and shows the nearest point's data on the tooltip.
The expected behaviour is: when there is no data, crosshair should be shown but not the tooltip.
here is an existing SO fiddle I found https://jsfiddle.net/jknipp/g3vr5v44/13/
To achieve the effect you need, just return false if window.isOutOfSync, instead of No data string here:
formatter: function(tooltip) {
var header,
s = [];
console.log(window.isOutOfSync);
if (window.isOutOfSync) {
console.log("don't show tooltip");
//return false;
console.log(this)
return false;
}
$.each(this.points, function(i, point) {
// check to see if the point is in the overall graph
//var overallChart = $("#total_success_rates").highcharts();
//console.log(overallChart);
var isSuccessRate = (point.series.name == 'Success');
if (header == null) {
var config = point.point.getLabelConfig();
header = tooltip.tooltipFooterHeaderFormatter(config);
}
s.push(formatSuccessRateToolTip(point.y, isSuccessRate));
// $("#" + point.series.name.toLowerCase() + "-rate").html(point.y + "%");
});
return header + s.reverse().join('<br>');
}
[EDIT]
Additionally, please call reflow() inside of the chart.events.load function on both charts, just like below:
chart: {
renderTo: container,
type: 'areaspline',
events: {
load() {
this.reflow()
}
},
height: '220',
spacingBottom: 20,
spacingTop: 20,
spacingLeft: 20,
spacingRight: 20
},
Live example: https://jsfiddle.net/27veyw1d/

Highcharts make pie chart show 0 data

When I have the following data supplied to Pie chart: [[0],[0],[0]], the chart is empty.
However, I want to make the pie show three slices, with each percentage distribution equal to 33.3%
I know it is better to use bar / column chart in this case, however I have this edge case where I need to show 0 data in Pie chart
Workaround:
Set some nonzero value and add isZero flag for every point. Then use this flag in tooltip.pointFormatter:
tooltip: {
pointFormatter: function() {
return "<span style='color:" + this.color + "'>\u25CF</span>" + this.series.name + ": <b>" + (this.options.isZero ? 0 : this.y) + "</b><br/>";
}
}
This will cause that your points will be visible and 0 will be printed in tooltip if the hovered point has isZero flag set to true.
Live demo: http://jsfiddle.net/BlackLabel/52a1xh99/

How to plot horizontal lines over the some columns of columnrange chart in Highcharts

I am working on a columnrange graph in Highcharts where I plot different measurements and confidence intervals in the same plot:
The first few columns inside a group (e.g. Januar) represent measurements for different cities, while the last column represent confidence intervals. I would like to add horizontal lines to the confidence intervals representing the data means. That is, each orange column would get its own line at a specific heigh going from the left to the right side of the orange rectangle. How do I plot such lines?
I know how to add lines as a separate series of type line. However, doing so, I'm not sure how to guess the exact location of orange column and also I do not know how to handle cases when some columns are hidden through the legend.
This question is related to this question though I am not able to get any of that solutions to work in my case.
Here is the fiddle: https://jsfiddle.net/nikicc/rqxqm4hm/
You can use renderer.path to draw proper lines.
function drawDataMeans() {
const intervalSeries = this.get('conf-interval'),
series = this.series.filter(series => intervalSeries !== series)
let lines = this.dataMeansLines
if (!lines) {
lines = this.dataMeansLines = series[0].data.map(series => this.renderer.path().attr({
'stroke-width': 2,
stroke: 'black'
}).add(intervalSeries.group))
}
const visibleSeries = series.filter(series => series.visible)
if (intervalSeries.visible && visibleSeries.length) {
intervalSeries.data.forEach((point, i) => {
const mean = visibleSeries.reduce((sum, series) => sum + series.data[i].high, 0) / visibleSeries.length
const {x, width} = point.shapeArgs
const y = this.yAxis[0].toPixels(mean, true)
lines[i].attr({
d: `M ${x} ${y} L ${x + width} ${y}`,
visibility: 'visible'
})
})
} else {
lines.forEach(line => line.attr({visibility: 'hidden'}))
}
}
Hook on load/redraw events
chart: {
type: 'columnrange',
inverted: false,
events: {
load: drawDataMeans,
redraw: drawDataMeans
}
},
example: https://jsfiddle.net/dq48sq3w/

Add tooltip to legend in highcharts when hovering

Id like to let the user know that he can remove items from the legend by simply clicking on them. To some, this may be intuitive but others may not know that they can do that. I would like to let the users know when they over the legend item that then can click to remove it.
I am using the GWT-wrapper class for highcharts.
Thank you.
Highcharts doesn't have built-in tooltip for item legend, but still you can create your own tooltip for that. It's simple to add custom events to legendItem (mouseover and mouseout for example) and show that tooltip.
See example how to add events to elements in Highcharts: http://jsfiddle.net/rAsRP/129/
events: {
load: function () {
var chart = this,
legend = chart.legend;
for (var i = 0, len = legend.allItems.length; i < len; i++) {
(function(i) {
var item = legend.allItems[i].legendItem;
item.on('mouseover', function (e) {
//show custom tooltip here
console.log("mouseover" + i);
}).on('mouseout', function (e) {
//hide tooltip
console.log("mouseout" + i);
});
})(i);
}
}
}
There is another opportunity to get tooltips at hovering over the Highcharts legend. You just need to enable useHTML for the legend and redefine the labelFormatter function; this function should return the label text enclosed into the "span" tag. In this "span" tag one may include a class to apply jQuery-based tooltips (jQuery UI or Bootstrap for example). Also it is possible to transfer some data (for example, the index of a legend item) using the 'data-xxx' attribute:
labelFormatter: function () {
return '<span class="abc" data-index="' + this.index + '">' + this.name + '</span>';
}
Tooltips can be formatted as you wish; hyperlinks are also possible. The fiddle is here.
Although there're great answers already, I still want to share my simplified solution (inspired by the answers provided above).
If you just need a plain text tooltip, you can use title attribute of <span> (W3 School, title attribute - most often shown as a tooltip text when the mouse moves over the element.) No jQuery setup is needed then.
In your Highcharts options object set legend.useHTML: true & configure legend.labelFormatter:
legend: {
enabled: true,
useHTML: true,
labelFormatter: function () {
// if legendTooltip set, put it into title attr
if (this.options.custom && this.options.custom.legendTooltip) {
return '<span title="' + this.options.custom.legendTooltip + '">' + this.name + '</span>';
}
return '<span>' + this.name + '</span>';
}
},
And add custom.legendTooltip to the options object of a series you want a tooltip for:
series: [{
name: 'counter',
data: [110, 50, 130],
custom: {
// provide a tooltip text here:
legendTooltip: "Counter custom tooltip"
}
}]
(using custom obj is recommended by Highcharts)
Also see the JS fiddle: http://jsfiddle.net/uhocybpj/8/
You can do that.
At first, Highcharts has callback function.
https://stackoverflow.com/a/16191017
And modified version Tipsy can show tooltip in SVG.
http://bl.ocks.org/ilyabo/1373263
*Use jquery.tipsy.js and tipsy.css on this page.
Then, start highcharts like this.
$('#your-chart').highcharts(your_chart_options,function(chart){
$('#your-chart').find('.highcharts-legend-item').each(function(){
// set title text example
var _text = $(this).text(),
_title = '';
switch(_text){
case "legend 1":
_title = 'legend 1 title';
break;
case "legend 2":
_title = 'legend 2 title';
break;
}
// add <title> tag to legend item
$(this).append($('<title></title>').text(_title));
});
$('#your-chart').find(".highcharts-legend-item").tipsy({
gravity: 's',
fade: true
})
});

Resources