对于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: [
{
答案 0 :(得分:-1)
您可以使用d3.csv函数Documentation在指定的网址处返回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]);
});
我会尝试设置一个小提琴,以便人们可以更好地帮助你!