我正在为学校作业制作数据可视化。我有很多不同大小的圆形div元素。它们可以让它们彼此相邻吗?现在我用float:left;但是然后div元素在1行,如果一个更大,则有一个空格。
网页:http://i290808.iris.fhict.nl/dv3/
1圈HTML示例:
<div class="circle" style="height: 200px; width: 200px; border: 15px solid rgb(255, 141, 0); background-image: url('http://zapp.trakt.us/images/episodes/9635-4-11.jpg?17'); background-size: cover;">
<div class="circle" style="height: 100%; background-color:rgba(255, 146, 0, 0.4)">
<h2 style="font-size: 25px">New Girl</h2>
</div>
</div>
(此HTML元素中有样式元素,因为我需要在PHP文件中更改此信息)
CSS文件:
.circle {
border-radius: 100%;
display: table;
float: left;
}
h2 {
color: #FFF;
text-align: center;
vertical-align: middle;
display: table-cell;
}
答案 0 :(得分:1)
更改以下规则。
h2 {
color: #FFF;
text-align: center;
vertical-align: middle;
transform: translateY(-50%);
margin-top: 50%;
word-wrap: break-word;
}
.circle {
border-radius: 100%;
display: inline-block;
vertical-align: middle;
}
此外,要将.circles
horion中心地将所有.circles
包裹在#container
div中,并为其提供以下规则。
#container {
width: 95%;
margin: 0px auto;
text-align: center;
}
结果如下。
答案 1 :(得分:0)
使用d3.js的气泡图最适合您的需求。
这是一个有效的代码段:
var data = {
"name": "animate",
"children": [
{"name": "Easing", "size": 17010},
{"name": "FunctionSequence", "size": 5842},
{
"name": "interpolate",
"children": [
{"name": "ArrayInterpolator", "size": 1983},
{"name": "ColorInterpolator", "size": 2047},
{"name": "DateInterpolator", "size": 1375},
{"name": "Interpolator", "size": 8746},
{"name": "MatrixInterpolator", "size": 2202},
{"name": "NumberInterpolator", "size": 1382},
{"name": "ObjectInterpolator", "size": 1629},
{"name": "PointInterpolator", "size": 1675},
{"name": "RectangleInterpolator", "size": 2042}
]
},
{"name": "ISchedulable", "size": 1041},
{"name": "Parallel", "size": 5176},
{"name": "Pause", "size": 449},
{"name": "Scheduler", "size": 5593},
{"name": "Sequence", "size": 5534},
{"name": "Transition", "size": 9201},
{"name": "Transitioner", "size": 19975},
{"name": "TransitionEvent", "size": 1116},
{"name": "Tween", "size": 6006}
]
};
var diameter = 960,
format = d3.format(",d"),
color = d3.scale.category20c();
var bubble = d3.layout.pack()
.sort(null)
.size([diameter, diameter])
.padding(1.5);
var svg = d3.select("body").append("svg")
.attr("width", diameter)
.attr("height", diameter)
.attr("class", "bubble");
//d3.json("flare.json", function(error, root) {
var node = svg.selectAll(".node")
.data(bubble.nodes(classes(data))
.filter(function(d) { return !d.children; }))
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
node.append("title")
.text(function(d) { return d.className + ": " + format(d.value); });
node.append("circle")
.attr("r", function(d) { return d.r; })
.style("fill", function(d) { return color(d.packageName); });
node.append("text")
.attr("dy", ".3em")
.style("text-anchor", "middle")
.text(function(d) { return d.className.substring(0, d.r / 3); });
//});
// Returns a flattened hierarchy containing all leaf nodes under the root.
function classes(data) {
var classes = [];
function recurse(name, node) {
if (node.children) node.children.forEach(function(child) { recurse(node.name, child); });
else classes.push({packageName: name, className: node.name, value: node.size});
}
recurse(null, data);
return {children: classes};
}
d3.select(self.frameElement).style("height", diameter + "px");
&#13;
text {
font: 10px sans-serif;
}
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
&#13;
关于将背景图像添加到每个气泡,您可以将相应的路径添加到输入数据中的每个孩子,然后使用d3.js应用它。