Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当我试图使用tsv文件的数据在d3.js中获取线条图时,我遇到了这个错误。[未捕获的TypeError:无法读取未定义的属性'length'_Javascript_Svg_D3.js - Fatal编程技术网

Javascript 当我试图使用tsv文件的数据在d3.js中获取线条图时,我遇到了这个错误。[未捕获的TypeError:无法读取未定义的属性'length'

Javascript 当我试图使用tsv文件的数据在d3.js中获取线条图时,我遇到了这个错误。[未捕获的TypeError:无法读取未定义的属性'length',javascript,svg,d3.js,Javascript,Svg,D3.js,当我试图通过使用tsv文件的数据在d3.js中获取线图时,我遇到了这个错误。 [未捕获的TypeError:无法读取未定义的属性'length'] 这就是我的数据集的样子 date label SatJan1700:05:421970 1 SatJan1700:07:381970 2 SatJan1700:10:381970 1 SatJan1700:14:391970 1 这是我的html代码 <!DOCTYPE html> <meta charset="utf-8

当我试图通过使用tsv文件的数据在d3.js中获取线图时,我遇到了这个错误。 [未捕获的TypeError:无法读取未定义的属性'length']

这就是我的数据集的样子

date label
SatJan1700:05:421970 1
SatJan1700:07:381970 2
SatJan1700:10:381970 1
SatJan1700:14:391970 1
这是我的html代码

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

body {
  font: 10px sans-serif;
}

.axis path,
.axis line {
  fill: none;
  stroke: #000;
  shape-rendering: crispEdges;
}

.x.axis path {
  display: none;
}

.line {
  fill: none;
  stroke: steelblue;
  stroke-width: 1.5px;
}

</style>
<body>
<script src="d3/d3.js"></script>
<script>

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

var parseDate = d3.time.format("%a%b%d%H:%M:%S%Y").parse;

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");

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

var line = d3.svg.line()
    .x(function(d) { return x(d.date); })
    .y(function(d) { return y(d.label); });

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 + ")");

d3.tsv("combined.tsv", function(error, data) {
  data.forEach(function(d) {
    d.date = parseDate(d.date);
    d.label = +d.label;
  });

  x.domain(d3.extent(data, function(d) { return d.date; }));
  y.domain(d3.extent(data, function(d) { return d.label; }));

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

  svg.append("g")
      .attr("class", "y axis")
      .call(yAxis)
    .append("text")
      .attr("transform", "rotate(-90)")
      .attr("y", 6)
      .attr("dy", ".71em")
      .style("text-anchor", "end")
      .text("Sentiment");

  svg.append("path")
      .datum(data)
      .attr("class", "line")
      .attr("d", line);
});
</script>
谁能帮我识别错误并背诵错误

这是我一直在使用的.js文件的链接


适合我。错误到底在哪里抛出?你确定你的数据是TSV吗?在给定的示例中,没有制表符,只有空格。@Sirko是正确的。当TSV中的空格被制表符替换时,这一点也有效。如d3:js所示:2465@FernOfTheAndes.... 坦克。。它正在工作!!!我在电脑上使用d3.v3.js时遇到了一个问题。我得到了解析错误,但是,当我使用相同的代码使用链接时,它工作得很好。你知道为什么会这样吗?