-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-activity-chart2.html
More file actions
79 lines (69 loc) · 2.63 KB
/
github-activity-chart2.html
File metadata and controls
79 lines (69 loc) · 2.63 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<html>
<head>
<style>
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.dot {
stroke: #000;
stroke-width: 2px;
}
</style>
</head>
<body>
<div id="chart"></div>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script>
const data = [
{ x: 10, y: 20, type: 'Commits' },
{ x: 20, y: 10, type: 'Issues' },
{ x: 30, y: 15, type: 'Pull requests' },
{ x: 40, y: 25, type: 'Code review' },
];
const margin = { top: 20, right: 20, bottom: 30, left: 40 },
width = 600 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
const xScale = d3.scaleLinear()
.domain([0, d3.max(data, d => d.x)])
.range([0, width]);
const yScale = d3.scaleLinear()
.domain([0, d3.max(data, d => d.y)])
.range([height, 0]);
const svg = d3.select('#chart')
.append('svg')
.attr('width', width + margin.left + margin.right)
.attr('height', height + margin.top + margin.bottom)
.append('g')
.attr('transform', `translate(${margin.left},${margin.top})`);
// Add a group for each data point
const points = svg.selectAll('.point')
.data(data)
.enter()
.append('g')
.attr('class', 'point');
// Add a circle for each data point
points.append('circle')
.attr('cx', d => xScale(d.x))
.attr('cy', d => yScale(d.y))
.attr('r', 5)
.attr('class', 'dot');
// Add a label for each data point
points.append('text')
.text(d => d.type)
.attr('x', d => xScale(d.x) + 10)
.attr('y', d => yScale(d.y) + 5)
.style('font-size', '10px');
// Append the x-axis to the chart
svg.append('g')
.attr('class', 'x axis')
.attr('transform', `translate(0,${height})`)
.call(d3.axisBottom(xScale));
// Append the y-axis to the chart
svg.append('g')
.attr('class', 'y axis')
.call(d3.axisLeft(yScale));
</script>
</body>
</html>