var chart = bb.generate({
data: {
columns: [
["sample", 30, 200, 100, 400, 150, 250],
["sample2", 1300, 1200, 1100, 1400, 1500, 1250]
],
axes: {
sample2: "y2"
}
},
axis: {
y2: {
show: true
}
},
grid: {
y: {
lines: [
{
value: 50,
text: "Label with some bublly background"
},
{
value: 1300,
text: "Label 1300 for bubbly style",
axis: "y2",
position: "start"
},
{
value: 350,
text: "Label 350 for y",
position: "middle"
}
]
}
},
bindto: "#OptionalYGridLines"
});
function addBackground() {
const index = document.querySelector("#index").value;
const grid = chart.internal.main.select(`.bb-ygrid-line:nth-child(${index})`);
const text = grid.select("text").node().getBBox();
grid.insert("rect", "text")
.attr("width", text.width)
.attr("height", text.height)
.attr("x", text.x)
.attr("y", text.y)
.style("fill", "#38ff00");
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/billboard.js/dist/billboard.min.css" />
<script src="https://cdn.jsdelivr.net/npm/billboard.js/dist/billboard.pkgd.min.js"></script>
<title>JS Bin</title>
</head>
<body>
<div id="OptionalYGridLines"></div>
<input type="number" id="index" style="width:40px" value=3>
<button onclick="addBackground()">Add background</button>
</body>
</html>