I have created an annotation with a label (see jsfiddle).
<html>
<head>
<title>test chart</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chartjs-plugin-annotation.min.js"></script>
</head>
<body onload="initChart()">
Chart:<br>
<canvas id=chartCanvas>
</canvas>
</body>
</html>
and
let data = {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
type: 'line',
label: 'Dataset 1',
borderColor: 'rgb(54, 162, 235)',
borderWidth: 2,
fill: false,
data: [10, 5, 40, 15, 30, 30, 48]
}]
};
let myAnnotation = {
type: 'line',
mode: 'vertical',
scaleID: 'x',
value: 3,
endValue: 3,
borderColor: 'rgb(75, 192, 192)',
borderWidth: 2,
borderDash: [20, 10],
label: {
position: 25,
display: true,
content: ["Special", "Date"],
rotation: -90,
color: 'red'
},
enter( { element }, event) {
element.label.options.content = ["Display the Tip"];
element.label.rotation = 0; // or even -90
return true; // force update
},
leave( { element }, event) {
element.label.options.content = name;
element.label.rotation = -90;
return true;
}
}
let config = {
type: 'line',
data,
options: {
plugins: {
annotation: {
annotations: {
myAnnotation
}
}
}
}
};
function initChart() {
var ctx = document.getElementById("chartCanvas").getContext("2d");
let myChart = new Chart(ctx, config)
return;
}
What I want to do is be able to hover over the label, and it change to another string, preferably horizontally displayed.
Mostly it works, but when the "enter" event is triggered, the textbox and orientation changes, but the size of the label box doesn't, so the text extends outside the boundary of the box.
How can I get the box to resize appropriately?