0

这是我的代码,我想要一个带有 dashbord 的组合图,但我有这个错误:

一个或多个参与者未能draw()× janv。2013 年 1 月。2013 年 4 月 2013 年 4 月 2013mars 2013mars 2013avr。2013 年 2013 年 2013 年 2013 年 2013 年 2013 年 2013 年 7 月 2013 年七月。2013 年 2013 年 2013 年


!function($) {


    google.load('visualization', '1.1', {packages: ['corechart']});
    google.load('visualization', '1', {packages: ['controls']});
    google.setOnLoadCallback(initialize);



       function initialize(cityName) {

            // You can manipulate the variable response
            // Success! 
            var query = new google.visualization.Query('http://api.XXX.com/XXX/datasource?table=montmorin');


            query.setQuery("select (cost_reportings_timestamp), sum (cost_reportings_cost) group by (cost_reportings_timestamp)  pivot ecoadmin_zone_name");
              //Send the query with a callback function.
            query.send(drawDashboard);
        //console.log(response);
        }

       function drawDashboard(response) {
            // it's a good idea to include something like this to catch errors

            if (response.isError()) {
                alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
                return;
            }

            var data = response.getDataTable();
            console.log(data);
            var namePicker= new google.visualization.ControlWrapper({
                controlType: 'ChartRangeFilter',
                containerId: 'filter_div',

                options: {
                    // Filter by the date axis.
                    filterColumnLabel: 'cost_reportings_timestamp',
                    ui: {
                        chartType: 'LineChart',
                        chartOptions: {
                            chartArea: {
                                width: '90%'
                            },
                            hAxis: {
                                baselineColor: 'none'
                            }
                        },
                        // Display a single series that shows the closing value of the stock.
                        // Thus, this view has two columns: the date (axis) and the stock value (line series).
                        chartView: {
                            columns: [0,1]
                        }
                    }
                },
                //Initial range: 2010 to 2021
                state: {
                    range: {
                        start: new Date(2012),
                        end: new Date(2019)
                    }
                }
            })

         // Define a bar chart
            var pieChart = new google.visualization.ChartWrapper({
                chartType: 'ComboChart',
                containerId: 'chart_div',

                options: {
                    width: 400,
                    height: 300,
                    seriesType: 'bars',
                    isStacked:'True',
                    hAxis: {
                        minValue: 0,
                        maxValue: 60
                    },
                    chartArea: {
                        top: 0,
                        right: 0,
                        bottom: 0
                    },
                },
                view: {columns: [0, 1, 2, 3]}
            });

            var dashboard = new google.visualization.Dashboard(document.getElementById('dashboard_div')).
            bind(namePicker, pieChart).
            draw(data);

       }         
}(jQuery);

你能给我解释一下吗??????

这是我的 JSON 格式:

