但我不知道如何实际实现 Series 对象来缩放和绑定数据,这是我的代码:
function render(svg) {
// const xValue = d => d['Population (2020)'];
// const yValue = d => d['Country (or dependency)'];
// const xExtent = d3.extent(world_population, xValue);
// const xScale = d3
// .scaleLinear()
// .domain(xExtent)
// .range([0, width]);
// const yScale = d3
// .scaleBand()
// .domain(world_population.map(yValue))
// .range([0, height]);
const xValue = d => d.data;
const yValue = d => d.index;
const xExtent = d3.extent(plot_data.values);
const xScale = d3
.scaleLinear()
.domain(xExtent)
.range([0, width]);
const yScale = d3
.scaleBand()
.domain(plot_data.index)
.range([0, height]);
const selection = d3.select(svg);
selection
.selectAll('rect')
.data(plot_data)
.enter()
.append('rect')
.attr('fill', 'slateblue')
.attr('y', d => yScale(d.index))
.attr('width', d => xScale(d.data))
.attr('height', yScale.bandwidth());
}
任何帮助或指示将不胜感激。