I’m parsing some data to display in a graph, yet I consistently get NaN when I parse my integers. I know that generally means that they’re not parsed correctly, but I’m using parseint and I thought that would fix things. I’m parsing the Unixtime (first field) and then three other fields (correctly parsed). Yet, whenever I go to display the Unixtime it fails. I’ve declared scale.linear for x, though time.scale also fails.
The code snippet I’m using is below:
d3.tsv("<?php echo $field; ?>values.tsv", function(error, data) {
color.domain(d3.keys(data[0]).filter(function(key) { return key !== "Unixtime"; }));
data.forEach(function(d) {
d.Unixtime = parseInt(d.Unixtime/1000);
});
var cities = color.domain().map(function(name) {
return {
name: name,
values: data.map(function(d) {
return {Unixtime: d.Unixtime, value: parseFloat(d[name]/1000)};
})
};
});
The error message I’m getting is below from the Chrome debugger.
Error: Problem parsing d="MNaN,1.7527908403982337CNaN,1.7527908403982337,NaN,1.7527908403982337,NaN,1.751122428294669CNaN
The data looks like:
1353168433 5557 6404 5510
1353175632 5478 6404 5510
1353182750 5432 6404 5510
The problem is this line:
When you divide it by 1000, you get a decimal number. Try
parseFloat()instead:Alternatively you could
/1000after converting to int: