Не воспринимает переменную

170
24 февраля 2017, 02:38

Строю диаграмму. Так не работает.А мне необходимо с переменной

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

Но если встать содержимое переменной в dataProvider все работает

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

пример http://jsfiddle.net/uqq2urqa/3/

Answer 1

Не нужны ";

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/

READ ALSO
генерация разметки Jquery

генерация разметки Jquery

привет есть код

268
JavaScript Проверка на аргумент-undefined

JavaScript Проверка на аргумент-undefined

Изучаю JavaScriptТема: «Псевдомассив аргументов "arguments"»

242
Node.js. Express, как использовать middleware только для корня

Node.js. Express, как использовать middleware только для корня

Хочу сделать авторизацию при переходе в корень сайта, остальные ссылки не трогатьПытаюсь сделать:

215