Imo
Imo

Reputation: 1475

Creating a donut chart with dynamic data c3.js

I do not understand this sytax error not sure what I might be doing wrong here

SyntaxError: missing ; before statement

why do I need a ; before a statement arent these suppose to end statements?

here is the JS fiddle https://jsfiddle.net/n5v84svm/10/

my code

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);

My data set looks like this (full data set could be seen in the 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"
    }]

Upvotes: 0

Views: 1245

Answers (1)

nardnob
nardnob

Reputation: 1056

Looks like you just had a few syntax errors...

This:

checkIt(data){

Should be:

function checkIt(data) {

And this:

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

Should be:

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

Upvotes: 1

Related Questions