我正在使用json Chart Link的d3js区域图示例。 当我们改变数据输入但是没有数据显示在图表中时,x和y轴正在改变。但是我使用了控制台日志。所以我看到数据已经存在于x和y轴上。我们不知道为什么数据不会出现在图表中。
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("%d-%b-%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 area = d3.svg.area()
.x(function(d) { return x(d.timeStamp); })
.y0(height)
.y(function(d) {return y(d.memberAverageLoadAverage); });
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 + ")");
var json1=[{"clusterId":"","timeStamp":1437063744524,"memberAverageLoadAverage":51,"memberId":""},
{"clusterId":"","timeStamp":1437069850060,"memberAverageLoadAverage":5,"memberId":""},
{"clusterId":"","timeStamp":1437069910059,"memberAverageLoadAverage":6,"memberId":""},
{"clusterId":"","timeStamp":1437069970060,"memberAverageLoadAverage":15,"memberId":""},
{"clusterId":"","timeStamp":1437070030056,"memberAverageLoadAverage":20,"memberId":""}];
var data = json1;
x.domain(d3.extent(data, function(d) { return d.timeStamp; }));
y.domain([-2, d3.max(data, function(d) { console.info(d.memberAverageLoadAverage); return d.memberAverageLoadAverage; })]);
svg.append("path")
.datum(data)
.attr("class", "area")
.attr("d", area);
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("memberAverageLoadAverage");
Any help will be really appreciated.
答案 0 :(得分:1)
在
SELECT * FROM table ORDER BY office id
您应该使用var area = d3.svg.area()
.x(function(d) { return x(d.timeStamp); })
.y0(height)
.y(function(d) {return y(d.memberAverageLoadAverage); });
代替.y1(...)
。
我认为应该这样做!