【问题标题】:d3.scale.linear() returns NaN [duplicate]d3.scale.linear() 返回 NaN [重复]
【发布时间】:2015-10-25 21:19:28
【问题描述】:

我正在尝试使用 d3.js 读取 json 文件,其中图形 y 轴取决于 json 文件中的最大数量。在文件中记录数据时,我得到30900,我可以用它们来设置我的cy,但是当我把它放在yscale()函数中时,它说数据是NaN

var yScale = d3.scale.linear()
    .domain([0,d3.max(charts)])
    .range([0,height])

var height = 600,
width = 800,
circleWidth = 50,
offSetX = 15

d3.json('_/data.json', function(data){

for (key in data) {
    charts.push(data[key].amount);
};

var graph = d3.select("#graph").append('svg')
.selectAll('circle').data(charts)
.enter().append('circle')
.attr('cx', function(d, i){
    return (i * circleWidth) + offSetX;
})
.attr('cy', function(d){
    return yScale(d);
})

Json 文件

[
  {
    "song":"Song1",
    "amount":30
  },
  {
    "song":"Song2",
    "amount":900
  }
]

【问题讨论】:

  • 是在定义的范围内使用的高度吗??
  • @AhmedEid 是的,我已经编辑了我的帖子。编辑:不在正确的功能中。谢谢

标签: javascript json d3.js


【解决方案1】:

发现我的问题。应该将variables 放在d3.json 函数中

【讨论】:

    猜你喜欢
    • 2013-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多