Search code examples
javascriptjsoncsvd3.jscyrillic

Reading Cyrillic text from CSV / JSON with d3


I would like to import Cyrillic text from CSV or JSON using d3 (for the purpose of a bubble chart visualisation)

Once loaded with either of the functions:

d3.csv('spendings.csv', function(data) {
  console.log(data[0]);
});

or

d3.json('spendings.json', function(data) {
  console.log(data[0]);
});

the text

Многопрофилна болница за активно лечение /МБАЛ/ "Света Анна" АД - София

looks something like this in the DOM console:

M������������ ������� �� ������� ������� /����/ "����� ����" �� - �����

This tells me that the problem is not with the HTML encoding, but rather with the way Cyrillic text is read by d3.js


Solution

  • I use Cyrillic in D3.

    1.HTML:

    <head>
      <meta charset="utf-8">
    </head>
    
    1. use utf-8 in editor .html .csv .json files