2015-03-13 83 views
0

我在完成xAxis時遇到問題。我是一個使用D3的newby,並且使用D3 Date方法丟失了。任何人都可以幫我找出導致undefined is not a function的問題。我會很感激的幫助下,這裏是我的代碼:xAxis(日期):未定義不是函數

的index.html

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Document</title> 
    <link rel="stylesheet" type="text/css" href="styles/main.css"/> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> 
</head> 
<body> 
    <h1>Hello worlds</h1> 
    <div id="wrapper"></div> 
    <script type="text/javascript" src="scripts/app.js"></script> 
</body> 
</html> 

scripts.js中

var height = 800, 
    width = 500, 
    padding = 50; 

var vizz = d3.select('#wrapper') 
      .append('svg') 
      .attr('height', height + padding * 2) 
      .attr('width', width + padding * 2) 
      .append('g') 
      .attr('id', 'visual') 
      .attr('transform', 'translate(' + padding + ',' + padding + ')'); 


var yScale = d3.scale.linear().range([height, 0]); 
var xScale = d3.time.scale().range([0, width]); 
var parseTime = d3.time.format("%Y%m%D"); 


var xAxis = d3.svg.axis().scale(xScale).orient("botom").tricks(8); 
var yAxis = d3.svg.axis().scale(yScale).orient("left").tricks(20); 



d3.csv('data/climate_data.csv', function(data){ 

    yDomain = d3.extent(data, function(element){ 
     return parseInt(element.TMAX) 
    }); 
    xDomain = d3.extent(data, function(element){ 
     return parseTime.parse(element.DATE) 
    }); 


    yScale.domain(yDomain); 
    xScale.domain(xDomain); 


    dots = vizz.selectAll('circle') 
      .data(data) 
      .enter() 
      .append('circle'); 


    dots.attr('r', function (d){ 
     return d.TMAX/100; }) 
    .attr('cx', function(d) {return Math.max(0 + padding, Math.random() * width - padding)}) 
    .attr('cy', function(d) { 
     return yScale(d.TMAX); 
    }); 

}); 

數據/ climate_data.csv

STATION,STATION_NAME,ELEVATION,LATITUDE,LONGITUDE,DATE,PRCP,TMAX,TMIN,TOBS 
GHCND:USC00356749,PORTLAND KGW TV OR US,48.5,45.51667,-122.68333,19730801,0,294,133,217 
GHCND:USC00356749,PORTLAND KGW TV OR US,48.5,45.51667,-122.68333,19730802,0,300,128,217 
GHCND:USC00356749,PORTLAND KGW TV OR US,48.5,45.51667,-122.68333,19730803,0,289,133,172 
+0

你在哪裏得到這個錯誤? – 2015-03-13 17:12:12

+0

在xAxis定義中。它說'未定義不是一個函數' – 2015-03-13 17:17:18

+0

你寫技巧()而不是蜱() – ee2Dev 2015-03-13 17:26:40

回答