In the following example how can i format the tooltip for both series AND flags?
http://jsfiddle.net/gh/get/jquery/1.7.1/highslide-software/highcharts.com/tree/master/samples/stock/plotoptions/flags/
I want to show extra information in series tooltip and other data in flag tooltip.
Use following function as tooltip formatter -
tooltip: {
shared:true,
formatter: function(){
var p = '';
console.log(this);
if(this.point) {
p += '<b>'+ Highcharts.dateFormat('%A, %b %e, %Y', this.point.x) +'</b><br/>';
p += this.point.config.text // This will add the text on the flags
}
else {
p += '<b>'+ Highcharts.dateFormat('%A, %b %e, %Y', this.x) +'</b><br/>';
$.each(this.points, function(i, series){
p += '<span style="color:' + this.series.color + '">' + this.series.name + '</span>: <b>'+ this.y + ' kWh ($' + Highcharts.numberFormat(this.y * rate, 0) + ')</b><br/>';
});
}
return p;
}}
Also refer to this JSFiddle : http://jsfiddle.net/aTcFe/
One way is to create a tooltip formatter that checks if the current object is a point.
tooltip: {
formatter: function(){
if(this.point) {
return "this is a flag"
}
else {
return "this is a line"
}
}
}
You could go one step further and give your flags names and then check if the point has a name (instead of if it just exists) to prevent non-flag points from getting the same format.
Here is your example modified to reflect the former http://jsfiddle.net/aTcFe/
With Highstock 2.1.7 you always get a this.point
object, so you should use this.series.type === 'flags'
to detect whether flags are present or not.
An example would be:
formatter: function () {
if (this.series.type === 'flags') {
// Flags formatting
}
else {
// Default formatting
}
}
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