在尝试在D3中制作多线图时获得一堆“NaN”

时间:2015-10-04 03:11:17

标签: javascript csv d3.js

我已经获得了一些D3.js代码来绘制多线图的轴,但是我不能用它绘制线条。

我的代码(or here):

kill $(...) 2>/dev/null

它将数据提取到下面的CSV文件(better visibility here):

<style type="text/css">
  .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>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.js" charset="utf-8"></script>

<div id="container">
  <svg class="line-chart"></svg>
  <p class="source">Source: U.S. Bureau of Labor Statistics</p>
</div>

<script type="text/javascript">
  var newspapers = 'Newspaper publishing',
    radio = 'Radio broadcasting',
    tv = 'Television broadcasting',
    pr = 'Public relations agencies';

  var margin = {
    top: 20,
    right: 30,
    bottom: 20,
    left: 50
  }
  var width = document.getElementById('container').clientWidth,
    width = width - margin.left - margin.right;
  var height = width / 1.5 - margin.top - margin.bottom;

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

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

  var color = d3.scale.category10();

  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.Month);
  //    })
  //    .y(function(d){
  //        return y(d[newspapers]);
  //    });

  var line = d3.svg
    .line()
    .interpolate('basis')
    .x(function(d) {
      return x(d.Month);
    })
    .y(function(d) {
      return y(d.jobs);
    });

  var svg = d3.select('.line-chart')
    .attr('width', width + margin.left + margin.right)
    .attr('height', height + margin.top + margin.bottom)
    .append('g')
    .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');

  d3.csv('MediaJobNumbersUSA.csv', function(error, csvData) {
    if (error) throw error;

    var data = csvData.map(function(obj) {
      var rObj = {};
      rObj[newspapers] = obj[newspapers];
      rObj[radio] = obj[radio];
      rObj[tv] = obj[tv];
      rObj[pr] = obj[pr];

      var timeFormat = d3.time.format('%Y M%m');
      rObj.Month = timeFormat.parse(obj.Year + ' ' + obj.Period);

      return rObj;
    });

    color.domain(
      d3.keys(data[0])
      .filter(function(key) {
        return (key !== 'Month');
      })
    );

    var industries = color.domain()
      .map(function(industry) {
        return {
          name: industry,
          values: data.map(function(d) {
            return {
              date: d.Month,
              jobs: +d[industry]
            };
          })
        };
      });


    x.domain(d3.extent(data, function(d) {
      return d.Month;
    }));
    y.domain([
      d3.min(industries, function(ind) {
        d3.min(ind.values, function(v) {
          return v.jobs;
        });
      }),
      d3.max(industries, function(ind) {
        d3.max(ind.values, function(v) {
          return v.jobs;
        });
      })
    ]);

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

    svg.append('g')
      .attr('class', 'y axis')
      .call(yAxis);

    var industry = svg.selectAll('.industry')
      .data(industries)
      .enter()
      .append('g')
      .attr('class', 'industry');

    industry.append('path')
      .attr('class', 'line')
      .attr('d', function(d) {
        console.log(d.values);
        return line(d.values);
      })
      .style('stroke', function(d) {
        return color(d.name);
      });

    // svg.append('path')
    //  .datum(data)
    //  .attr('class','line')
    //  .attr('d',line);
  });
</script>

