score:5
Here's one solution I've put together in JSFiddle, although it's a bit of a hack.
Add the following line to the mouseover event:
chart.tooltip.refresh(chart.series[1].points[2]);
This displays the tooltip for an appropriately placed point in a hidden series.
A custom tooltip formatter then returns the required text.
score:2
Another solution would be to use the "label" property of plotBands/plotLines with "useHTML:true" flag and CSS hover.
xAxis: {
//...code
plotLines: [{
//...code
dashStyle: 'Dash',
color: '#000000',
width: 2,
label: {
text: `<div class="plotline">
<div id="custom-tooltip" class="thetooltip">
My custom tooltip!
</div>
</div>`,
useHTML: true,
}
}]
}
Modified CSS would be:
.thetooltip {
display: none; //the main change
border: 1px solid #2f7ed8;
background-color: #fff;
opacity: 0.8500000000000001;
padding: 4px 12px;
border-radius: 3px;
position: absolute;
top:100px;
box-shadow: 1px 1px 3px #666;
}
And of course in plotline class:
.plotline {
&:hover {
.thetooltip {
display: block;
}
}
}
In my opinion, it is a more robust solution - first, it is a CSS solution, not JS, and from the UX/UI point of view works smoother than the quirky JS (just try to set the timeout right!)
score:8
I made another variant based on Gregs answer but for plotlines instead, since that was what I needed. I suppose it would be easily translated to plotBands as well.
This variant also works with events, but instead displays another div instead of relying on a particular hidden series.
The example can be found at JSFiddle.
So the tooltip is added in the same container as the chart
<div id="tooltip" class="thetooltip">
<p id="tooltiptext" style="margin:0">default</p>
</div>
and when the user mouses over a plotline an event is fired which displays the tooltip along with an attached tooltip
var $tooltip = $('#tooltip');
$tooltip.hide();
var $text = $('#tooltiptext');
displayTooltip = function (text, left) {
$text.text(text);
$tooltip.show();
$tooltip.css('left', parseInt(left)+24 + 'px');
};
var timer;
hideTooltip = function (e) {
clearTimeout(timer);
timer = setTimeout(function () {
$tooltip.fadeOut();
}, 5000);
};
And then each plotline is defined with an additional option, tooltipText, and events for displaying the div above.
plotLines: [{
tooltipText: 'hello',
value: Date.UTC(2011, 2, 28, 0, 1, 1),
color: '#ff6666',
dashStyle: 'solid',
width: 3,
events: {
mouseover: function (e) {
displayTooltip(this.options.tooltipText, this.svgElem.d.split(' ')[1]);
},
mouseout: hideTooltip
}
}
the tooltipText is not part of highcharts api, but when defined it is available via the options property on the element.
The css for the tooltip can be defined similar to the default one by highcharts simply by mimicing the css:
.thetooltip {
border: 1px solid #2f7ed8;
background-color: #fff;
opacity: 0.8500000000000001;
padding: 4px 12px;
border-radius: 3px;
position: absolute;
top:100px;
box-shadow: 1px 1px 3px #666;
}
Source: stackoverflow.com
Related Query
- Highcharts + Plotband tooltip hover + default styling
- HighCharts area graph - show tooltip only on hover of marker
- Highcharts - Show tooltip onClick instead of hover
- How to edit tooltip in Highcharts C# code
- highcharts dataLabels support RTL with enable hover it for show tooltip
- how to use highcharts tooltip formatter in python code
- Append to default highcharts tooltip
- highcharts custombutton hover and press changing colors by default
- How to remove default Hover text and display the custom text title on hover Donut chart Highcharts
- Custom hover / tooltip data on highcharts network chart
- How to show tooltip of bars as default in highcharts gantt?
- Highcharts tooltip for single series always centre. Can I force it to be left hover of the marker?
- Highcharts Gantt - Show Tooltip on Dependency Path Hover
- Highcharts solidgauge default tooltip position
- Highcharts - Can we have default and custom tooltip based on different chart types?
- Getting value from tooltip when hover on svg element on the graph created with highcharts
- Highcharts shared tooltip(for line series) - Change on hover ACCORDING TO PLOTBAND
- Highcharts - hover event handling for tooltip throws exception
- customize Highcharts tooltip on marker points and show default tooltip on the other points
- highcharts display tooltip on category label hover
- Disable highcharts tooltip on certain lines, leave it enabled on others?
- How to make highcharts default to 0 for missing data
- Customize tooltip and format the number to 2 decimal places of highcharts
- Disable hover on HighCharts
- Hide line in default state in Highcharts
- Highcharts tooltip overflow is hidden
- customize highcharts tooltip to show datetime
- Highcharts Series - want to show/hide all EXCEPT selected series (reversal of default logic)
- highcharts pass multiple values to tooltip
- Disable tooltip on certain points in Highcharts
More Query from same tag
- I want to use the "layouts: hanging" feature at all levels, but when I do so, I get overlapping nodes and incorrect lines
- Increase the size of one country on a HighCharts map?
- How to connect to end points in two linked series in HighCharts
- Multiple y-axes for column graph categories in highcharts
- Is there limit on the number of data points to plot HighChart
- Want to take difference between single series data and show them on chart in highcharts/highstock
- Show default Drilldown in highcharts
- How to remove decimal values on x-axis of bar chart : Highcharts
- Highcharts How to update all series with ajax
- Highcharts warning: Invalid attribute 'src' in config
- using flask render_template to make a highchart on the front end
- Display time on Xaxis with line chart make by Highcharts
- Highcharts - Identify whether point lies on (within/inside) Chart from X/Y coordinates
- Highcharts: Longer pie labels are chopped off
- How to format data labels with Jquery Highcharttable column charts
- Framework for a Business Dashboard - MVC, browser accessible
- Clickable link in tooltip of Highcharts
- Having issues to make the data value in centre in pie chat using high charts
- Coloring Country while showing mappoint for cities in world map using highmaps
- Highcharts: align markers with xAxis
- Add Offline Export chart capability in Angular-8
- MySQL Timestamp to JavaScript Date not converting correctly
- Highcharts: converting millimeters to pixel
- Highcharts - How to plot a X axis line on my bell curve (Standard Deviation Curve)
- Highcharts / Highstock scroll bar and Zoom issue
- HighCharts display total of stacked column in labels
- highcharts: when adding new data series add new Y axis only if the title is different from existing Y axis
- DotNet.Highcharts Error when using StackLabels
- Highcharts: basic column chart not showing correct color
- JSon with HighCharts and ASP.NET