代码一样,怎么我的报错呢?
为啥我的一直报错data is undefined??? 我都仔细对比了代码,是一样的呀!
为啥我的一直报错data is undefined??? 我都仔细对比了代码,是一样的呀!
2015-10-22
var width = 500,
height = 250,
margin={left:50, top:30, right:20, bottom:20},
g_width = width - margin.left - margin.right,
g_height = height - margin.top - margin.bottom;
//svg
var svg = d3.select("#container")
.append("svg:svg")
//width, height
.attr("width", width)
.attr("height",height)
var g = d3.select("svg")
.append("g")
.attr("transform", "translate("+margin.left+", "+margin.top+")")
var data = [1,3,5,7,8,4,3,7];
var scale_x = d3.scale.linear()
.domain([0, data.length - 1])
.range([0, g_width])
var scale_y = d3.scale.linear()
.domain([0, d3.max(data)])
.range([0, g_height])
var line_generator = d3.svg.line()
.x(function(d, i){return scale_x(i);}) //0,1,2,3...
.y(function(d){ return scale_y(d);}) //1,3,5...
.interpolate("cardinal")
d3.select("g")
.append("path")
.attr("d", line_generator(data)) //d="M1,0L20,40L40,50L100,100L0,200", d - path data
var width=500, height=250, margin={left:50,top:30,right:20,bottom:20}, g_width = width-margin.left-margin.right, g_height = height-margin.top-margin.bottom; //svg var svg = d3.select("#container") .append("svg") //width,height .attr("width",width) .attr("height",height) var g = d3.select("svg") .append("g") .attr("transform","translate("+margin.left+","+margin.top+")") var data = [1,3,6,9,2,7,3]; var scale_x = d3.scale.linear() .domain([0,data.length-1]) .range([0,g_width]) var scale_y = d3.scale.linear() .domain([0,d3.max(data)]) .range([0,g_height]) var line_generator = d3.svg.line() .x(function(d,i){return scale_x(i);})//0,1,2,... .y(function(d){return scale_y(d);})//1,2,3,... .interpolate("cardinal") d3.select("g") .append("path") .attr("d",line_generator)
老师,这是我的js代码,能麻烦您看下吗?我找了好久都没找到错误!
举报