亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 d3 圖表上拖動時僅更新最后一個 Y 軸

在 d3 圖表上拖動時僅更新最后一個 Y 軸

慕森王 2022-01-01 18:34:53
我的圖表有多個具有不同域的 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 軸?
查看完整描述

1 回答

?
鳳凰求蠱

TA貢獻1825條經驗 獲得超4個贊

這里,


.on('zoom', () => this.zoomed(tag))

您只更新了當前縮放,但也應使用當前縮放值更新其他縮放對象。


.on('zoom', () => {

    this.zoom.forEach((zoom, t) => {

        zoom.scale(this.zoom[tag].scale());

        zoom.translate(this.zoom[tag].translate());

        this.zoomed(t);

    });

})


查看完整回答
反對 回復 2022-01-01
  • 1 回答
  • 0 關注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號