I am trying to display a custom tooltip using Highcharts. You can find an example of the code here: http://jsfiddle.net/jalbertbowdenii/fDNh9/188/
When you hover over the chart, you can see that the tooltip only contains values from Series 2, but not from Series 1 (which is invisible). When you click on "Series 1" in the legend, you can see the values from Series 1 in the tooltip.
EDIT: no code
to commit, just fixing linkrot/adhering to editing rules...
Is there any way to display the values from an invisible series in a tooltip?
tooltip: {
formatter: function() {
var s = '<b>'+ this.x +'</b>';
var chart = this.points[0].series.chart; //get the chart object
var categories = chart.xAxis[0].categories; //get the categories array
var index = 0;
while(this.x !== categories[index]){index++;} //compute the index of corr y value in each data arrays
$.each(chart.series, function(i, series) { //loop through series array
s += '<br/>'+ series.name +': ' +
series.data[index].y +'m'; //use index to get the y value
});
return s;
},
shared: true
}
The tooltip formatter is a function like any other function so if you just make the data available it can return a string with values for all series. In this example I moved the series arrays and categories to separate variables and the tooltip formatter uses an index into these arrays to find the values.
formatter: function() {
var index = $.inArray(this.x, categories);
var s = '<b>'+ this.x +'</b>';
s += '<br/>'+ chart.series[0].name + ': ' + data1[index];
s += '<br/>'+ chart.series[1].name + ': ' + data2[index];
return s;
}
Another way to go about this is to make certain attributes of the series invisible, rather than the entire series itself. This will allow you to see it in the tooltip and legend.
Here's what I did:
Here's a modified version of your original fiddle with these changes: http://jsfiddle.net/brightmatrix/fDNh9/184/
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
lineColor: 'transparent', // make the line invisible
marker: {
fillColor: 'transparent', // make the line markers invisible
states: {
hover: {
enabled: false // prevent the highlight circle on hover
}
}
}
}, {
data: [216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5]
}]
Two items to note:
enableMouseTracking: false
with other invisible series to prevent users from interacting with them (to achieve visual effects). If you set this for your invisible series, it will prevent the series data from appearing in your tooltip.showInLegend: false
. Its data will still show in the tooltip.I hope this helps others who come across this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With