Build a chart. So it does not work. And I need a variable

var data_for="{'country': 'Lithuania','litres': 501.9}, {'country': 'Czech Republic', 'litres': 301.9 }, {'country': 'Ireland','litres': 201.1}, {'country': 'Germany','litres': 165.8}, {'country': 'Australia','litres': 139.9}, {'country': 'Austria','litres': 128.3}, {'country': 'UK','litres': 99}, {'country': 'Belgium','litres': 60}, {'country': 'The Netherlands','litres': 50}"; var chart = AmCharts.makeChart( "chartdiv", { "type": "pie", "theme": "none", "dataProvider": [data_for], "valueField": "litres", "titleField": "country", "balloon":{ "fixedPosition":true }, "export": { "enabled": true } } ); 

But if you get the contents of the variable in the dataProvider everything works

 var data_for="{'country': 'Lithuania','litres': 501.9}, {'country': 'Czech Republic', 'litres': 301.9 }, {'country': 'Ireland','litres': 201.1}, {'country': 'Germany','litres': 165.8}, {'country': 'Australia','litres': 139.9}, {'country': 'Austria','litres': 128.3}, {'country': 'UK','litres': 99}, {'country': 'Belgium','litres': 60}, {'country': 'The Netherlands','litres': 50}"; var chart = AmCharts.makeChart( "chartdiv", { "type": "pie", "theme": "none", "dataProvider": [{'country': 'Lithuania','litres': 501.9}, {'country': 'Czech Republic', 'litres': 301.9 }, {'country': 'Ireland','litres': 201.1}, {'country': 'Germany','litres': 165.8}, {'country': 'Australia','litres': 139.9}, {'country': 'Austria','litres': 128.3}, {'country': 'UK','litres': 99}, {'country': 'Belgium','litres': 60}, {'country': 'The Netherlands','litres': 50}], "valueField": "litres", "titleField": "country", "balloon":{ "fixedPosition":true }, "export": { "enabled": true } } ); 

example http://jsfiddle.net/uqq2urqa/3/

    1 answer 1

    Not needed " ;

     var data_for = [{'country': 'Lithuania','litres': 501.9}, {'country': 'Czech Republic', 'litres': 301.9 }, {'country': 'Ireland','litres': 201.1}, {'country': 'Germany','litres': 165.8}, {'country': 'Australia','litres': 139.9}, {'country': 'Austria','litres': 128.3}, {'country': 'UK','litres': 99}, {'country': 'Belgium','litres': 60}, {'country': 'The Netherlands','litres': 50}] 

    http://jsfiddle.net/uqq2urqa/4/

    • And what is this array dataArr = []; where is it used? - zkolya
    • ignore it. I debugged the code - Nick
    • without it does not work - zkolya