score:1

Accepted answer

firstly your json string should be like:

    var datajson = '[        { "x": 100, "y": 110 },        
{ "x": 83, "y": 43 },        { "x": 92, "y": 28 },        
{ "x": 49, "y": 74 },        
{ "x": 51, "y": 10 },        { "x": 25, "y": 98 },
{ "x": 77, "y": 30 },        { "x": 20, "y": 83 },
{ "x": 11, "y": 63 },        { "x":  4, "y": 55 },
{ "x":  0, "y":  0 },        { "x": 85, "y": 100 },
{ "x": 60, "y": 40 },        { "x": 70, "y": 80 },
{ "x": 10, "y": 0 },        { "x": 40, "y": 50 },
{ "x": 25, "y": 31 }      ]';

note the double codes(") on the key.

next

you are setting the domain like:

var x = d3.scale.linear()
      .domain([0, d3.max(data, function(d) {
        return d.x + 10;
      })])
      .range([margin.left, w - margin.right]); // 

but data is defined much below this line.

so please move the below lines above:

var data = json.parse(datajson);



    data.foreach(function(d) {
      d.x = d.x;
      d.y = +d.y;
    });

working code here


Related Query