【问题标题】:D3 bubble chart - get data from jsonD3气泡图-从json获取数据
【发布时间】:2018-06-15 18:13:14
【问题描述】:

我是 javascript 和 D3 的初学者。我想使用 D3 创建一个气泡图,我需要从外部文件中获取数据。我已经搜索了其他方法,但看起来没有任何效果。有谁知道我该怎么做?

function animatedBubbleChart() {
    var bubbleChart = new d3.svg.BubbleChart({
        supportResponsive: true,
        size: 800,
        innerRadius: 600 / 3.5,
        radiusMin: 50,
        data: {
          items: [//replace this with data from a json
            {text: "2010", count: "170"},
            {text: "2011", count: "170"},
            {text: "2012", count: "170"},
            {text: "2013", count: "170"},
            {text: "2014", count: "170"},
            {text: "2015", count: "170"},
            {text: "2016", count: "170"},
          ],
          eval: function (item) {return item.count;},
          classed: function (item) {return item.text.split(" ").join("");}
        },
        plugins: [
          {

【问题讨论】:

  • 嗯,这看起来不像是纯D3代码,这里有某种插件。因此,请编辑您的问题,向我们展示您使用的插件是什么,以便您获得适当的帮助。另外,我删除了 sn-p,它仅用于运行代码。
  • 什么不起作用?加载数据是唯一的问题吗?请更新您的问题以详细说明。

标签: javascript json d3.js


【解决方案1】:

您可以使用 d3.csv 函数 Documentation 在指定 url 返回对 CSV 文件的新请求。这个问题有一个很好的答案! LINK TO QUESTION 例子

d3.csv("test.csv", function (data) {    
    console.log(data[0]);
}

对于json类似

d3.json("test.json", function(data) {
  console.log(data[0]);
});

我会尝试设置一个小提琴,以便人们可以更好地帮助你!

【讨论】:

  • 不知道为什么我投了反对票,这是正确的答案,如果提问者可以提出一个小提琴 Id 附加他的工作来反映这一点..
  • 我想他是在问你如何发出 Ajax 请求然后解析 d3 图表中的数据。我正在寻找同样的东西
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-20
  • 1970-01-01
相关资源
最近更新 更多