谷歌可视化代码引发了一个加密错误

时间:2014-06-02 15:09:24

标签: google-analytics google-visualization

我从Google Analytics获取数据并尝试将其显示在表格中。代码抛出错误“this.zf [a] .c is undefined”。我没有看到任何明显错误的代码。

/*Table */
google.load('visualization', '1.0', {packages:['table']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawNewTable);
function drawNewTable() {
var json = {cols: [{id:'campaign',label:'campaign',type:'string'},{id:'source',label:'source',type:'string'},{id:'medium',label:'medium',type:'string'},{id:'sessions',label:'sessions',type:'number'}],rows:[["FAC 2005-74 addresses contractor past performance reporting, contractor compensation","todays_acquisition_news_05302014","email",8.0],["GAO sustains protest, finding agency revised requirements","todays_acquisition_news_05292014","email",8.0],["GSA Announces OASIS Awards","todays_acquisition_news_05202014","email",6.0],["Governance Key to IT Program Success","todays_acquisition_news_05192014","email",6.0],["Revised FAC-C Addresses Competency Gaps, Uniform Standards","todays_acquisition_news_05192014","email",4.0],["FAR change could boost small business subcontracting, advocates say","todays_acquisition_news_05272014","email",3.0],["GAO examines sequestration?s effects","todays_acquisition_news_05292014","email",3.0],["GSA OIG finds PBS should have notified Congress when supplementing Recovery Act funding.","todays_acquisition_news_04282014","email",3.0],["Rung to leave GSA for OMB.","todays_acquisition_news_05152014","email",3.0],["Air Force may consider partnership to develop new launch rocket","todays_acquisition_news_05222014","email",2.0],["Boeing subcontractor pleads guilty in bribery scheme.","todays_acquisition_news_05142014","email",2.0],["Commentary questions whether contracting officers are using FAR part 1 authorities.","todays_acquisition_news_05302014","email",2.0],["Contractor improperly charged labor rates, DoD OIG finds","todays_acquisition_news_05212014","email",2.0],["Digital Service team would help agencies address IT gaps","todays_acquisition_news_05272014","email",2.0],["Senate hearing addresses DoD's acquisition reform efforts.","todays_acquisition_news_05012014","email",2.0],["poll","todays_acquisition_news_05302014","email",2.0],["Administration Threatens Veto of FY2015 Defense Authorization Act","todays_acquisition_news_05202014","email",1.0],["Administration Threatens Veto of FY2015 Defense Authorization Act-readmore","todays_acquisition_news_05202014","text-email",1.0],["Agencies have bolstered suspension and debarment programs","todays_acquisition_news_05222014","email",1.0],["Air Force asking industry to help reduce supply chain costs, official says.","todays_acquisition_news_04182014","email",1.0]]}
var data_newtable = new google.visualization.DataTable(json);
var data_table = new google.visualization.Table(document.getElementById('emailTable_div'));
data_table.draw(data_newtable, null);
};

1 个答案:

答案 0 :(得分:1)

json文件的格式错误(cols,id ...应该像字符串......)。应改为:

var json = {
    'cols': [
        {'id': 'campaign', 'label':'campaign',  'type':'string'},
        {'id':'source',    'label':'source',    'type':'string'},
        {'id':'medium',    'label':'medium',    'type':'string'},
        {'id':'sessions',  'label':'sessions',  'type':'number'}
    ],
    'rows':
        [{ 'c':[{ 'v': "FAC 2005-74 addresses contractor past performance reporting, contractor compensation"}, {'v': "todays_acquisition_news_05302014"}, {'v': "email"},{'v': 8.0}]}]
}

更新:您可以在不更改json的情况下使用addColumn()addRow()

var data_newtable = new google.visualization.DataTable();

for (var i = 0; i < json.cols.length; ++i) {
    data_newtable.addColumn(json.cols[i].type, json.cols[i].label, json.cols[i].id);
}

for (var i = 0; i < json.rows.length; ++i) {
    data_newtable.addRow(json.rows[i]);
}

请参阅example at jsbin