-1

是否可以通过单击相应的按钮在图表类型(饼图和列)之间切换?

例如,我想要两个按钮,一旦我点击第一个按钮,它就会显示饼图。

4

1 回答 1

2

这很简单

function drawChart() {

    // Create the data table.
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Topping');
    data.addColumn('number', 'Slices');
    data.addRows([
      ['Mushrooms', 3],
      ['Onions', 1],
      ['Olives', 1],
      ['Zucchini', 1],
      ['Pepperoni', 2]
    ]);

    // Set chart options
    var options = {'title':'How Much Pizza I Ate Last Night',
                   'width':400,
                   'height':300};

    // Instantiate and draw our chart, passing in some options.
    var piechart = new google.visualization.PieChart(document.getElementById('chart_div'));
    chart.draw(data, options);

在您的点击处理程序上只需替换

var barchart = new google.visualization.BarChart(document.getElementById('chart_div'));
        chart.draw(data, options);
于 2013-06-11T18:58:34.873 回答