I've added data labels to a chart and changed the position of data labels by the following way:
Code: Select all
plotOptions: {
candlestick: {
... ,
dataLabels: {
enabled: true,
... ,
formatter() {
const dataMax = this.series.dataMax
const dataMin = this.series.dataMin
if (dataMax === dataMin) {
return
}
const point = this.point
const highestPrice = this.series.points.find((point) => point.high === dataMax)
const lowestPrice = this.series.points.find((point) => point.low === dataMin)
if (point.index === highestPrice.index) {
point.customAlignLabel = point.plotHigh - 20
point.customColor ='red'
return point.high
}
if (point.index === lowestPrice.index) {
point.customAlignLabel = point.plotLow
point.customColor = 'green'
return point.low
}
},
},
},
},
Code: Select all
HighStock.addEvent(HighStock.Series, 'afterDrawDataLabels', function() {
var series = this;
series.points.forEach(function(point) {
if (point.customAlignLabel && point.dataLabel) {
point.dataLabel.attr({
y: point.customAlignLabel
});
point.dataLabel.css({
color: point.customColor
});
delete point.customAlignLabel;
}
});
});
However, I found that data labels sometimes could be almost out of the chart, which means the scale of y axis does not include data labels.
It looks like this: https://drive.google.com/file/d/1a2XuP5 ... sp=sharing
I'm wondering how I can make the scale change according to both data and data labels.
If the information mentioned above is not clear enough, please let me know.
Thank you for your help.
Best regards,