简体   繁体   English

定制对数d3图表

[英]customized logarithmic d3 chart

I am trying to create a d3 chart with logarithmic scale(1,10,100..). 我正在尝试创建对数标度(1,10,100 ..)的d3图表。 I used their functions and call but not much help. 我使用了它们的功能并打电话给我,但帮助不大。

var x = d3.scale.log()
    .domain([1,10])
    .range([0, width]);

var y = d3.scale.log()
    .domain([1,10])
    .range([height, 0]);

var color = d3.scale.category10();

var xAxis = d3.svg.axis()
    .scale(x)   
    .orient("bottom");

var yAxis = d3.svg.axis()
    .scale(y)   
    .orient("left");

var line = d3.svg.line()
    .x(function(d) { return x(d[xAxxis]); })
    .y(function(d) { return y(d[yAxxis]); });
var svg = d3.select("#"+this.divid).append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
  .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

x.domain(d3.extent(totalArray, function(d) { return d[xAxxis]; })).nice(); 
y.domain(d3.extent(totalArray, function(d) { return d[yAxxis]; })).nice(); 

Is there any way i can create the axis with 1e+0,10e+0,100e+0 rather than 1e+0,2e+0,3e+0 我有什么办法可以用1e + 0,10e + 0,100e + 0而不是1e + 0,2e + 0,3e + 0创建轴

You can control which labels the axis renders using either the tick() or tickValues() method, depending on how you want to go about it. 您可以使用tick()tickValues()方法来控制轴渲染的标签,具体取决于您要使用的方式。 See the d3's API documentation for more details . 有关更多详细信息,请参见d3的API文档 Also, note that a log scale's tick() method takes no arguments , so you'll likely have to use tickValues() though the other method might come in handy for formatting. 另外,请注意,对数刻度的tick()方法不带任何参数 ,因此您可能不得不使用tickValues()尽管其他方法在格式化时可能会派上用场。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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