D3.js text element does not display unicode character correctly

I am trying to add ➤ to SVG using unicode as shown below.

g.append("text")
        .attr("x", 10)
        .attr("y", 10)
        .text("➤");

      

➤

is displayed but not ➤

+3


source to share


2 answers


Instead of using, .text()

use.html()



+11


source


➤

- HTML / XML markup. You are not pasting in HTML / XML source code, so these screens do nothing. You can simply:

.text('➤');

      

And save the file in the same encoding that the browser will read (usually UTF-8 for a page with <meta charset="utf-8"/>

.



If you really can't use non-ASCII characters, for example because your script must be included from multiple pages with different character sets, or because your text editor doesn't support Unicode, then the type of escape code you want to use JavaScript string literal encoding. ➤ - U + 27A4 Black right arrow, so:

.text('\u27A4');

      

+6


source







All Articles