gpt4 book ai didi

javascript - 使用动态数据创建圆环图 c3.js

转载 作者:行者123 更新时间:2023-12-03 08:21:04 24 4
gpt4 key购买 nike

我不明白这个语法错误,不确定我在这里可能做错了什么

语法错误:缺少;声明之前

为什么我需要一个 ;在语句之前这些不是应该结束语句吗?

这是 JS fiddle https://jsfiddle.net/n5v84svm/10/

我的代码

checkIt(data){
var countriesByName = d3.nest()
.key(function(d) { return d.Country_Names; })
.entries(data);

console.log(countriesByName)

function makePie(){
var chart = c3.generate({
data: {
columns: [
function(m) {
var obj = [];
for (var i in m) {
obj.push('Road ' + m.countriesByName[i].key.values.Food and tobacco);
}
return obj;
}
],
type : 'donut'
}
});
}
makePie();
};




d3.json("https://gist.githubusercontent.com/heenaI/cbbc5c5f49994f174376/raw/82cd19eff7db367193cf8ce00144a40ea8d140ac/data.json", checkIt);

我的数据集如下所示(完整的数据集可以在 fiddle 中看到)

[
{
"Continent": "Europe",
"Country_Names": "Albania",
"Total": "3.8",
"Change_total": "-38.7",
"Main activity electricity and heat production": "0.1",
"Main activity electricity plants": "",
"Main activity CHP plants": "",
"Unallocated autoproducers / Other energy industry own use": "0.1",
"Other": "1.4",
"Manufacturing industries and construction": "1",
"Iron and steel": "0",
"Chemical and petrochemical": "0",
"Machinery": "",
"Mining and quarrying": "",
"Food and tobacco": "0.1",
"Paper, pulp and printing": "",
"Construction": "0",
"Transport": "2.2",
"Road": "2.2",
"Domestic aviation": "",
"Rail": "0",
"Domestic navigation": "0.1",
"Residential": "0.2",
"Commercial and public services": "0",
"Agriculture/forestry": "0.2",
"Sub-bituminous coal / Lignite": "",
"Other bituminous coal": "",
"Natural gas": "0",
"Motor gasoline excl. bio": "0.3",
"Gas/diesel oil excl. bio": "2.2"
}]

最佳答案

看起来您只是遇到了一些语法错误...

这个:

checkIt(data){

应该是:

function checkIt(data) {

还有这个:

obj.push('Road ' + m.countriesByName[i].key.values.Food and tobacco);

应该是:

obj.push('Road ' + m.countriesByName[i].key.values.Food + ' and tobacco');

关于javascript - 使用动态数据创建圆环图 c3.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33746213/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com