D3.js 如何在直线路径中创建D3气泡图?
我想创建一个气泡图,如图中所示。直线路径中的气泡图。气泡对于每种类型的数据都有一个大小范围D3.js 如何在直线路径中创建D3气泡图?,d3.js,charts,data-visualization,D3.js,Charts,Data Visualization,我想创建一个气泡图,如图中所示。直线路径中的气泡图。气泡对于每种类型的数据都有一个大小范围 使用svg元素,循环数据,并为每个基准绘制圆圈和附加文本字段。 以下是一个可用于构建的基础: var data = [{ label: 'Datum 1', rVal: 1, yVal: 1, xVal: 1, 'class': 'red' }, { label: 'Datum 2', rVal: 2, yVal: 1, xV
使用svg元素,循环数据,并为每个基准绘制圆圈和附加文本字段。 以下是一个可用于构建的基础:
var data = [{
label: 'Datum 1',
rVal: 1,
yVal: 1,
xVal: 1,
'class': 'red'
}, {
label: 'Datum 2',
rVal: 2,
yVal: 1,
xVal: 2,
'class': 'green'
}, {
label: 'Datum 3',
rVal: 3,
yVal: 1,
xVal: 3,
'class': 'blue'
}],
// Preliminaries
// domain is the data domain to show
// range is the range the values are mapped to
svgElm = d3.select('svg'),
rscale = d3.scale.linear().domain([0, 5])
.range([0, 60]),
xscale = d3.scale.linear().domain([0, 5])
.range([0, 320]),
yscale = d3.scale.linear().domain([0, 5])
.range([240, 0]),
circles;
// Circles now easily reusable
circles = svgElm.select('g.data-group')
.selectAll('circle')
.data(data)
.enter()
.append('circle');
// Alter circles
circles.attr('class', function (d) {
return d['class'];
})
.attr('r', function (d) {
return rscale(d.rVal);
})
.attr('cx', function (d) {
return xscale(d.xVal);
})
.attr('cy', function (d) {
return yscale(d.yVal);
});
请参阅JSFIDLE上的完整示例:
使用svg元素,循环数据,并为每个基准绘制圆圈和附加文本字段。 以下是一个可用于构建的基础:
var data = [{
label: 'Datum 1',
rVal: 1,
yVal: 1,
xVal: 1,
'class': 'red'
}, {
label: 'Datum 2',
rVal: 2,
yVal: 1,
xVal: 2,
'class': 'green'
}, {
label: 'Datum 3',
rVal: 3,
yVal: 1,
xVal: 3,
'class': 'blue'
}],
// Preliminaries
// domain is the data domain to show
// range is the range the values are mapped to
svgElm = d3.select('svg'),
rscale = d3.scale.linear().domain([0, 5])
.range([0, 60]),
xscale = d3.scale.linear().domain([0, 5])
.range([0, 320]),
yscale = d3.scale.linear().domain([0, 5])
.range([240, 0]),
circles;
// Circles now easily reusable
circles = svgElm.select('g.data-group')
.selectAll('circle')
.data(data)
.enter()
.append('circle');
// Alter circles
circles.attr('class', function (d) {
return d['class'];
})
.attr('r', function (d) {
return rscale(d.rVal);
})
.attr('cx', function (d) {
return xscale(d.xVal);
})
.attr('cy', function (d) {
return yscale(d.yVal);
});
请参阅JSFIDLE上的完整示例:
但是否可以使所有圆在底部均匀对齐。第一个圆能接触到第二个圆吗?第二个圆能接触到第三个圆吗?但有没有可能使所有的圆在底部均匀对齐呢。第一个圆圈能接触到第二个圆圈,第二个圆圈能接触到第三个圆圈吗?