如何打破d3.axis.tickFormat中的一行? [英] How to break a line in d3.axis.tickFormat?

查看:647
本文介绍了如何打破d3.axis.tickFormat中的一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个函数,它返回一个有两行文本的tick标签。我可以看到,一个svg文本标签用于文本标签。有没有办法添加tspan有什么或什么?

I want to write a function, that returns a tick label with two lines of text. As I can see, an svg text tag is used for text labels. Is there a way to add tspan there or something?

推荐答案

您可以访问演示

d3.select('svg')
  .append('g')
  .attr('transform', 'translate(180, 10)')
  .call(xAxis)
  .selectAll('text') // `text` has already been created
  .selectAll('tspan')  
  .data(function (d) { return bytesToString(d); }) // Returns two vals
  .enter()
  .append('tspan')
  .attr('x', 0)
  .attr('dx', '-1em')
  .attr('dy', function (d, i) { return (2 * i - 1) + 'em'; })
  .text(String);

此外,您必须设置 .tickFormat 上的''

Also, you'll have to set .tickFormat to '' on the axis.

这篇关于如何打破d3.axis.tickFormat中的一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