d3 y轴的间隙为25个数字

发布于 2025-02-04 19:47:06 字数 942 浏览 2 评论 0原文

我的D3 JS代码低于

const svg = select(svgRef.current);
const { width, height } = wrapperRef.current.getBoundingClientRect();
const stackGenerator = stack().keys(keys);
const layers = stackGenerator(data);

const extent = [0, 100];

const yScale = scaleLinear().domain(extent).range([height, 0]);

const x0Scale = scaleBand()
  .domain(data.map((d) => d.name))
  .range([0, width])
  .padding(0.46);
const x1Scale = scaleBand()
  // .domain(data.map((d) => d.type))
  .rangeRound([0, x0Scale.bandwidth()])
  .padding(0.12);

const xAix = axisBottom(x0Scale);
const yAix = axisLeft(yScale);
svg.select(".x-axis").attr("transform", `translate(0, ${height})`).call(xAix);

svg
  .select(".y-axis")
  .attr("transform", `translate(${0 + 25}, 0 )`)
  .call(yAix);

D3 -y轴的范围为0到100。我在10分的组中获得Y轴 - (0,10,20,30,40,50,60,70,80,90,100)

我想在其差距中绘制它25 - (0,25,50,75,100)

如何实现?

I have below D3 js code -

const svg = select(svgRef.current);
const { width, height } = wrapperRef.current.getBoundingClientRect();
const stackGenerator = stack().keys(keys);
const layers = stackGenerator(data);

const extent = [0, 100];

const yScale = scaleLinear().domain(extent).range([height, 0]);

const x0Scale = scaleBand()
  .domain(data.map((d) => d.name))
  .range([0, width])
  .padding(0.46);
const x1Scale = scaleBand()
  // .domain(data.map((d) => d.type))
  .rangeRound([0, x0Scale.bandwidth()])
  .padding(0.12);

const xAix = axisBottom(x0Scale);
const yAix = axisLeft(yScale);
svg.select(".x-axis").attr("transform", `translate(0, ${height})`).call(xAix);

svg
  .select(".y-axis")
  .attr("transform", `translate(${0 + 25}, 0 )`)
  .call(yAix);

I have extent 0 to 100 for Y Axis. I am getting Y-Axis in the group of 10 points - (0,10,20,30,40,50,60,70,80,90,100)

I want to plot it in the gap of 25 - (0,25,50,75,100)

How can I achieve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回忆凄美了谁 2025-02-11 19:47:06

创建y轴时,您可以传递ticks要渲染的的数量

svg
  .select(".y-axis")
  .attr("transform", `translate(${0 + 25}, 0 )`)
  .call(yAix.ticks(5));

,将使用tickvalues

svg
  .select(".y-axis")
  .attr("transform", `translate(${0 + 25}, 0 )`)
  .call(yAix.tickValues([0,25,50,75,100]));

when creating the y-axis you can pass the number of ticks that you want to render

svg
  .select(".y-axis")
  .attr("transform", `translate(${0 + 25}, 0 )`)
  .call(yAix.ticks(5));

the other way would be using tickValues

svg
  .select(".y-axis")
  .attr("transform", `translate(${0 + 25}, 0 )`)
  .call(yAix.tickValues([0,25,50,75,100]));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文