html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>D3.js Bar and Line Chart</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="chart-container"></div>
<script src="https://d3js.org/d3.v7.min.js"></script>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
body {
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//Created by MBanski
document.addEventListener("DOMContentLoaded", function () {
// Data
const d3ChartData = [
{ category: 'A', values: 20, metric1: 10 },
{ category: 'B', values: 30, metric1: 15 },
{ category: 'C', values: 40, metric1: 20 },
{ category: 'D', values: 50, metric1: 25 },
{ category: 'E', values: 60, metric1: 30 }
];
// Chart dimensions
const width = 300;
const height = 300;
// Create SVG container
const svg = d3.select("#chart-container")
.append("svg")
.attr("width", width)
.attr("height", height);
// Create scales
const xScale = d3.scaleBand()
.domain(d3ChartData.map(d => d.category))
.range([0, width])
.padding(0.1);
const yScale = d3.scaleLinear()
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run