Imo*_*Imo 3 javascript arrays jquery json
我有一个 JSON 数据集
[{"key":"Albania",
"values":[{
"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"
}]
}]
Run Code Online (Sandbox Code Playgroud)
我想从每个键(国家/地区)中提取特定值(例如道路、铁路),并从每个对象中绘制一个单独的饼图。例如,阿尔巴尼亚的一张图表显示了公路和铁路的价值,然后是数据集中下一个国家的相同图表。
我正在尝试使用以下代码来实现这一点:
function checkIt(data) {
var countriesByName = d3.nest()
.key(function(d) { return d.Country_Names; })
.entries(data);
//console.log(countriesByName)
var data = JSON.stringify(countriesByName);
console.log(data);
function makePie() {
function myfunc(data){
var obj = [];
for (var i in data.key) {
obj.push('Road' + m.countriesByName[i].key.values[i].Food+ ' and tobacco');
}
}
var data1 = myfunc(data);
//console.log(data)
var chart = c3.generate({
bindto: "#left",
data: {
columns: [
data1
],type : "donut"
}
});
}
makePie();
};
d3.json("https://gist.githubusercontent.com/heenaI/cbbc5c5f49994f174376/raw/82cd19eff7db367193cf8ce00144a40ea8d140ac/data.json", checkIt);
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
未捕获的类型错误:无法读取未定义的属性“0”
这是数据集的JS 小提琴:
预期的结果是这样的 ["Road", 2.2] 然后我想将它作为循环运行在数据中的所有国家以获得类似的数组
| 归档时间: |
|
| 查看次数: |
7089 次 |
| 最近记录: |