gpt4 book ai didi

javascript - 是否可以在 D3.js 中找到刻度之间的距离?

转载 作者:数据小太阳 更新时间:2023-10-29 04:12:53 26 4
gpt4 key购买 nike

有没有办法找出 x 轴上刻度线之间的距离?我将序数刻度与 rangeRoundBands 一起使用,告诉我它没有刻度函数。

var x= d3.scale.ordinal().rangePoints([_margin.left, cWidth]);
x.domain(['Dec','Jan']);
var testTicks = x.ticks(2);

它可以很好地生成轴(无法发布图像)但我无法弄清楚如何获得距离

(编辑:添加 x.domain)

最佳答案

var data         = [45, 31, 23], // whatever your data is
graphHeight = 400,
// however many ticks you want to set
numberTicksY = 4,
// set y scale
// (hardcoded domain in this example to min and max of data vals > you should use d3.max real life)
y = d3.scale.linear().range(graphHeight, 0]).domain(23, 45),
yAxis = d3.svg.axis().scale(y).orient("left").ticks(numberTicksY),
// eg returns -> [20, 30, 40, 50]
tickArr = y.ticks(numberTicksY),
// use last 2 ticks (cld have used first 2 if wanted) with y scale fn to determine positions
tickDistance = y(tickArr[tickArr.length - 1]) - y(tickArr[tickArr.length - 2]);

关于javascript - 是否可以在 D3.js 中找到刻度之间的距离?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17221755/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com