【发布时间】:2019-12-11 11:10:59
【问题描述】:
我使用 d3.js-v3 时间刻度 d3.time.scale() 绘制了我的 x 轴。
我的轴刻度不等间距。
我怎样才能有等距的刻度?
这是我的代码
var customTimeFormat = d3.time.format("%d %b");
var margin = {
top: 0,
right: 20,
bottom: 20,
left: 20
},
width = 550 - margin.left - margin.right,
height = 20 - margin.top - margin.bottom;
var x = d3.time.scale()
.domain([new Date("08/21/2019"), new Date("09/5/2019")])
.range([0, width]);
var xAxis = d3.svg.axis()
.scale(x)
.tickFormat(customTimeFormat);
var svg = d3.select("body").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 + ")");
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
.axis text {
font: 10px sans-serif;
}
.axis line,
.axis path {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
<script src="https://d3js.org/d3.v3.min.js"></script>
【问题讨论】:
标签: javascript d3.js