D3.js .csv问题 - 错误:<path>属性的值无效d =“M499.99730980162605,187.54702784048158L499.99731009247085,

时间:2015-05-27 02:47:50

标签: javascript jquery parsing csv d3.js

我正在制作基于d3.js的图表,我正在收到一个,

“错误:属性值无效:d =”M499.99730980162605,187.54702784048158L499.99731009247085,...“。

我正在尝试以.csv格式绘制循环数据,看起来像是

record,5,timestamp,positionlat,positionlong,distance,altitude,speed,temperature
data,5,2015-05-25 18:33:19,467885825,"-1,275,710,534",8.25,"2,402.6",7.976,20
data,5,2015-05-25 18:33:24,467886510,"-1,275,704,356",53.3,"2,402.6",9.552,19
data,5,2015-05-25 18:33:25,467886903,"-1,275,703,091",63.16,"2,402.6",9.581,19
data,5,2015-05-25 18:33:27,467887866,"-1,275,700,622",83.15,"2,402.6",9.69,19
data,5,2015-05-25 18:33:30,467889786,"-1,275,696,923",115.37,"2,394.2",10.064,19
data,5,2015-05-25 18:33:32,467891098,"-1,275,694,820",134.88,"2,394.2",9.715,19
data,5,2015-05-25 18:33:34,467892345,"-1,275,692,669",154.28,"2,394.2",9.588,19
data,5,2015-05-25 18:33:36,467893324,"-1,275,690,252",174,"2,394.2",9.825,19

这是代码

d3.csv(activityFile.url(), function(d){

    return {
        timestamp : new Date(d.timestamp),
        speed : +d.speed,
        altitude : +d.altitude.replace(/\,/g,''),
        distance : +d.distance.replace(/\,/g,''),
        //timeDone : parseDate(d.timestamp)
    };

    function sortByDateAscending(a, b) {
        // Dates will be cast to numbers automagically:
        return a.timestamp - b.timestamp;
    }

    data = data.sort(sortByDateAscending);

},function(data) {

    maxTime = d3.max(data, function(d) { return d.timestamp;} );
    maxAlt = d3.max(data, function(d) { return d.altitude;} );
    maxSpeed = d3.max(data, function(d) { return d.speed;} );

    //timeDone = parseDate(d.timestamp);

    console.log(maxAlt);
    console.log(maxTime);
    console.log(maxSpeed);

    var chart = d3.select("body").append("svg")
        .attr("class", "chart")
        .attr("id", "theChart")
        .attr("width", chartRowWidth)
        .attr("height", chartRowWidth/aspect);

    var xScale = d3.scale.linear()
                     .domain([0, maxTime])
                     .range([0, chartRowWidth]);

    var yScale = d3.scale.linear()
                     .domain([0, maxSpeed])
                     .range([0, chartRowWidth/aspect]);

    var area = d3.svg.area()
        .interpolate("basis")
        .x(function(d)  {  return xScale(d.timestamp); })
        .y(function(d) {  return yScale(d.speed); });


    chart.append("path")
        .attr("class", "area")
        .attr("d", area(data));  //around here

}); 

我感谢我收到了对最后一行口渴的错误。我真的不明白为什么我有这个问题。

Sidenote,由于某种原因,maxAlt值实际上已返回最大位置值。不知道为什么会发生这种情况。

由于

0 个答案:

没有答案