Hello,
I am trying to load a CSV file using D3. The HTML file is run on a XAMPP web server.
The CSV file has special characters that are not correctly interpreted. When a display the result in the console, instead of having the characters correctly, � are displayed. I have tried to use different charset encoding in order to try getting a correct result. However, I did not obtained what I wanted.
Could anyone know how I may be able to correctly process CSV files with special characters?
The code of my HTML file is the following one. The analysed file is attached to this message.
<!--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
<!doctype html>
<html>
<head>
<title>D3 loading CSV test</title>
</head>
<body>
<script>
var DSV_PARSER = d3.dsv(",", "text/plain;charset=ANSI");
d3.text("file.csv", function(getRows) {
var rows = DSV_PARSER.parseRows(getRows).map(function(row) {
return row.map(function(value) {
return value;
});
});
console.log("1: " + rows[0]);
});
var DSV_PARSER2 = d3.dsv(",", "text/plain;charset=windows-1252");
d3.text("file.csv", function(getRows) {
var rows = DSV_PARSER2.parseRows(getRows).map(function(row) {
return row.map(function(value) {
return value;
});
});
console.log("2: " + rows[0]);
});
var DSV_PARSER3 = d3.dsv(",", "text/plain;charset=UTF-8");
d3.text("file.csv", function(getRows) {
var rows = DSV_PARSER3.parseRows(getRows).map(function(row) {
return row.map(function(value) {
return value;
});
});
console.log("3: " + rows[0]);
});
</script>
</body>
</html>
<!--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
Thank you,
Best regards