一个或多个参与者未能绘制()

时间:2013-08-06 19:24:23

标签: javascript jquery ajax google-visualization

这是我的代码我希望有一个与dashbord的combochart但我有这个错误:

一个或多个参与者未能绘制()× janv。 2013janv。 2013févr。 2013févr。 2013mars 2013mars 2013avr。 2013avr。 2013mai 2013mai 2013juin 2013juin 2013juil。 2013juil。 2013août2013août2013


!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)}]}

1 个答案:

答案 0 :(得分:1)

JSON的问题在于JSON表示中没有'table'属性,'cols''rows''version'的直接对等。因此,您修复的JSON应如下所示:

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