google.visualization.Query.setResponse({"version":"0.6","status":"ok","sig":"266867977","table":{"cols":[{"id":"ecoadmin_building_name","label":"ecoadmin_building_name","type":"string","pattern":""},{"id":"ecoadmin_zone_name","label":"ecoadmin_zone_name","type":"string","pattern":""},{"id":"cost_reportings_cost","label":"cost_reportings_cost","type":"number","pattern":""},{"id":"cost_reportings_timestamp","label":"cost_reportings_timestamp","type":"date","pattern":""}],"rows":[{"c":[{"v":"Mairie de Montmorin"},{"v":"Bureau de M. le Maire"},{"v":0.0},{"v":new Date(2012,11,8)}]},{"c":[{"v":"Mairie de Montmorin"},{"v":"Bureau de M. le Maire"},{"v":0.0},{"v":new Date(2012,11,9)}]},{"c":[{"v":"Mairie de Montmorin"},{"v":"Bureau de M. le Maire"},{"v":0.453663},{"v":new Date(2012,11,10)}]},{"c":[{"v":"Mairie de Montmorin"},{"v":"Bureau de M. le Maire"},{"v":0.458649},{"v":new Date(2012,11,11)}]},{"c":[{"v":"Mairie de Montmorin"},{"v":"Bureau de M. le Maire"},{"v":0.44573},{"v":new Date(2012,11,12)}]},{"c":[{"v":"Mairie de Montmorin"},{"v":"Bureau de M. le Maire"},{"v":1.09863},{"v":new Date(2012,11,13)}]},{"c":[{"v":"Mairie de Montmorin"},{"v":"Bureau de M. le Maire"},{"v":0.429977},{"v":new Date(2012,11,14)}]},{"c":[{"v":"Mairie de Montmorin"},{"v":"Bureau de M. le Maire"},{"v":1.13331E-4},{"v":new Date(2012,11,15)}]},{"c":[{"v":"Mairie de Montmorin"},{"v":"Bureau de M. le Maire"},{"v":0.0},{"v":new Date(2012,11,16)}]},{"c":[{"v":"Mairie de Montmorin"},{"v":"Bureau de M. le Maire"},{"v":0.471569},{"v":new Date(2012,11,17)}]}

4

1 回答 1

1

The problem with your JSON is that there is no 'table' property in the JSON representation, 'cols' and 'rows' are direct peers of 'version'. So your fixed JSON should look as follows:

google.visualization.Query.setResponse({
  "version": "0.6",
  "status": "ok",
  "sig": "266867977",
  "cols": [{
      "id": "ecoadmin_building_name",
      "label": "ecoadmin_building_name",
      "type": "string",
      "pattern": ""
    }, {
      "id": "ecoadmin_zone_name",
      "label": "ecoadmin_zone_name",
      "type": "string",
      "pattern": ""
    }, {
      "id": "cost_reportings_cost",
      "label": "cost_reportings_cost",
      "type": "number",
      "pattern": ""
    }, {
      "id": "cost_reportings_timestamp",
      "label": "cost_reportings_timestamp",
      "type": "date",
      "pattern": ""
    }
  ],
  "rows": [
    {"c": [{"v": "Mairie de Montmorin"}, {"v": "Bureau de M. le Maire"}, {"v": 0.0}, {"v": new Date(2012, 11, 8)}]},
    {"c": [{"v": "Mairie de Montmorin"}, {"v": "Bureau de M. le Maire"}, {"v": 0.0}, {"v": new Date(2012, 11, 9)}]},
    {"c": [{"v": "Mairie de Montmorin"}, {"v": "Bureau de M. le Maire"}, {"v": 0.453663}, {"v": new Date(2012, 11, 10)}]},
    {"c": [{"v": "Mairie de Montmorin"}, {"v": "Bureau de M. le Maire"}, {"v": 0.458649}, {"v": new Date(2012, 11, 11)}]},
    {"c": [{"v": "Mairie de Montmorin"}, {"v": "Bureau de M. le Maire"}, {"v": 0.44573}, {"v": new Date(2012, 11, 12)}]},
    {"c": [{"v": "Mairie de Montmorin"}, {"v": "Bureau de M. le Maire"}, {"v": 1.09863}, {"v": new Date(2012, 11, 13)}]},
    {"c": [{"v": "Mairie de Montmorin"}, {"v": "Bureau de M. le Maire"}, {"v": 0.429977}, {"v": new Date(2012, 11, 14)}]},
    {"c": [{"v": "Mairie de Montmorin"}, {"v": "Bureau de M. le Maire"}, {"v": 1.13331E-4}, {"v": new Date(2012, 11, 15)}]},
    {"c": [{"v": "Mairie de Montmorin"}, {"v": "Bureau de M. le Maire"}, {"v": 0.0}, {"v": new Date(2012, 11, 16)}]},
    {"c": [{"v": "Mairie de Montmorin"}, {"v": "Bureau de M. le Maire"}, {"v": 0.471569}, {"v": new Date(2012, 11, 17)}]}
  ]
});
于 2013-08-07T13:43:13.110 回答