Accepted answer

The problem is that you are serving D3 with the ISO-8859-1 character encoding (often the browser default), whereas D3 must be served with UTF-8 encoding. Typically this happens because you are missing a meta tag at the top of the loading HTML page:

<!DOCTYPE html>
<meta charset="utf-8">

The meta-specified charset is required because is served by GitHub Pages and does not specify a charset in the Content-Type response header. The charset is therefore inferred from the loading HTML document.

If you prefer, you can specify a charset attribute on the script tag. Make sure you clear your browser cache before testing, as the cached copy will retain the character encoding from when it was originally accessed:

<script src="" charset="utf-8"></script> 

The error does not occur with the minified version because the variable names are replaced with ASCII equivalents. (I don't recall offhand if UTF-8 characters in format strings are likewise replaced with escape sequences, but I still recommend serving D3 as UTF-8 in all cases.)

Encoding problems can also happen if you downloaded D3 by viewing the source in your browser and then using copy-paste, which is why I recommend downloading


it is definitely an encoding issue, try to focus on that.

Opening with Chrome the link you posted ( i see that double-byte characters too:

 var π = Math.PI, ε = 1e-6, d3_radians = π / 180, d3_degrees = 180 / π;

if you barely save the file with "save page as..." and you open it with an editor like Sublime Text ( it works fine and it shows:

var π = Math.PI, ε = 1e-6, d3_radians = π / 180, d3_degrees = 180 / π;

i tried to use this downloaded file with a projects of mine and it's all right.

Related Query

More Query from same tag