I have this stacked column chart. Demo
tooltip: {
formatter: function() {
return '<b>'+ this.x +'</b><br/>'+
this.series.name +': '+ this.y +'<br/>'+
'Total: '+ this.point.stackTotal;
}
},
I want when I hover the first column, it should display:
John: 3
Bob: 5
Total: 8
whatever the stack I hover on the same column, it should display 3 those values.
How to do that? My solution I've thought is get (this.total - this.y) but it doesn't show correct value.
The normal way to show the values in the stack is to define your tooltip as follows:
tooltip:
{
shared:true
},
http://jsfiddle.net/RG8YT/
I'm not sure if this is good enough for what you want, as in your chart, that shows all the values, not just the ones in the stack.
There is a question here: highchart total in tooltip about adding totals to a shared tooltip.
In case when you would like to sum only in "part of stack", I mean left / right, you can sum elements partially.
var indexS = this.series.index,
indexP = this.point.x,
series = this.series.chart.series,
out;
out = '<b>'+ this.x +'</b><br/>'+
this.series.name +': '+ this.y +'<br/>';
switch(indexS) {
case 0:
out += series[1].name + ': ' + series[1].data[indexP].y + '<br/>';
break;
case 1:
out += series[0].name + ': ' + series[0].data[indexP].y + '<br/>'; break;
case 2:
out += series[3].name + ': ' + series[3].data[indexP].y + '<br/>';
break;
case 3:
out += series[2].name + ': ' + series[2].data[indexP].y + '<br/>';
break;
}
out += 'Total: '+ this.point.stackTotal;
return out
http://jsfiddle.net/sbochan/3Utat/7/
Related
I got some problem with Highcharts transition between 9.x and 10.x version. I can't get color of series inside function in tooltip formatter.
tooltip: {
formatter: function () {
return this.points.reduce(function (s, point) {
return s + '<br/>' + "<span style='color:" + point.series.color + "'>\u25CF</span> " + point.series.name + ': ' +
point.y + 'm';
}, '<b>' + this.x + '</b>');
},
...
This is related to Belchertown weewx's skin issue.
Please have a look to that FIDDLE
Thanks.
Onza
Thank you for reporting this behaviour! I've created a github issue, that you can track here: https://github.com/highcharts/highcharts/issues/17627
Use another quotation marks configuration to achieve the correct tooltip format:
formatter: function () {
return this.points.reduce(function (s, point) {
return s + '<br/>' + '<span style="color:' + point.series.color + '">\u25CF</span>' + point.series.name + ': ' +
point.y + 'm';
}, '<b>' + this.x + '</b>');
},
Demo:
https://jsfiddle.net/BlackLabel/a2uLhdys/
Highcharts: I have a shared tooltip with 3 default bullets. I need to add custom information to the 3rd bullet (or series).
I need Bullet C to show its default value, but also show what percentage it is of Bullet B. In the screenshot below, Bullet C would say: "Good Condition: 3,448 (32% of Assessed).
My question is 2 parts:
How do I customize only the third bullet tooltip?
How do I find out what percentage of Bullet B is represented by Bullet C? (in my example, 3,448 is 32% of 10,697, but how do i find that using highcharts?)
Update: This code formats the bullet and partially answers my first question (except it's missing the comma for thousands format):
return '<span style="color:' + this.series.color + '">● </span>' + this.series.name + ':<b>' + this.y + '</b><br/>';
You can define individual tooltip options for a series, in your case you need to use pointFormatter function, for example:
series: [..., {
...,
tooltip: {
pointFormatter: function() {
var series = this.series.chart.series,
percentage = Highcharts.numberFormat(
this.y / series[1].points[this.index].y * 100,
2
);
return '<span style="color:' +
this.color + '">●</span> ' +
this.series.name + ': <b>' +
Highcharts.numberFormat(this.y, 0) +
'</b> Percentage: ' + percentage + '%<br/>'
}
}
}]
Live demo: http://jsfiddle.net/BlackLabel/6m4e8x0y/4955/
API Reference:
https://api.highcharts.com/highcharts/series.column.tooltip
https://api.highcharts.com/class-reference/Highcharts#.numberFormat
How do I make this: https://www.highcharts.com/stock/demo/candlestick-and-volume
with single line series like this:
https://www.highcharts.com/stock/demo/basic-line
Final chart should have single line series with volume
How do I display a single tooltip with the following information:
Date, Time:
Price:
Volume:
You can achieve it by setting tooltip.split = false and using tooltip.formatter callback.
Code:
tooltip: {
split: false,
formatter: function() {
var point = this.point,
chart = point.series.chart,
pointIndex = point.index,
date = Highcharts.dateFormat('%b %e, %H:%M', this.x),
volumePoint = chart.series[1].points[pointIndex],
text =
'<span style="color:' + point.color +
'">\u25CF</span> ' + point.series.name +
': <b>' + point.y + '</b><br/>' +
'<br><span style="color:' + volumePoint.color +
'">\u25CF</span> ' +
'Volume: <b>' + volumePoint.y +
'</b><br>' + date;
return text;
}
}
Demo:
https://jsfiddle.net/BlackLabel/9gq7Lv4r/
API reference:
https://api.highcharts.com/highcharts/tooltip.split
https://api.highcharts.com/highcharts/tooltip.formatter
I have the following highcharts graph
https://jsfiddle.net/deemgfay/
and I am trying to display the "Consum Test" values in the tooltip but without adding them to the series. I just want to add Consum (l/100km)
Total Consum (l) to the series. Is that possible with hightcharts? Please see the screenshot below.
You can set the extra series to be hidden and ignored in legend:
visible: false,
showInLegend: false
Then use tooltip formatter function (useHTML must be enabled) to display points from all series in the shared tooltip regardless of their visibility:
formatter: function() {
var html,
originalPoint = this.points[0];
// header
html = "<span style='font-size: 10px'>" + originalPoint.x + "</span><br/>";
// points
originalPoint.series.chart.series.forEach(function(series) {
var point = series.points.find((p) => p.x === originalPoint.point.x);
html += "<span style='color: " + series.color + "'>\u25CF</span> " + series.name + ": <b>" + point.y + "</b><br/>"
});
return html;
}
Live demo: https://jsfiddle.net/kkulig/1oggzsx0/
API references:
http://api.highcharts.com/highcharts/tooltip.formatter
http://api.highcharts.com/highcharts/tooltip.useHTML
This can be done by using tooltip.formatter. Here I append to tooltip info based on index of current series from index of required extra array.
formatter: function() {
var s = '<b>' + this.x + '</b>';
var reqpoint = 0;
$.each(this.points, function() {
var reqpoint = this.point.index
s += '<br/>' + this.series.name + ': ' +
this.y.toFixed(2) + 'm';
if (this.series.index == 1) {
s += '<br/>Test Consum (l): ' + extraData[reqpoint] + 'm';
}
});
return s;
},
Fiddle demo
I have a series of points under a single series and I want the tooltip to display all the points in the series but my tooltip displays the top and bottom points selected and does not display the remaining points through the tool tip.How to fix this ?
http://jsfiddle.net/#&togetherjs=7IfUNtFkAE
In the above fiddle,I have the tooltip displaying values for the top and bottom points for apple series ,hovered over in the fiddle.How will i make it such that middle points are also displayed when i hover over them ?
As Paweł Fus pointed out in the comment, the data is not well prepared for highcharts.
So I have converted it from basic line chart to Scatter plot with line.
Scatter plot with line
http://jsfiddle.net/S8wzF/1/ OR http://jsfiddle.net/S8wzF/2/
Reference:
http://www.highcharts.com/demo/scatter
http://www.highcharts.com/demo/combo-regression
Original fiddle with highcharts usage issues
Add useHTML for tooltip when HTML formatting is in use.
shared is not needed and thus return statement of formatter is modified accordingly.
tooltip: {
useHTML: true,
formatter: function () {
return '<b>' + this.x + '</b><br/>' + 'fruit_id' + ': ' + this.point.fruit_id + '<br/>' + 'Values' + ': ' + this.point.y + '<br/>' + 'Mean' + ': ' + this.point.mean + '<br/>' + 'Median' + ': ' + this.point.median + '<br/>' + 'Min' + ': ' + this.point.min + '<br/>' + 'Max' + ': ' + this.point.max + '<br/>'
}
}
Original code contains Javascript problems (Unrelated to highcharts)
The series add data incorrectly as it is inside the loop.
Put this segment of code outside "for loop".
series.push({
data: data,
type: 'line',
color: '#000',
marker: {
symbol: 'circle'
},
showInLegend: false
});