我的圖表有多個具有不同域的 Y 軸。當我在圖表上拖動時,只有最后一個 y 軸正在更新。我添加了每個 y 軸,如下所示;addYAxis(data, tag) { // tag is for index for each y-axis e.g: 0, 1, 2 const yScale = d3.scale.linear() .domain([0, this.innerHeight]) .range([this.innerHeight, 0]); const yAxis = d3.svg.axis() .scale(yScale) .orient(tag ? 'right' : 'left') .tickSize(tag ? this.innerWidth + 50 * (tag - 1) : -this.innerWidth); const yAxisElement = this.g.append('g') .attr('class', 'y axis') .call(yAxis); this.yAxisList.push({yScale, yAxis, yAxisElement});}這是每個軸的縮放列表。this.zoom.push(d3.behavior.zoom() .x(this.xScale) .y(this.yAxisList[tag].yScale) // when I replace [tag] with [0], then only first axis is being updated. .scaleExtent([.5, 10]) .scale(this.currentZoom) .translate(this.currentPan) .on('zoom', () => this.zoomed(tag)) .on('zoomend', () => { setTimeout(() => { this.zooming = false; }, 10); }));this.g.call(this.zoom[tag]) // when I replace [tag] with [0], then only first axis is being updated. .on('dblclick.zoom', null);并像下面一樣更新它們;updateYAxis() { this.yAxisList.forEach(({yAxisElement, yAxis}) => yAxisElement.call(yAxis));}此圖表的結構:如何在圖表上拖動時更新所有 Y 軸?
在 d3 圖表上拖動時僅更新最后一個 Y 軸
慕森王
2022-01-01 18:34:53