Well, that's the easy approach one. If fulfill your needs, that's okay just styling with the css.
But, probably you'll find that <rect>
elements has blank spaces between.
So, to cover up all the area just add a new <rect>
element to functioning as styling the background.
Check out the example below:
EDIT(03/12/19): Implemented new background
option since v1.11.0
. Checkout the Demo.
EDIT: The simple way:
1) Just fill the color for event <rect> elements, but in this case you will have blank spaced area in left & right.
.bb-event-rects .bb-event-rect {
fill: cyan;
}
2) Or simply use 'regions' option
bb.generate({
...
regions: [{ axis: "x" }],
.bb-region {fill: cyan; }
var chart = bb.generate({
data: {
columns: [
["data1", 30, 20, -5, 40, 15, 25],
["data2", 3, 10, 20, 10, 25, 15]
]
},
oninit: function() {
this.svg.select("g.bb-event-rects").insert("rect")
.attr("width", "100%")
.attr("height", "100%")
.attr("class", "myBgColor");
}
});
.myBgColor {
fill: cyan;
fill-opacity: 1;
}
<!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>billboard.js</title>
</head>
<body>
<div id="chart"></div>
</body>
</html>