d3 - attaching data to an axis for rescaling

前端 未结 1 328
无人共我
无人共我 2021-01-14 20:48

I want to switch between showing actual values and percentages on a scale. At present the data is imported from a csv file and I process the csv to find the domain for the

相关标签:
1条回答
  • 2021-01-14 21:16

    You could create two axis components which utilize your two scales (percentage and value), and transition between the two axes when you transition your data.

    var xAxisValue = d3.svg.axis()
        .scale(valueScale)
        .orient("bottom");
    var xAxisPercentage = d3.svg.axis()
        .scale(percentageScale)
        .orient("bottom");
    
    d3.select("svg").append("g")
        .attr("class", "x-axis")
        .call(xAxisValue);
    
    /* More code... */
    
    // At the point you want to switch...
    var dur = 1500;
    d3.select(".x-axis").transition().duration(dur).call(xAxisPercentage);
    
    0 讨论(0)
提交回复
热议问题