d3.js中的转义符号 [英] Escape Characters in d3.js ticks

查看:168
本文介绍了d3.js中的转义符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的图表的tickFormat中显示每升微摩尔(μmol/ L),但是当我传入µ mol / L时,它会显示字符µ而不是mu的符号。如何让它呈现符号?

I need to display micromoles per liter (µmol/L) in my chart's tickFormat, but when I pass in "µmol/L", it shows the characters "µ" instead of the symbol for mu. How do I get it to render the symbol?

推荐答案

在这种情况下,您不应该使用HTML实体。一旦你正在处理SVG,请使用:

In that case, you shouldn't use an HTML entity. Once you're dealing with an SVG , use this:

\u00B5

检查此代码段:

var svg = d3.select("body")
	.append("svg")
	.attr("width", 500)
	.attr("height", 200);
	
var scale = d3.scaleLinear()
	.range([40, 460])
	.domain([0, 100]);
	
var axis = d3.axisBottom(scale)
	.tickFormat(function(d){ return d + "\u00B5mol/L"})
    .ticks(5);

svg.append("g")
	.attr("transform", "translate(0,100)")
	.call(axis);

text { font-size: 14px;}

<script src="https://d3js.org/d3.v4.min.js"></script>

这篇关于d3.js中的转义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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