2013-07-01 2 views
2

Я создал Географическую карту в Google Visualization, и она отлично работает с JavaScript, но мне нужно иметь возможность обновлять «на лету», поэтому вам нужно создать данные в JSON ,Как использовать JSON с Google Geography Map

Это JS, которые я хочу повторить в формате JSON:

var data = google.visualization.arrayToDataTable([ 
    ['Country', 'Popularity'], 
    ['Germany', 200], 
    ['United States', 300], 
    ['Brazil', 400], 
    ['Canada', 500], 
    ['France', 600], 
    ['RU', 700] 
]); 

Я прочитал документацию по 10 раз, и я не понимаю, как строить выше, чтобы быть в примере в компании Google формат:

{ 
    "cols": [ 
     {"id":"","label":"Topping","pattern":"","type":"string"}, 
     {"id":"","label":"Slices","pattern":"","type":"number"} 
     ], 
    "rows": [ 
     {"c":[{"v":"Mushrooms","f":null},{"v":3,"f":null}]}, 
     {"c":[{"v":"Onions","f":null},{"v":1,"f":null}]}, 
     {"c":[{"v":"Olives","f":null},{"v":1,"f":null}]}, 
     {"c":[{"v":"Zucchini","f":null},{"v":1,"f":null}]}, 
     {"c":[{"v":"Pepperoni","f":null},{"v":2,"f":null}]} 
     ] 
} 

Я не знаю, что «с», «v», «е» и «шаблон» так не понимают, как создать это для Гео карты. Если у кого есть какие-то идеи, я буду очень благодарен !!

ответ

3

Я попытался объяснить это так, как мог.

{ 
    // The 'cols' array contains all the columns of your chart. 
    "cols": [ 
     { // This object describes the first column. 
      // The first column has an empty string for its id, the label 'Topping', 
      // and the type 'string'. The 'pattern' is optional. 
      "id": "", 
      "label": "Topping", 
      "pattern": "", 
      "type": "string"}, 
     {"id":"","label":"Slices","pattern":"","type":"number"} 
     ], 
    // The 'rows' array contains all the rows of your chart. 
    "rows": [ 
     // Each row object must have a 'c' property, which is an array of cells 
     // Each cell has a 'v' value and an 'f' value. 
     // The 'v' value contains the actual value of the cell. 
     // The 'f' value contains the formatted value of the cell. 
     {"c":[{"v":"Mushrooms","f":null},{"v":3,"f":null}]}, 
     {"c":[{"v":"Onions","f":null},{"v":1,"f":null}]}, 
     {"c":[{"v":"Olives","f":null},{"v":1,"f":null}]}, 
     {"c":[{"v":"Zucchini","f":null},{"v":1,"f":null}]}, 
     {"c":[{"v":"Pepperoni","f":null},{"v":2,"f":null}]} 
     ] 
} 
+0

+1 за комментарии. НО, можете ли вы объяснить, почему эти же ошибки JSON для PieChart и работают на гистограмме? –

0
// Load the Visualization API and the piechart package. 
google.load('visualization', '1', {'packages':['corechart']}); 

// Set a callback to run when the Google Visualization API is loaded. 
google.setOnLoadCallback(drawChart); 

function drawChart() { 
    var jsonData = $.ajax({ 
     url: "getData.php", 
     dataType:"json", 
     async: false 
     }).responseText; 

    // Create our data table out of JSON data loaded from server. 
    var data = new google.visualization.DataTable(jsonData); 

    // Instantiate and draw our chart, passing in some options. 
    var chart = new google.visualization.PieChart(document.getElementById('chart_div')); 
    chart.draw(data, {width: 400, height: 240}); 
} 

Google имеет руководство здесь: Follow this link for details

Смежные вопросы