score:1
Highcharts annotations use callout
symbol (Highcharts.SVGRenderer.prototype.symbols.callout
) by default which is not designed for this usage. However, you can modify it so that it fits your needs. Check my wrap posted below and demo with it.
Wrapper on Highcharts.SVGRenderer.prototype.symbols.callout
method:
(function(H) {
H.SVGRenderer.prototype.symbols.callout = function(x, y, w, h, options) {
var arrowLength = 6,
halfDistance = 6,
r = Math.min((options && options.r) || 0, w, h),
safeDistance = r + halfDistance,
anchorX = options && options.anchorX,
anchorY = options && options.anchorY,
path;
path = [
'M', x + r, y,
'L', x + w - r, y, // top side
'C', x + w, y, x + w, y, x + w, y + r, // top-right corner
'L', x + w, y + h - r, // right side
'C', x + w, y + h, x + w, y + h, x + w - r, y + h, // bottom-rgt
'L', x + r, y + h, // bottom side
'C', x, y + h, x, y + h, x, y + h - r, // bottom-left corner
'L', x, y + r, // left side
'C', x, y, x, y, x + r, y // top-left corner
];
// Anchor on right side
if (anchorX && anchorX > w) {
// Chevron
if (
anchorY > y + safeDistance &&
anchorY < y + h - safeDistance
) {
path.splice(13, 3,
'L', x + w, anchorY - halfDistance,
x + w + arrowLength, anchorY,
x + w, anchorY + halfDistance,
x + w, y + h - r
);
// Simple connector
} else {
path.splice(13, 3,
'L', x + w, h / 2,
anchorX, anchorY,
x + w, h / 2,
x + w, y + h - r
);
}
// Anchor on left side
} else if (anchorX && anchorX < 0) {
// Chevron
if (
anchorY > y + safeDistance &&
anchorY < y + h - safeDistance
) {
path.splice(33, 3,
'L', x, anchorY + halfDistance,
x - arrowLength, anchorY,
x, anchorY - halfDistance,
x, y + r
);
// Simple connector
} else {
path.splice(33, 3,
'L', x, h / 2,
anchorX, anchorY,
x, h / 2,
x, y + r
);
}
} else if ( // replace bottom
anchorY &&
anchorY > h &&
anchorX > x + safeDistance &&
anchorX < x + w - safeDistance
) {
path.splice(23, 3,
'L', anchorX + halfDistance, y + h,
anchorX, y + h + arrowLength,
anchorX - halfDistance, y + h,
x + r, y + h
);
} else if ( // replace top
anchorY &&
anchorY < 0 &&
anchorX > x + safeDistance &&
anchorX < x + w - safeDistance
) {
path.splice(3, 3,
'L', anchorX - halfDistance, y,
anchorX, y - arrowLength,
anchorX + halfDistance, y,
w - r, y
);
} else { // add to support right arrows
path.splice(13, 3,
'L', x + w, anchorY - halfDistance,
x + w + arrowLength, anchorY,
x + w, anchorY + halfDistance,
x + w, y + h - r
);
}
return path;
}
})(Highcharts);
Demo:
https://jsfiddle.net/BlackLabel/0eydz6q3/
EDIT
For annotations that are dynamically added, we can use chart.events.render
to get each element dimensions using SVGElement.getBBox()
method and calculate appropriate offsets using particular annotation width and height. Nextly we have to remove the old annotations using chart.removeAnnotations('id')
method and add new ones (with updated distance and x position) using chart.addAnnotations(newOptions)
. Check the demo posted below.
chart: {
events: {
render: function() {
var chart = this,
annotations = chart.annotations[0],
options = annotations.userOptions,
labels = options.labels,
arrowWidth = 6,
bbox;
labels.forEach(function(label, i) {
if (label.point.x === 0) {
bbox = annotations.labels[i].getBBox();
label.point.x = -(bbox.width / 2 + arrowWidth);
label.distance = -bbox.height / 2;
}
});
chart.removeAnnotation('annotations-id');
chart.addAnnotation(options);
}
}
}
Demo:
https://jsfiddle.net/BlackLabel/wf8q1odj/1/
Api reference:
https://api.highcharts.com/class-reference/Highcharts.SVGElement#getBBox
https://api.highcharts.com/class-reference/Highcharts.Chart#removeAnnotation
https://api.highcharts.com/class-reference/Highcharts.Chart#addAnnotation
Source: stackoverflow.com
Related Query
- Highcharts annotations outside the plot area incorrectly placed
- Highcharts - Annotations outside plot area (top/bottom)- doesn't show up
- Highcharts AreaSpline - Adding padding in between the chart and plot area
- Change the plot area colour for HighCharts Swift iOS
- highcharts - Draw horizontal line outside the chart area
- Highcharts Column Chart overflowing the plot area
- Highcharts - Click event not firing outside of plot area
- Highcharts - Place the y-axis plot-line label outside the chart area
- Highcharts annotation outside plot area not working
- how to customize heatmap highcharts plot area and the color of the datalabels
- How to extend plot line value outside the grey area or outside the chart in highchart?
- How would I add a padding to the plot area in HighCharts (HighStock) to pad the border?
- Highcharts showing points on hovering over the line which are outside the chart area when the chart is zoomed in
- Highcharts area fillOpacity do not work when changing the color
- Highcharts - Legend Positioning outside the chart
- Add a gap between the second and third series in a Highcharts column plot with four series displayed
- Highcharts - multiple plot with the same x scale
- Highcharts - Bar - Setting the X axis width and the chart area width to be constant
- Highcharts Area Range Plot in rCharts
- Highcharts - areaspline with negative values, area should be always at the bottom
- Highcharts datalabels outside of plot area?
- DataLabels in Highcharts are outside the container / not showing
- Highcharts change the line color if its out of the area range
- Highcharts visualizes chart data incorrectly after zooming or using the navigator
- how to display 2 same highcharts without duplicate the code
- HighCharts range area plot not working when plot is inverted
- Highcharts legend is overlapping on to the graph area
- plot area width and height in HighCharts
- Highcharts - Different Marker for Each Point of Area Plot
- Highcharts specify height of plot area only
More Query from same tag
- how to improve highcharts scatter 3d performance
- Cannot display name with special character in highchart
- SCRIPT87: Invalid argument In IE8 Using HighCharts v3.0.5
- ReactDOM.render into a <div> does not immediately produce HTML
- Highcharts bubble chart with date?
- Highcharts 3 like menu button won't display
- Add Y axis to highchart dynamically at bottom of the 1st chart without reducing the size of the previous chart
- Highcharts - yAxis dissapears, when zooming in to area with unknown values
- How to set default range selected on chart draw in Highcharts/Highstock
- How to set a different value on opposite y-axis in bar-negative high charts
- How to keep x-axis max value not changed in Highcharts?
- Changing a pie chart into an arrow ring chart
- Highmaps logo string rendering invalid copyright character
- Highcharts: align markers with xAxis
- Getting a django view python dict into highcharts series data
- How can I hide non-selected series and axes when using XY zoom with highcharts?
- How to fill data dynamically in Highchart
- highstocks hozontal line won't draw
- Angular 7 High Charts Stock Chart Datetime X Axis tooltip formatting independently of other tooltips
- Server-side rendering with Highcharts in C#
- WebPack and Require
- How to interpret Timelien for HighStock
- how to show specific tick value on highchart gauge?
- Calling Reset Zoom manually
- Different axis per category
- Highstock Angular value in legend
- HighChart 'tooltip' object is not found on the very next line in IE8
- Highcharts: To rotate the chart 90 degree but also redraw it
- not able to get refs on addEventListener callback function
- axis.extremes.userMin & userMax undefined on redraw with multiple charts