Loading CSV file with special characters

704 views
Skip to first unread message

Paulo Carvalho

unread,
Mar 30, 2016, 3:30:43 AM3/30/16
to d3-js
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>
        <script src="http://d3js.org/d3.v3.min.js"></script>
    </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
file.csv

Tito

unread,
Mar 30, 2016, 12:43:17 PM3/30/16
to d3-js
could the issue be your xampp server as it is working for me just fine when using basic express with app.js

eoin

unread,
Mar 31, 2016, 7:25:09 AM3/31/16
to d3-js
Maybe try adding :
<meta charset="utf-8">

Between the <head></head>
Reply all
Reply to author
Forward
0 new messages