Google Charts:如何更改controlType中的默认选定值:ControlWrapper的CategoryFilter

时间:2012-11-02 09:32:32

标签: javascript visualization google-visualization

我有一个类别过滤器,用于选择绑定到饼图的日期。目前它将标题显示为默认值(“选择值”)。我想将其默认值设置为其中一个包含的值,例如最后一个日期。

我该怎么做?

谢谢!

1 个答案:

答案 0 :(得分:0)

有点晚了,但结帐这个例子:

  // Load the Visualization API and the piechart package.
  google.load('visualization', '1.0', {'packages':['corechart']});

  // Set a callback to run when the Google Visualization API is loaded.
  google.setOnLoadCallback(drawChart);

  // Callback that creates and populates a data table,
  // instantiates the pie chart, passes in the data and
  // draws it.
  function drawChart() {

    // Create the data table.
    var data = google.visualization.arrayToDataTable([
      ['Year', 'Sales', 'Expenses'],
      ['2004',  1000,      400],
      ['2005',  1170,      460],
      ['2006',  660,       1120],
      ['2007',  1030,      540]
    ]);

    var options = {
      title: 'Company Performance'
    };

    var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
    chart.draw(data, options);
    //============All=U=Need============
    chart.setSelection([{'column': 1}]);
    //============All=U=Need============
  }

:d