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

Creating a donut chart with dynamic data c3.js

本文关键字:js 创建 圆环图 c3 数据 动态      更新时间:2023-09-26

我不理解这个sytax错误,不确定我在这里可能做错了什么

SyntaxError:缺少;报表前

为什么我需要一个;在语句之前,这些语句不是用来结束语句的吗?

这是JS小提琴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);

我的数据集看起来像这样(完整的数据集可以在小提琴中看到)

[
    {
        "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');