简体   繁体   中英

Decimal value on d3.js y axis

在此输入图像描述

I am having an issue with adjusting scale on y-axis for a d3.js visualization that I am working on. On the scale, it is showing the values as 1.0,2.0 1 Y-axis for d3

I want to change the value to 0.3,0.4,0.5,0.6 instead 3,4,5,6.

My code is attached below :

  var y = d3.scale.linear()
  .domain([0, d3.max(stateById.values(), function(d) { return d.total; })])
  .rangeRound([height, 0])
  .nice();

var yAxis = d3.svg.axis() .scale(y) .orient("left") .tickFormat(d3.format(".1f"));

please advise on what change I should make in the line above. Thanks.

Essentially what you need to do is change the tickFormat function to divide the datum by ten. It may also be good practice to store the d3.format(".1f") in an external variable and use that instead.

.tickFormat(function (d){
    return d3.format(".1f")(d/10);
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM