Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.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 “错误:属性d:预期数量…”的确切含义是什么?_Javascript_Html_D3.js - Fatal编程技术网

Javascript “错误:属性d:预期数量…”的确切含义是什么?

Javascript “错误:属性d:预期数量…”的确切含义是什么?,javascript,html,d3.js,Javascript,Html,D3.js,我正在尝试从.csv文件中的数据创建折线图。我使用了一个我在网上找到的例子,但是我得到了一个错误:error:attributed:Expected number,我不确定这到底意味着什么,或者我必须在代码中修复什么 这是我的代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Arduino Server</title> <

我正在尝试从.csv文件中的数据创建折线图。我使用了一个我在网上找到的例子,但是我得到了一个错误:error:attributed:Expected number,我不确定这到底意味着什么,或者我必须在代码中修复什么

这是我的代码:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
    <title>Arduino Server</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="stylesheet" type="text/css" href="style.css">

    <script type="text/javascript" src="d3.min.js"></script>
    <script type="text/JavaScript" src="jquery-3.2.1.min.js"></script>
</head>
<body>
    <!--div that will contain everything-->
    <div class ="container">

        <div>
            <h1 style="text-align: center; color:red;">My Arduino 
Server</h1>
        </div>

        <!--div that will contain the Temperature Link-->
        <div >
            <h1 style="text-align: center; color: #ff6961">Temperature Over 
              Some Time</h1>    
            <script>
                // set the dimensions and margins of the graph
                var margin = {top: 20, right: 20, bottom: 30, left: 50},
                    width = 960 - margin.left - margin.right,
                    height = 500 - margin.top - margin.bottom;

                // parse the date / time
                var parseTime = d3.timeParse("%d-%b-%y");

                // set the ranges
                var x = d3.scaleTime().range([0, width]);
                var y = d3.scaleLinear().range([height, 0]);

                // define the line
                var line = d3.line()
                    .x(function(d) { return x(d.date); })
                    .y(function(d) { return y(d.temp); });

                // append the svg obgect to the body of the page
                // appends a 'group' element to 'svg'
                // moves the 'group' element to the top left margin
                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.csv("p.csv", function(error, data) {
                  if (error) throw error; 

                  // format the data
                  data.forEach(function(d) {
                      d.date = parseTime(d.date);
                      d.temp = +d.temp;
                  });

                  // 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.temp; })]);


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

                  // Add the Y Axis
                  svg.append("g")
                      .call(d3.axisLeft(y));

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

                });
            </script>
        </div>

    </div>

</body>
</html>

如何更好地理解错误?

错误发生在哪一行?我认为错误来自.attrd,行;这是一个数字。可能来自日期。您的代码不会抛出任何错误,工作正常:@GerardoFurtado,我注意到您添加了这行代码var data=d3.csvParsed3.selectcsv.text,那到底是干什么用的?它只是将csv解析为文本文件吗?奇怪的是,我的代码昨天不起作用,但今天就起作用了,只是如果我更改了值,代码就不会更新。知道会是什么吗?谢谢你的帮助!我忘了提到,如果我用你的代码替换我的代码,它将不起作用。我得到一个错误,它是:uncaughttypeerror:无法读取null的属性“textContent”。我不确定为什么它会为null?
date,temp
1-Apr-17,70
2-Apr-17,80
3-Apr-17,75
4-Apr-17,64
5-Apr-17,54
6-Apr-17,67
7-Apr-17,89
8-Apr-17,87
9-Apr-17,25
10-Apr-17,56