1

I am starting with this simple example but I have the following error (using Firebug)

TypeError: string is undefined [Break On This Error]
var c, p, i = 0, n = template.length, m = string.length;

Any hint?? (I tried similar responses and it didn't work, I guess there is something wrong with the time and date format, but I believe the "%Y-%m-%d" format is the right one that I have in the csv file...)

Thanks!!

//here my prueba.html file

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

body{font: 12px arial;}

path{stroke: steelblue;
    stroke-width: 2;
    fill: none;}

.axis path,
.axis line {fill: none;
            stroke: grey;
            stroke-width: 1;
            shape-rendering: crispEdges;}

</style>
<body>
<script type="text/javascript" src="d3/d3.v3.js"></script>

<script>

var margin = {top: 30, right: 20, bottom: 30, left: 50},
    width = 600 - margin.left - margin.right,
    height = 270 - margin.top - margin.bottom;

var parseDate = d3.time.format("%Y-%m-%d").parse; // HERE ERROR !!!

var x = d3.time.scale().range([0, width]);
var y = d3.scale.linear().range([height, 0]);

var xAxis = d3.svg.axis().scale(x)
    .orient("bottom").ticks(5);

var yAxis = d3.svg.axis().scale(y)
    .orient("left").ticks(5);

var valueline = d3.svg.line()
    .x(function(d) { return x(d.timestamp); })
    .y(function(d) { return y(d.temperature); });

var svg = d3.select("body")
    .append("svg")
        .attr("width", width + margin.left + margin.right)
        .attr("height", height + margin.top + margin.bottom)
    .append("g")
        .attr("transform", "translate(" + margin.left + "," + margin.top +")");

// Get the data
d3.tsv("data/data.csv", function(error, data) 
{data.forEach(function(d) 
    {d.timestamp = parseDate(d.timestamp); // HERE ERROR !!!
     d.temperature = +d.temperature;});

    // Scale the range of the data
    x.domain(d3.extent(data, function(d) { return d.date; }));
    y.domain([0, d3.max(data, function(d) { return d.close; })]);

    svg.append("path")      // Add the valueline path.
        .attr("d", valueline(data));

    svg.append("g")         // Add the X Axis
        .attr("class", "x axis")
        .attr("transform", "translate(0," + height + ")")
        .call(xAxis);

    svg.append("g")         // Add the Y Axis
        .attr("class", "y axis")
        .call(yAxis);

});

</script>
</body>

//here my data.csv file

timestamp,temperature
1900-01-01,20
1900-01-02,20
1900-01-03,17
1900-01-04,23
1900-01-05,15
1900-01-06,22
1900-01-07,24
1900-01-08,15
1900-01-09,25
1900-01-10,19
1900-01-11,23
1900-01-12,19
1900-01-13,17
1900-01-14,15
1900-01-15,17
1900-01-16,21
1900-01-17,23
1900-01-18,25
1900-01-19,17
1900-01-20,22
1900-01-21,23
1900-01-22,17
1900-01-23,15
1900-01-24,23
1900-01-25,19
1900-01-26,25
1900-01-27,21
1900-01-28,22
1900-01-29,20
1900-01-30,15
1900-01-31,21
1900-02-01,19
1900-02-02,15
1900-02-03,15
1900-02-04,25
1900-02-05,23
1900-02-06,25
1900-02-07,15
1900-02-08,18
1900-02-09,22
1900-02-10,15
1900-02-11,19
1900-02-12,18
1900-02-13,24
1900-02-14,22
1900-02-15,16
1900-02-16,21
1900-02-17,24
1900-02-18,25

A picture of this using Chrome developer tools... https://i.stack.imgur.com/Yh7WE.jpg

lmblanes
  • 121
  • 1
  • 2
  • 11

2 Answers2

0

You are using d3.tsv, you should be using d3.csv instead.

Pablo Navarro
  • 8,244
  • 2
  • 43
  • 52
  • Are you sure is the same error? I tried to reproduce it but I have the timestamps parsed without problem. – Pablo Navarro Jul 09 '13 at 12:33
  • Thanks Pablo!. Anyway there was another error where //return the range of data is. The d.close and d.date where not changed according with the new csv data. – lmblanes Jul 09 '13 at 13:26
  • HA! This is so annoying. As a python programmer, pasting the demo tsv data into vim converted the tabs to 4x spaces for me.. good catch, cheers. – Rich Jones Jan 13 '14 at 08:36
0

Also if you want to use tsv (Tab-separated values) you'll need to replace every comas by a tabulation.

PS: care to not save the file with an editor that automatically replace the tabulations with spaces :)

Yves Lange
  • 3,914
  • 3
  • 21
  • 33