使用动态数据创建圆环图 c3.js
Creating a donut chart with dynamic data c3.js
我不明白这个语法错误,不确定我在这里做错了什么
语法错误:缺少;声明前
为什么我需要一个;在声明之前这些不是假设结束声明吗?
这是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');
我不明白这个语法错误,不确定我在这里做错了什么
语法错误:缺少;声明前
为什么我需要一个;在声明之前这些不是假设结束声明吗?
这是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');