As I delve into the world of D3 charts in HTML, I've noticed that most charts are typically embedded within standard HTML elements such as <div>
, <td>
, and so on.
However, I came across this unique D3 Radial bar Chart that doesn't seem to be encapsulated within a traditional HTML element. I wanted to add a border around it by enclosing it within a DIV
or a table, but I couldn't figure out how to achieve that. The HTML structure appears like this:
<html>
<head>
<title></title>
</head>
<body>
<script>
// This is where the control is drawn
</script>
</body>
</html>
If I were to place it inside a DIV
for styling purposes, how could I possibly accomplish that?
The challenge I'm facing currently is that the chart seems to expand horizontally to occupy the entire width. It behaves as if it's confined within a div that stretches 100% horizontally.
Below is the code snippet in question. Any insights or guidance would be greatly appreciated.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Household monthly electricity consumption</title>
<style>
body {
font: 12px sans-serif;
}
svg {
margin: 0px auto;
display: block;
}
/* Additional styling rules */
...
</style>
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<script>
// JavaScript code for the D3 radial bar chart creation
...
</script>
</body>
</html>