【问题标题】:Google Charts - Table Chart Not Displaying Data谷歌图表 - 表格图表不显示数据
【发布时间】:2015-02-20 15:12:10
【问题描述】:

我正在使用 Google 图表 - 表格图表。我的表突然停止显示任何数据。大约 5 到 7 天前,我最后一次工作时工作正常。该表将显示正确的列标题,但没有数据。这是从我的 AJAX 调用(使用 Google.DataTable 生成 json 的 C# 服务)返回的 json:

{
    "cols": [
        {
            "type": "string",
            "id": "Business Name",
            "label": "Business Name"
        },
        {
            "type": "string",
            "id": "Location",
            "label": "Location"
        }
    ],
    "rows": [
        {
            "c": [
                {
                    "v": "<a href='/Advertiser/DisplayPage?advertiserId=8'>Acem Birding Tours</a>"
                },
                {
                    "v": "Cincinnati, OH"
                }
            ]
        }
    ]
}

我通过 json Lint 运行了这个 json,它是有效的 json。

我绘制图表/表格的 JavaScript 函数如下所示:

function createSearchResultsTable() {
    var options = {
        // Create some options for the displaying of the table
        page: 'enable',
        allowHtml: true,
        width: 800,
        pageSize: 20,
        showRowNumber: true
    };

    // Get the list of guides
    $.getJSON('/Home/SearchForGuide', { country: selectedCountry }, function (jsonData) {
    }).success(function (jsonData) {

        data = new google.visualization.DataTable(jsonData);
        table = new google.visualization.Table(document.getElementById('resultsTable'));
        table.draw(data, options);

    }).fail(function (jqXHR, textStatus, errorThrown) {
        alert('Error: ' + textStatus + ' ' + errorThrown);
    });
}

就像我说的,大约 5 到 7 天前,这完全按预期工作,并且正在显示数据。现在,上面显示的同一行数据没有显示出来。谁能看出哪里出了问题?

【问题讨论】:

    标签: google-visualization


    【解决方案1】:

    您的代码很好。当您说“..大约 5-7 天前,这完全按预期工作并且正在显示数据”,那么我强烈怀疑原因是您的标题发生了变化,例如。你如何加载谷歌可视化。为了显示表格图表类型,您必须像这样初始化谷歌可视化

    google.load("visualization", "1.1", {packages:["table"]});
    

    google.load('visualization', '1.1', {packages:["corechart, table"]});
    

    不是

    google.load("visualization", "1.1", {packages:["corechart"]});
    

    我怀疑你在做 :) 否则你的代码没问题 -> http://jsfiddle.net/7361pk4g/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多