Google可视化ColumnChart数据

时间:2014-02-14 00:04:44

标签: javascript html google-visualization googlevis

在这里,我根据这些数据创建一个仪表板http://jsbin.com/OJAnaji/27/edit(googl可视化):

data = google.visualization.arrayToDataTable([
        ['Name', 'Gender', 'Age', 'Donuts eaten'],
        ['Michael' , 'Male', 12, 5],
        ['Elisa', 'Female', 20, 7],
        ['Robert', 'Male', 7, 3],
        ['John', 'Male', 54, 2],
        ['Jessica', 'Female', 22, 6],
        ['Aaron', 'Male', 3, 1],
        ['Margareth', 'Female', 42, 8],
        ['Miranda', 'Female', 33, 6]
    ]);

并且除了ColumnChart之外一切正常,因为我得到错误: 给定轴上的所有系列必须具有相同的数据类型×

ColumnChart代码:

var wrapper = new google.visualization.ChartWrapper({
    chartType: 'ColumnChart',
    containerId: 'chart3'
  });

并绘制函数:

// Create a dashboard
    new google.visualization.Dashboard(document.getElementById('dashboard')).
    // Establish bindings, declaring the both the slider and the category
    // picker will drive both charts.
    bind([slider, categoryPicker, stringFilter], [pie, table, wrapper]).
    // Draw the entire dashboard.
    draw(data, {'allowHtml':true, 'cssClassNames': 'cssClassNames'});      
}
google.load('visualization', '1', {packages:['controls'], callback: drawVisualization});

和HTML:

          <div class="col-md-4" style="float: left;" id="chart3"></div>

有没有办法让我显示(过滤数据)等.Y轴上的'Name'列和X轴上的'Age'或Y轴上的'Name'列和X轴上的'Donuts eaten'???

更新:我试过这个:

'view':{'columns':[0,3]}

但没有任何事情发生

1 个答案:

答案 0 :(得分:0)

您是否在包装器中指定了视图?

var wrapper = new google.visualization.ChartWrapper({
    chartType: 'ColumnChart',
    containerId: 'chart3',
    view: {
        columns: [0,3]
    }
});

顺便说一句,将第二个参数传递给Dashboad#draw调用将不会执行任何操作 - 它不接受任何选项:

new google.visualization.Dashboard(document.getElementById('dashboard')).
// Establish bindings, declaring the both the slider and the category
// picker will drive both charts.
bind([slider, categoryPicker, stringFilter], [pie, table, wrapper]).
// Draw the entire dashboard.
draw(data);

这些应该作为options参数传递到相应的ChartWrapper中(可能是Table的包装器,给定指定的选项)。