【发布时间】:2021-07-21 22:20:29
【问题描述】:
我一直在 D3 中制作一个 3 x 3 的小倍数网格。每个图表都有自己的 x 和 y 轴。但是,我只想在网格左列的图表上包含 y 轴(即第 1、第 4、第 7 个倍数)。
数据已经嵌套并绑定到 DOM,如下所示:
const wrapper = div.selectAll('uniqueChart')
.data(nest)
.enter()
.append('svg')
.attr('width', smallChartDims.width)
.attr("height", smallChartDims.height)
const bounds = wrapper.append('g')
.style('transform', `translate(${smallChartDims.margins.left}px, ${smallChartDims.margins.top}px)`)
然后,稍后,我将数据绘制到每个图表:
bounds.selectAll('.bar')
.data(d => d.values)
.enter()
.append('rect')
.attr("class", "bar")
.attr('height', d => smallChartDims.boundedHeight - yScale(yAccessor(d)))
.attr('width', newScale.bandwidth() + 1)
.attr('x', d => newScale(xAccessor(d)))
.attr('y', d => yScale(yAccessor(d)))
.attr("fill", womanColor)
.on("mouseover", d => mouseOn(d))
.on("mousemove", d => mouseMove(d))
.on("mouseout", d => mouseOut(d))
并生成并添加轴:
const xAxisGenerator = d3.axisBottom(newScale)
.tickValues(newScale.domain().filter((d, i) => !(i%10)))
.tickSizeOuter(0)
const xAxis = bounds.append('g')
.style("transform", `translateY(${smallChartDims.boundedHeight}px)`)
.call(xAxisGenerator)
const yAxisGenerator = d3.axisLeft(yScale)
.tickValues(["25", "50", "75"])
const yAxis = bounds.append('g')
.attr("class", "yAxis")
.call(yAxisGenerator)
.call(g => g.select(".domain").remove())
我尝试选择bounds 中的所有对象,然后以这种方式选择轴以希望将其移除,但并没有走得太远。有谁知道我该怎么做?
【问题讨论】:
标签: javascript d3.js data-visualization