问题:在绘制Year,Period,Newspaper publishing,Television broadcasting,Radio broadcasting,Public relations agencies 1947,M01,230.6,,, 1947,M02,233.1,,, 1947,M03,234.4,,, 1947,M04,235,,, 1947,M05,237.1,,, 1947,M06,239.3,,, 1947,M07,239.3,,, 1947,M08,240.4,,, 1947,M09,242,,, 1947,M10,242.2,,, 1947,M11,243.7,,, 1947,M12,243.8,,, 1948,M01,245.2,,, 1948,M02,248.2,,, 1948,M03,251,,, 1948,M04,252.3,,, 1948,M05,253.6,,, 1948,M06,254.8,,, 1948,M07,255.6,,, 1948,M08,255.8,,, 1948,M09,256.6,,, 1948,M10,258.9,,, 1948,M11,259.9,,, 1948,M12,261.6,,, 1949,M01,259.2,,, 1949,M02,259,,, 1949,M03,260.3,,, 1949,M04,261.2,,, 1949,M05,263.6,,, 1949,M06,266,,, 1949,M07,265.4,,, 1949,M08,266.7,,, 1949,M09,267.5,,, 1949,M10,268.8,,, 1949,M11,269,,, 1949,M12,268.5,,, 1950,M01,265.1,,, 1950,M02,267.8,,, 1950,M03,269,,, 1950,M04,270,,, 1950,M05,269.6,,, 1950,M06,270.1,,, 1950,M07,269.8,,, 1950,M08,267.2,,, 1950,M09,269,,, 1950,M10,266.5,,, 1950,M11,268.8,,, 1950,M12,271.2,,, 1951,M01,267.5,,, 1951,M02,268.3,,, 1951,M03,268.5,,, 1951,M04,269.5,,, 1951,M05,270.4,,, 1951,M06,271.6,,, 1951,M07,271.1,,, 1951,M08,270.1,,, 1951,M09,271.3,,, 1951,M10,272.2,,, 1951,M11,273.2,,, 1951,M12,274.6,,, 1952,M01,271.2,,, 1952,M02,271.8,,, 1952,M03,271.1,,, 1952,M04,271.2,,, 1952,M05,272.9,,, 1952,M06,273.9,,, 1952,M07,273.6,,, 1952,M08,273.2,,, 1952,M09,273.7,,, 1952,M10,274.9,,, 1952,M11,276,,, 1952,M12,276.5,,, 1953,M01,273.2,,, 1953,M02,273.7,,, 1953,M03,274.5,,, 1953,M04,275.5,,, 1953,M05,276.5,,, 1953,M06,277.7,,, 1953,M07,276.3,,, 1953,M08,276.9,,, 1953,M09,278.7,,, 1953,M10,280.5,,, 1953,M11,281.4,,, 1953,M12,283.1,,, 1954,M01,278.8,,, 1954,M02,278.9,,, 1954,M03,279.6,,, 1954,M04,279,,, 1954,M05,280.2,,, 1954,M06,281.8,,, 1954,M07,280.4,,, 1954,M08,281.1,,, 1954,M09,282.8,,, 1954,M10,284.1,,, 1954,M11,285.2,,, 1954,M12,286.3,,, 1955,M01,283,,, 1955,M02,283.8,,, 1955,M03,285.1,,, 1955,M04,287,,, 1955,M05,287.6,,, 1955,M06,290,,, 1955,M07,290.3,,, 1955,M08,290.5,,, 1955,M09,293.7,,, 1955,M10,294.8,,, 1955,M11,296.3,,, 1955,M12,295,,, 1956,M01,292.1,,, 1956,M02,296.5,,, 1956,M03,297.9,,, 1956,M04,299.2,,, 1956,M05,299.7,,, 1956,M06,300.6,,, 1956,M07,299.1,,, 1956,M08,299.4,,, 1956,M09,300.5,,, 1956,M10,301.5,,, 1956,M11,300.2,,, 1956,M12,303.7,,, 1957,M01,299.7,,, 1957,M02,300.6,,, 1957,M03,300.8,,, 1957,M04,301.3,,, 1957,M05,301.8,,, 1957,M06,303,,, 1957,M07,301.3,,, 1957,M08,299.4,,, 1957,M09,302.8,,, 1957,M10,304,,, 1957,M11,305.3,,, 1957,M12,305.2,,, 1958,M01,301.4,,, 1958,M02,301.1,,, 1958,M03,301.7,,, 1958,M04,300.5,,, 1958,M05,301.2,,, 1958,M06,301.5,,, 1958,M07,300.3,,, 1958,M08,301.4,,, 1958,M09,301.1,,, 1958,M10,302.7,,, 1958,M11,302.7,,, 1958,M12,300.6,,, 1959,M01,300.9,,, 1959,M02,301.2,,, 1959,M03,302.3,,, 1959,M04,302.6,,, 1959,M05,303.8,,, 1959,M06,305.3,,, 1959,M07,306.9,,, 1959,M08,306.4,,, 1959,M09,308,,, 1959,M10,308.9,,, 1959,M11,307.9,,, 1959,M12,311.8,,, 1960,M01,307.5,,, 1960,M02,308.4,,, 1960,M03,309.6,,, 1960,M04,310.4,,, 1960,M05,311.1,,, 1960,M06,313.9,,, 1960,M07,313.9,,, 1960,M08,312.8,,, 1960,M09,312.3,,, 1960,M10,313.8,,, 1960,M11,315.3,,, 1960,M12,314.9,,, 1961,M01,312.1,,, 1961,M02,310.7,,, 1961,M03,312,,, 1961,M04,312,,, 1961,M05,312,,, 1961,M06,313.6,,, 1961,M07,313.2,,, 1961,M08,312.3,,, 1961,M09,312.3,,, 1961,M10,313.5,,, 1961,M11,313.4,,, 1961,M12,314.1,,, 1962,M01,310.3,,, 1962,M02,310.9,,, 1962,M03,311.7,,, 1962,M04,313.4,,, 1962,M05,312.6,,, 1962,M06,315.6,,, 1962,M07,315.7,,, 1962,M08,318.5,,, 1962,M09,318.6,,, 1962,M10,320.6,,, 1962,M11,322.9,,, 1962,M12,299.9,,, 1963,M01,297.4,,, 1963,M02,298.2,,, 1963,M03,299.7,,, 1963,M04,318.2,,, 1963,M05,320,,, 1963,M06,322.3,,, 1963,M07,322,,, 1963,M08,321.7,,, 1963,M09,321.1,,, 1963,M10,321.8,,, 1963,M11,320.4,,, 1963,M12,322.9,,, 1964,M01,318.9,,, 1964,M02,319.2,,, 1964,M03,320.3,,, 1964,M04,320.8,,, 1964,M05,321.7,,, 1964,M06,323.3,,, 1964,M07,322.2,,, 1964,M08,321.7,,, 1964,M09,320.8,,, 1964,M10,323.2,,, 1964,M11,324.2,,, 1964,M12,328.4,,, 1965,M01,325.1,,, 1965,M02,326.8,,, 1965,M03,327.8,,, 1965,M04,327.9,,, 1965,M05,327.4,,, 1965,M06,332.3,,, 1965,M07,334.1,,, 1965,M08,333,,, 1965,M09,332.9,,, 1965,M10,335.8,,, 1965,M11,335.9,,, 1965,M12,337.6,,, 1966,M01,334.2,,, 1966,M02,335.5,,, 1966,M03,331.8,,, 1966,M04,336.8,,, 1966,M05,334.7,,, 1966,M06,337.2,,, 1966,M07,337,,, 1966,M08,335.7,,, 1966,M09,338.6,,, 1966,M10,339.6,,, 1966,M11,340.2,,, 1966,M12,341.5,,, 1967,M01,338.2,,, 1967,M02,339.3,,, 1967,M03,340.6,,, 1967,M04,340.9,,, 1967,M05,342.1,,, 1967,M06,343.9,,, 1967,M07,342.2,,, 1967,M08,341.1,,, 1967,M09,340,,, 1967,M10,339.1,,, 1967,M11,338.7,,, 1967,M12,341.2,,, 1968,M01,337.4,,, 1968,M02,338.8,,, 1968,M03,338.9,,, 1968,M04,338.4,,, 1968,M05,340.3,,, 1968,M06,343.5,,, 1968,M07,343.7,,, 1968,M08,346.4,,, 1968,M09,345.5,,, 1968,M10,348.1,,, 1968,M11,349.6,,, 1968,M12,351.6,,, 1969,M01,348.5,,, 1969,M02,350.3,,, 1969,M03,350.6,,, 1969,M04,350.9,,, 1969,M05,351.1,,, 1969,M06,354,,, 1969,M07,353.9,,, 1969,M08,353.8,,, 1969,M09,352.6,,, 1969,M10,355.8,,, 1969,M11,357.6,,, 1969,M12,358.7,,, 1970,M01,354.7,,, 1970,M02,356,,, 1970,M03,356.9,,, 1970,M04,357.4,,, 1970,M05,357.2,,, 1970,M06,358.7,,, 1970,M07,358.7,,, 1970,M08,358.6,,, 1970,M09,357,,, 1970,M10,359.1,,, 1970,M11,360.3,,, 1970,M12,359.5,,, 1971,M01,357,,, 1971,M02,359,,, 1971,M03,356.4,,, 1971,M04,356.3,,, 1971,M05,356.9,,, 1971,M06,358.7,,, 1971,M07,358.9,,, 1971,M08,358,,, 1971,M09,357.5,,, 1971,M10,359.7,,, 1971,M11,361.3,,, 1971,M12,363.2,,, 1972,M01,361.6,,, 1972,M02,362.9,,, 1972,M03,363.7,,, 1972,M04,364,,, 1972,M05,365.6,,, 1972,M06,367.9,,, 1972,M07,366.7,,, 1972,M08,366.6,,, 1972,M09,366.4,,, 1972,M10,369.2,,, 1972,M11,372,,, 1972,M12,372.6,,, 1973,M01,370.1,,, 1973,M02,370.9,,, 1973,M03,369.6,,, 1973,M04,370.6,,, 1973,M05,369.9,,, 1973,M06,372,,, 1973,M07,371,,, 1973,M08,370.8,,, 1973,M09,367.5,,, 1973,M10,368.6,,, 1973,M11,369.8,,, 1973,M12,370.6,,, 1974,M01,367,,, 1974,M02,367.6,,, 1974,M03,366.1,,, 1974,M04,364.1,,, 1974,M05,364.1,,, 1974,M06,369,,, 1974,M07,368.5,,, 1974,M08,367.5,,, 1974,M09,368.3,,, 1974,M10,369.3,,, 1974,M11,367,,, 1974,M12,367.1,,, 1975,M01,365.6,,, 1975,M02,363.7,,, 1975,M03,361.7,,, 1975,M04,361.6,,, 1975,M05,360.8,,, 1975,M06,361.9,,, 1975,M07,358.9,,, 1975,M08,359.8,,, 1975,M09,360.3,,, 1975,M10,359.8,,, 1975,M11,361.4,,, 1975,M12,362.5,,, 1976,M01,362,,, 1976,M02,362.1,,, 1976,M03,363.2,,, 1976,M04,363.1,,, 1976,M05,366.1,,, 1976,M06,369.7,,, 1976,M07,369.7,,, 1976,M08,370.5,,, 1976,M09,372.2,,, 1976,M10,373.1,,, 1976,M11,374.1,,, 1976,M12,374.5,,, 1977,M01,372.3,,, 1977,M02,374,,, 1977,M03,373.2,,, 1977,M04,373.9,,, 1977,M05,376.5,,, 1977,M06,380.5,,, 1977,M07,381.5,,, 1977,M08,382.2,,, 1977,M09,383.3,,, 1977,M10,383.3,,, 1977,M11,385.5,,, 1977,M12,387.3,,, 1978,M01,385.9,,, 1978,M02,386.9,,, 1978,M03,387.6,,, 1978,M04,388,,, 1978,M05,389.6,,, 1978,M06,395,,, 1978,M07,395,,, 1978,M08,395.9,,, 1978,M09,385.5,,, 1978,M10,389.9,,, 1978,M11,398.3,,, 1978,M12,400.5,,, 1979,M01,398.4,,, 1979,M02,400.6,,, 1979,M03,401.4,,, 1979,M04,400.4,,, 1979,M05,400.9,,, 1979,M06,405.1,,, 1979,M07,404.6,,, 1979,M08,403,,, 1979,M09,402.4,,, 1979,M10,404.3,,, 1979,M11,407.3,,, 1979,M12,407.4,,, 1980,M01,405.7,,, 1980,M02,405.8,,, 1980,M03,404.5,,, 1980,M04,403.6,,, 1980,M05,403,,, 1980,M06,404.6,,, 1980,M07,401.8,,, 1980,M08,399.3,,, 1980,M09,398.8,,, 1980,M10,400.6,,, 1980,M11,401.9,,, 1980,M12,403.9,,, 1981,M01,400.2,,, 1981,M02,401,,, 1981,M03,400.4,,, 1981,M04,399.6,,, 1981,M05,401.9,,, 1981,M06,403.5,,, 1981,M07,403.3,,, 1981,M08,403.6,,, 1981,M09,402.2,,, 1981,M10,404.3,,, 1981,M11,405.4,,, 1981,M12,407.2,,, 1982,M01,401.7,99.4,104.8, 1982,M02,402.9,98.5,106.3, 1982,M03,401.5,99.9,105.8, 1982,M04,400.7,99.7,106.3, 1982,M05,400.8,101.7,107, 1982,M06,402.2,101.7,107.7, 1982,M07,402,103.1,107.7, 1982,M08,401,102.8,107.3, 1982,M09,401.1,103.1,107.2, 1982,M10,401.7,103.6,107.5, 1982,M11,403.9,103.4,108.1, 1982,M12,405.6,103.6,108.2, 1983,M01,402.3,102.4,108.5, 1983,M02,402.3,103.7,108.5, 1983,M03,404.2,103.9,108.4, 1983,M04,404.7,104.3,108.6, 1983,M05,406.6,105.5,108.8, 1983,M06,409.7,107.1,110.1, 1983,M07,407.7,105.9,110.2, 1983,M08,409.3,107,109.9, 1983,M09,411.7,106.4,110.2, 1983,M10,413.2,106.3,109.8, 1983,M11,416.2,106.6,110, 1983,M12,418.2,107.3,110, 1984,M01,414.5,107.9,108.8, 1984,M02,416,108.6,109.2, 1984,M03,417,109.5,109.2, 1984,M04,418,109.8,109.4, 1984,M05,418.5,111.1,110, 1984,M06,422.3,111.6,111.9, 1984,M07,422.3,111.6,111.9, 1984,M08,422.8,112.1,111.4, 1984,M09,424,112.3,111.3, 1984,M10,426.2,112.8,111, 1984,M11,430.3,112.8,111.8, 1984,M12,430.5,113.3,111.9, 1985,M01,428,113.4,111.6, 1985,M02,428.7,114,112, 1985,M03,429.3,113.9,112.1, 1985,M04,428.8,113.9,112, 1985,M05,430.4,114.3,112.6, 1985,M06,432.3,115.5,113.1, 1985,M07,431.6,114.7,112.9, 1985,M08,432,115.1,112.7, 1985,M09,429.3,114.7,111.9, 1985,M10,432.7,114.8,111.8, 1985,M11,438.7,114.3,111.6, 1985,M12,440,114.3,111.6, 1986,M01,435.3,113.3,111.7, 1986,M02,435.6,113.3,111.4, 1986,M03,435.4,114,111.6, 1986,M04,436.5,113.6,111.6, 1986,M05,437.9,114,112.2, 1986,M06,441.7,113.8,112.6, 1986,M07,441.8,113,112.7, 1986,M08,441.7,113.4,112.1, 1986,M09,443.5,114.2,111.8, 1986,M10,446.9,114,112.6, 1986,M11,449.6,112.7,113.2, 1986,M12,450.2,112.7,113.4, 1987,M01,446.3,110.3,114, 1987,M02,447.2,110.6,113.4, 1987,M03,447.1,110.5,113.8, 1987,M04,446.1,109.3,114.2, 1987,M05,446.7,109.2,114.5, 1987,M06,449,107.9,115.5, 1987,M07,449.2,105.5,115.1, 1987,M08,449.3,104.6,115.1, 1987,M09,451.2,105.2,114.3, 1987,M10,453.7,106.2,114.7, 1987,M11,457,109.4,114.4, 1987,M12,456.8,109,115.4, 1988,M01,453.7,107.4,115.3, 1988,M02,453.3,107.8,115.5, 1988,M03,452.3,108.6,115.7, 1988,M04,452.1,108.4,115.8, 1988,M05,452.4,108.9,116.5, 1988,M06,455.2,108.9,117, 1988,M07,453.6,108.3,118.1, 1988,M08,451.8,108.5,117.8, 1988,M09,451.9,108.7,117.4, 1988,M10,453.6,108.9,116.9, 1988,M11,455.6,109.6,117, 1988,M12,455.6,110.2,117.5, 1989,M01,453.3,108.7,116.9, 1989,M02,451.9,109,117.3, 1989,M03,450.4,109,116.6, 1989,M04,449.5,110,117, 1989,M05,450.1,110.6,117.8, 1989,M06,453.3,110.7,118.1, 1989,M07,451.5,110.9,118, 1989,M08,450.9,111.5,118.7, 1989,M09,450.1,112.4,118, 1989,M10,451.6,112.3,118, 1989,M11,455.3,112.9,118.2, 1989,M12,455.8,113.5,118.4, 1990,M01,454.7,113.2,118,32.2 1990,M02,455.1,113.7,118.3,32.6 1990,M03,454.8,114.1,117.9,33.1 1990,M04,454,113.7,118,33.6 1990,M05,455.4,113.9,118,33.2 1990,M06,458.4,113.7,118.1,33.9 1990,M07,457.1,113.9,118.5,33.6 1990,M08,456.7,114.3,118.4,33.6 1990,M09,456.2,114.5,118.3,32.6 1990,M10,456.3,114.2,118.5,32.6 1990,M11,455.7,114.1,118.5,32.3 1990,M12,454.3,113.6,118.4,32.2 1991,M01,449.2,113.6,117.5,32.2 1991,M02,445.7,113.6,117,31.8 1991,M03,443.3,113.2,116.4,32 1991,M04,441.4,112.8,116.1,31.6 1991,M05,442,112.5,116.6,31.6 1991,M06,441.1,112.4,116.3,31.8 1991,M07,438.9,112.3,116.1,31.7 1991,M08,437.2,112.3,116.1,31.5 1991,M09,437,112.2,115,31.3 1991,M10,437.6,112,114.6,31.5 1991,M11,438.3,113.1,114.8,31.5 1991,M12,438.4,113.1,114.2,31.4 1992,M01,434,112.9,112.6,31.1 1992,M02,432.7,113.1,112.1,31.1 1992,M03,431.2,113,111.8,31.5 1992,M04,431.2,113.2,112,31.8 1992,M05,431.3,113.3,112.8,31.6 1992,M06,433.5,113.4,113.5,31.9 1992,M07,432.9,113.6,113,31.4 1992,M08,432.9,113.7,111.8,31.9 1992,M09,433.9,114.5,112,32 1992,M10,434.8,114.6,111.7,31.4 1992,M11,436.3,114.9,112.2,31.3 1992,M12,436.8,114.9,112.4,31.6 1993,M01,431.6,115,111.8,31.3 1993,M02,432.6,115.2,111.6,31.5 1993,M03,431.5,115.2,111.6,32 1993,M04,430.8,115.6,112.7,32.3 1993,M05,431.6,115.3,112.8,32.5 1993,M06,433.9,114.6,113.8,32.8 1993,M07,433.6,115.3,113.8,32.3 1993,M08,434,115.4,113.5,31.9 1993,M09,432.9,115.4,112.6,31 1993,M10,432.5,115.5,113.1,31.6 1993,M11,433.8,115.9,112.8,31.8 1993,M12,434.6,116.3,112.8,31.1 1994,M01,430.7,116.5,112.3,33.1 1994,M02,429.7,116.8,112.2,32.8 1994,M03,429.3,117.1,112.5,32.8 1994,M04,428.7,116.8,112.2,33 1994,M05,429,116.9,112.3,32.8 1994,M06,431.8,116.9,113.4,33 1994,M07,430.9,117.4,113.1,33 1994,M08,431.7,118.5,112.7,33.1 1994,M09,430,119,113.3,32.5 1994,M10,431.1,118.9,113.3,32.7 1994,M11,429.2,119.8,113.5,33.1 1994,M12,433.8,120.5,113.8,33.2 1995,M01,430.7,119.4,112.1,33.2 1995,M02,430.7,120.2,112.1,33.5 1995,M03,430.4,121.4,112.5,33.8 1995,M04,429.3,120.5,111.9,33.9 1995,M05,428.6,121.1,112.4,34 1995,M06,431.3,121.2,112.7,35 1995,M07,430.3,121.3,111.9,34.9 1995,M08,428,122.5,112.5,35.4 1995,M09,427.3,122.9,112.5,34.5 1995,M10,428.6,123.3,112.6,35.3 1995,M11,430.5,123.8,112.6,35 1995,M12,430.7,124.4,113.2,35.2 1996,M01,424.3,125,112.1,35.4 1996,M02,424.3,125.1,112.2,36.3 1996,M03,423.8,126.1,112,36.1 1996,M04,422.5,126,112.4,35.4 1996,M05,422.6,126,112.8,35 1996,M06,424.8,126.4,112.9,35.4 1996,M07,423.8,125.9,112.8,35.7 1996,M08,422.2,127.3,112.4,36.3 1996,M09,421.8,127.5,112.6,35.9 1996,M10,423.7,127.7,113.5,35.8 1996,M11,423.1,127.7,113.3,35.9 1996,M12,424.3,128.3,113.3,36 1997,M01,420.6,127.9,111.9,36.4 1997,M02,420.4,127.7,112.3,37.2 1997,M03,420,127.4,113.3,37.9 1997,M04,420.5,127.7,112.8,38.7 1997,M05,422.5,128.4,113.4,38.4 1997,M06,425,127.9,112.8,39.3 1997,M07,424.8,128,112.7,39.5 1997,M08,424.8,127.8,112.5,39 1997,M09,424.2,128.2,113.6,38.8 1997,M10,424.9,129.3,114,39.9 1997,M11,427.2,129.5,115.3,40.1 1997,M12,427.7,129.1,115.1,40.3 1998,M01,425.4,129,113.9,40.5 1998,M02,426.1,129.4,113.7,40.6 1998,M03,424.3,130.9,113.3,40.8 1998,M04,424.6,130.4,114.7,41 1998,M05,424.3,130.9,114.7,41.1 1998,M06,426.5,131.8,115.4,41.2 1998,M07,425.5,130.9,114.6,42 1998,M08,425.1,131.6,114.8,41.9 1998,M09,424.1,132.7,115.6,42.9 1998,M10,424.9,131.9,116.1,42.4 1998,M11,426.9,129.1,117,43.1 1998,M12,427.5,129.4,116.6,43 1999,M01,423.3,130,115.8,43.7 1999,M02,423,130,115.5,44.3 1999,M03,422.8,130.2,115.2,44.8 1999,M04,421.3,130.6,115.6,45.5 1999,M05,422.6,131.5,115.3,45.2 1999,M06,424.4,131.7,115,46 1999,M07,425.4,131.6,114.8,46.5 1999,M08,424.7,132.3,115.4,47 1999,M09,424.7,133.2,116.1,46.7 1999,M10,426.1,133.2,116.3,47.9 1999,M11,427,133.6,116.9,48.3 1999,M12,428.5,134.7,116.9,48.4 2000,M01,424.2,135.4,116,49.1 2000,M02,424.5,136.3,116.1,50.6 2000,M03,423.5,137.1,116.3,51.4 2000,M04,421.5,137.1,116.5,51.1 2000,M05,421.8,135.2,116.6,52.1 2000,M06,423.6,135.2,117.7,53.7 2000,M07,423.3,134.9,118.3,55 2000,M08,422.5,135.1,117.6,55.8 2000,M09,420.6,136.7,116.9,55.9 2000,M10,420.1,136.6,116.5,55.9 2000,M11,422.5,137,116.4,56.3 2000,M12,422.9,137.6,114.1,56.4 2001,M01,418.7,137,113.8,55 2001,M02,416.4,136.7,114.4,56.1 2001,M03,413.5,137.1,114,56 2001,M04,409.7,135.8,113.9,55.2 2001,M05,408.6,134.7,113.5,53.5 2001,M06,408.3,135,114.1,52.4 2001,M07,404.2,134.4,115,52.2 2001,M08,402.4,134.2,116,52.5 2001,M09,400,132.4,115.1,51.9 2001,M10,399.8,132.7,113.9,51.9 2001,M11,399.2,132.5,115,51.5 2001,M12,399.3,132.6,114.8,50.9 2002,M01,393.3,133,112,49.4 2002,M02,390.8,132,111.5,49.8 2002,M03,389.3,131.9,111.3,47.8 2002,M04,387.2,131.5,109.4,47.9 2002,M05,386,130.8,110.3,47.5 2002,M06,388.3,131,111,48.8 2002,M07,387.7,130.5,110.6,48.1 2002,M08,386.9,129.4,111.3,47.9 2002,M09,387.4,127.6,111.7,47.1 2002,M10,387.5,127,110.7,46.5 2002,M11,390.4,128.3,111.2,46.5 2002,M12,391.4,128.1,112.5,45.8 2003,M01,384.8,127.9,112,44.9 2003,M02,386.2,127.8,111.3,45.3 2003,M03,385.4,129.1,110.7,45.6 2003,M04,382.4,128.5,109.7,44.7 2003,M05,381.1,127.9,109,44.6 2003,M06,381.7,127.7,109.9,46 2003,M07,380.6,126.7,110.7,46.2 2003,M08,378.1,126.4,110.6,45.1 2003,M09,377.9,127.3,110.8,45.4 2003,M10,378.5,127,109.4,45 2003,M11,379.1,127.4,111.4,43.6 2003,M12,380,128.7,112,44.8 2004,M01,377.3,127.3,109.9,44.5 2004,M02,377.7,127.7,110,45.1 2004,M03,376.8,127.8,111.5,45 2004,M04,376.3,127.5,110.6,45.7 2004,M05,374.6,128.3,111.5,45.5 2004,M06,376.9,128.4,111.6,45.5 2004,M07,376.1,127.1,112.1,45.2 2004,M08,374.7,127.8,111.7,45 2004,M09,375.1,127.6,111.3,44.8 2004,M10,373,128.4,112.1,45.7 2004,M11,375.2,128.6,112.4,45.8 2004,M12,374,129.4,113.5,45.9 2005,M01,369.6,126.9,113.3,45.6 2005,M02,371,126.9,111.7,46 2005,M03,371.5,127.7,111,45.6 2005,M04,369.4,127.5,109.7,45.8 2005,M05,368.2,126.8,109.4,46 2005,M06,369.5,127.2,111.3,46.7 2005,M07,370.3,127.1,111.9,46.4 2005,M08,370,128.5,111.5,46.5 2005,M09,370.6,127.4,110.9,45.9 2005,M10,370.1,128.5,111.7,46.6 2005,M11,369.6,127.3,111,46.5 2005,M12,369.6,128.5,111.5,46.2 2006,M01,364.6,126.2,110.3,46.6 2006,M02,365.7,126.7,110.9,46.6 2006,M03,365.5,126.5,111.5,46.9 2006,M04,363,126.1,112.4,46.2 2006,M05,358.8,125.9,113,46.5 2006,M06,359.3,126.9,113.2,47.9 2006,M07,357,126.1,112.1,48.1 2006,M08,356,126.5,112.3,48.4 2006,M09,357.3,126.3,111.9,46.4 2006,M10,356.6,127,110.3,45.8 2006,M11,356.9,127.3,110.8,46.8 2006,M12,357,127.6,112.1,46.8 2007,M01,352.9,127.4,109.8,47.3 2007,M02,353,127.2,110.8,48.4 2007,M03,351.8,125.9,110.1,49.6 2007,M04,348.9,125.8,110.4,48.6 2007,M05,345.9,125,110.2,50 2007,M06,347.6,125.3,111.2,51.5 2007,M07,346.7,125,109.9,51.4 2007,M08,343.7,126.5,109.6,51.1 2007,M09,341.2,127.7,110.4,50.1 2007,M10,343.2,127.1,109.7,49.9 2007,M11,344.2,127,111.3,49.8 2007,M12,342.4,127,110.2,50.1 2008,M01,339.3,126.2,108.5,50.6 2008,M02,337.9,126.7,109.2,51.5 2008,M03,335,127.2,108.1,52.4 2008,M04,333.4,127,107.1,52 2008,M05,329.1,126.8,107.9,51.4 2008,M06,327.1,125.5,108.8,52.3 2008,M07,323.7,125.2,108.9,52.2 2008,M08,318.4,124.1,107.9,51.8 2008,M09,315.7,124.5,106.2,50.9 2008,M10,313.5,125.8,105.1,51.6 2008,M11,309.7,125.6,105.8,50.9 2008,M12,307.1,123.8,104.7,50.3 2009,M01,298.6,123,102.3,49.8 2009,M02,294.2,122.5,99.9,49.7 2009,M03,289.1,121.7,98.7,49.6 2009,M04,284.3,120.6,97.3,49 2009,M05,277.5,119,97.2,49.3 2009,M06,274,118.1,96.6,49.2 2009,M07,270,116.4,95.7,50 2009,M08,267.5,115.9,95.1,49 2009,M09,268.6,115.4,95,48.2 2009,M10,266.4,116,95.1,48 2009,M11,265.1,115.7,94.7,47.8 2009,M12,265.1,116,95,48 2010,M01,260.9,116.7,92.4,47.3 2010,M02,257.9,117.6,92.3,47.2 2010,M03,256.6,117.8,92.3,47.9 2010,M04,255.6,117.6,91,48.2 2010,M05,254.4,117,91.4,48 2010,M06,254,116.6,91.7,49.1 2010,M07,253,116.5,92,49.1 2010,M08,251.4,117,92.7,47.7 2010,M09,250.9,117.3,93.4,48.5 2010,M10,250,117.8,94,48.8 2010,M11,249.6,118.7,93.9,48.2 2010,M12,248.7,117.4,93.8,49.2 2011,M01,246.6,117.5,92,48.6 2011,M02,245.7,116.7,93.4,49.2 2011,M03,244.5,115.6,92.7,49.4 2011,M04,244.1,115.7,91.9,49.4 2011,M05,241.9,115.3,91.8,50.2 2011,M06,241.3,116.4,92.8,50.4 2011,M07,240.3,115.8,92.8,50.9 2011,M08,239,116.3,92.3,49.6 2011,M09,238,117.4,93.2,49.5 2011,M10,237,118.5,93.2,50.7 2011,M11,236.3,119,92.8,50.3 2011,M12,234.9,119.8,92.2,50.3 2012,M01,230.4,119,91.2,50.8 2012,M02,229.3,119.6,91.7,51.4 2012,M03,228.1,121,92.1,51.9 2012,M04,227.2,120.3,92.8,52.5 2012,M05,225.2,120.2,92.3,51.3 2012,M06,224.4,121.9,91,51.9 2012,M07,223.4,120,90.3,51.8 2012,M08,222.3,119.9,89.3,51.7 2012,M09,222.9,122,89.7,52.7 2012,M10,222.4,121.3,89.5,53.9 2012,M11,221.3,121.2,90.5,53.1 2012,M12,221.1,122.7,91.1,52.4 2013,M01,217.8,121.9,89.9,52 2013,M02,218.1,121.5,90.1,53 2013,M03,217.3,122.1,90.4,52.2 2013,M04,215.9,123.2,89.9,53.1 2013,M05,212.9,122.3,89.3,53.7 2013,M06,212.6,124.1,90.3,53.8 2013,M07,212,123.7,89.9,53.9 2013,M08,210.3,123.8,89.9,54.7 2013,M09,210.6,125.4,91.1,54.1 2013,M10,210.3,126.9,91.6,54.5 2013,M11,211.2,128.1,91.4,55 2013,M12,210.2,127.8,90.4,55.1 2014,M01,206.8,128.1,89.8,54.5 2014,M02,205.6,128.8,89.6,55.2 2014,M03,204.7,129.2,90,54.5 2014,M04,203.6,129.2,91.3,55.4 2014,M05,201.3,128.4,92,55.1 2014,M06,201.7,131.3,93,55.9 2014,M07,200.8,131.6,92.4,57.7 2014,M08,199.8,133.5,93.7,57.2 2014,M09,201.5,131.9,94.3,57.7 2014,M10,201,131.8,92.9,58.9 2014,M11,199.9,133,92.5,58.9 2014,M12,200.4,132.6,92.5,59.3 2015,M01,196.5,131.7,93.8,59.5 2015,M02,196.5,131.5,94.3,59.9 2015,M03,195,132.5,94.5,60 2015,M04,194.1,132.4,95.3,60.3 2015,M05,194,131.3,94.4,59.8 2015,M06,192.8,131.6,94.6,61.9 2015,M07,190.4,131.5,94.6,61.5 2015,M08,188.3,130.8,93.4,62.2 元素时,path属性有一堆d个值。

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

这里有几个问题。

首先,你的行函数正在使用d.Month,但它应该是d.date:

var line = d3.svg
  .line()
  .interpolate('basis')
  .x(function(d) {
    return x(d.date); //<-- should be d.date
  })
  .y(function(d) {
    return y(d.jobs);
  });

其次,如何设置y.domain()返回undefined。您可以使用类似的东西来正确设置它:

  y.domain(
    d3.extent(d3.merge(industries.map(function(d){return d.values})), function(d){ return d.jobs })
  );

修复这些问题后,这里是results

答案 1 :(得分:0)

rObj.Month = timeFormat.parse(obj.Year + ' ' + obj.Period);

您正在解析的字符串看起来像'2015 M05',我怀疑它不是它想要的。也许:

rObj.Month = timeFormat.parse(obj.Year + ' ' + obj.Period.replace(/M/, '');

虽然您似乎仍然使用日期/时间/日期时间作为obj.Month的分配值,但也许可以:

rObj.Month = timeFormat.parse(obj.Year + ' ' + obj.Period.replace(/M/, '').Month;

希望这有帮助。