[英]Bars on D3 Bar Graph not showing up
I've been staring at this code for hours now and maybe it's obvious or just needs a fresh set of eyes, but I am desperate to figure out why the bars on the graph aren't showing up??我已经盯着这段代码看了几个小时了,也许这很明显,或者只是需要一双新的眼睛,但我很想弄清楚为什么图表上的条形没有出现?
Here is the fiddle for it: http://jsfiddle.net/u7zs3jwo/1/这是它的小提琴: http : //jsfiddle.net/u7zs3jwo/1/
Here's the JSON:这是JSON:
var bardata = [
{
"ts":1431728734,
"interval":12,
"method":"GET",
"host":"beta.familysearch.org",
"aggs":{
"con":{ //Connect
"25":6,
"50":6,
"75":6,
"90":7.1,
"95":7.55,
"99":7.91,
"mn":6,
"mx":8,
"avg":6.3,
"stddv":0.67
},
"count":10,
"srvbsy":{
"25":2100.75,
"50":2272,
"75":3038.25,
"90":3571.4,
"95":3627.2,
"99":3671.84,
"mn":920,
"mx":3683,
"avg":2452.6,
"stddv":836.3
}
}
}
];
Thank you in advance for any help!!!预先感谢您的任何帮助!!!
The data passed in to D3 must be in the form of an array.传入D3的数据必须是数组的形式。 As your code stands you are passing in a single value.
就您的代码而言,您正在传递一个值。 I am answering with the assumption that you only want to plot a single bar, the value of 'mx'.
我的回答是假设您只想绘制一个条形图,即“mx”的值。
Simply by changing your code like below, the line shows up.只需像下面这样更改代码,就会显示该行。
Change the value passed in to be an array.将传入的值更改为数组。
bardata = {
...
"mx":[3683],
...
}
And change the scale function to use the first index of the 'mx' array.并更改 scale 函数以使用 'mx' 数组的第一个索引。
var vGuideScale = d3.scale.linear()
.domain([0, bardata[i].aggs.srvbsy.mx[0]]) // <-- here
.range([height, 0])
http://jsfiddle.net/u7zs3jwo/2/ http://jsfiddle.net/u7zs3jwo/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.