d3.js - 更新轴并更改路径宽度

时间:2014-04-14 23:19:05

标签: javascript css d3.js

我试图像这样更新轴的宽度:

零宽度的初始设置:

var x2 = d3.scale.linear()
        .domain([0, 10])
        .range([0, 0])
        .clamp(true);

svg.append("g")
        .attr("class", "x axis2")
        .attr("transform", "translate(0," + height / 2 + ")")
        .call(d3.svg.axis()
          .scale(x2)
          .orient("bottom")
          .tickFormat(function(d) { return d; })
          .tickSize(0)
          .tickPadding(12))
      .select(".domain")
      .select(function() { return this.parentNode.appendChild(this.cloneNode(true)); })
        .attr("class", "bar-highlight");

后来我想更新路径的宽度(转换效果很好)。我尝试了这个answer,但没有运气:

x2 = d3.scale.linear()
        .domain([0, data.page_count])
        .range([0, 15])
        .clamp(true);

d3.selectAll("g.x.axis2")
        .call(x2);

1 个答案:

答案 0 :(得分:1)

您需要在轴上调用d3.svg.axis().scale(x2),而不仅仅是x2。以下更新程序适用于我(虽然在空图上):

// Update the range of existing variable, x2
x2.range([0, 15]);
// Select and change the axis in D3
d3.selectAll("g.x.axis2")
    .call(d3.svg.axis().scale(x2));
相关问题