簡體   English   中英

使用D3 JS向軸添加魚眼

[英]Adding fisheye to axes with D3 JS

我有此可視化 ,我試圖將魚眼視圖添加到圖表中。 我試圖在plotData函數中添加以下行,但不會發生:

var fisheye = d3.fisheye.circular()
            .radius(120);

    svg.on("mousemove", function () {
        fisheye.focus(d3.mouse(this));

        circle.each(function (d) {
            d.fisheye = fisheye(d);
        });
    });

關於如何解決這個問題的任何想法?

謝謝!

首先,您的d3.timer永遠不會停止運行。 這使我的機器發瘋(CPU 100%)並破壞了fishey的性能。 我真的不確定您在那做什么,所以暫時忽略一下。

魚眼需要一點按摩。 首先,它希望將數據像素的位置存儲在dxdy屬性中。 您可以在畫圓時對此進行修飾:

     circle
        .attr("cx", function(d, i) { d.x = X(d[0]); return d.x; })
        .attr("cy", function(d, i){ d.y = Y(d[1]); return d.y; });

其次,您要分多個步驟繪制數據,因此需要選擇魚眼的所有圓圈。 第三,您忘記了實際上使積分增加和縮小的代碼:

svg.on("mousemove", function () {
    fisheye.focus(d3.mouse(this));

    // select all the circles
    d3.selectAll("circle.data").each(function(d) { d.fisheye = fisheye(d); })
      // make them grow and shrink and dance
      .attr("cx", function(d) { return d.fisheye.x; })
      .attr("cy", function(d) { return d.fisheye.y; })
      .attr("r", function(d) { return d.fisheye.z * 4.5; });

});

更新示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM