为什么谷歌饼图显示空白?

时间:2016-03-22 18:35:07

标签: javascript charts google-visualization pie-chart

我正在尝试加载饼图。我在页面上有其他图表(4列和2个双Y列)并且它们正确加载,但饼图显示为空白。我没有收到任何错误消息。为什么显示空白?我错过了什么?

function insert_graph(graph_data_type, location, title, type, horizontal_axis, vertical_axis, height) {
    $.ajax({
        type: 'get',
        url: 'getdata.php?id=' + id+ '&graph=' + graph_data_type,
        dataType: 'json',
        success: function (response) {
            if (response === 'error') {
                //Error Handling
            } else if (null === response) {
                //Error Handling
            } else {
                chart_data = response;

                google.charts.setOnLoadCallback(function () {
                    drawGoogleGraph(response, location, title, type, horizontal_axis, vertical_axis,height);
                });

            }
        }
    });
}

function drawGoogleGraph(chart_data, chart_location, chart_title, chart_type, horizontal_axis, vertical_axis,height) {
    var data = new google.visualization.DataTable(chart_data);

    switch (chart_type) {
        case 'column':
            var options = {
                    title: chart_title,
                    height: height,
                    hAxis: horizontal_axis,
                    vAxis: vertical_axis
                },
                chart = new google.visualization.ColumnChart($('#' + chart_location)[0]);

            break;
        case 'column_dual_y':
            var options = {
                    title: chart_title,
                    height: height,
                    hAxis: horizontal_axis,
                    vAxis: vertical_axis,
                    series: {
                        0: {axis: 'cytd'},
                        1: {axis: 'pytd'}
                    }
                },
                chart = new google.visualization.ColumnChart($('#' + chart_location)[0]);

            break;
        case 'pie_3d_exploding':
            var options = {
                    title: chart_title,
                    is3D: true,
                    height: height,
                    hAxis: horizontal_axis,
                    vAxis: vertical_axis
                },
                chart = new google.visualization.PieChart($('#' + chart_location)[0]);

            break;
    }

    chart.draw(data, options);
}

从PHP脚本返回的数据

{"cols":[{"id":"product_type","label":"product_type","type":"string"},{"id":"cases","label":"cases","type":"number"}],"rows":[{"c":[{"v":"COFF"}{"v":"36046.00"}]},{"c":[{"v":"COCO"},{"v":"710.00"}]},{"c":[{"v":"TEA"},{"v":"635.00"}]},{"c":[{"v":"NA"},{"v":"156.00"}]},{"c":[{"v":"DAIR"},{"v":"155.00"}]},{"c":[{"v":"BRWR"},{"v":"149.00"}]},{"c":[{"v":"FRUI"},{"v":"70.00"}]},{"c":[{"v":"ACC"},{"v":"2.00"}]}]}

0 个答案:

没有答案