2015-03-31 76 views
0

我正在尝试使用ComboCharts。Google图表库中的组合图表

在它的options变量中,它在示例Here中设置值5series。这5个字是什么意思?

var options = { 
    title : 'Monthly Coffee Production by Country', 
    vAxis: {title: "Cups"}, 
    hAxis: {title: "Month"}, 
    seriesType: "bars", 
     series: {5: {type: "line"}} 
    }; 

编辑:我现在意识到,这5是每个值的值类型上vAxis

虽然我尝试,改变50,1,2,3 or 4.它不仅改变了线的位置。 它与图表中行的位置有什么关系?

回答

1

该数字是您的数据中您正在更改属性的系列的从零开始的索引。您的选项中的seriesType: "bars"部分表示您的所有系列将默认呈现为条形。

当您专门调出这样一个系列时,您将覆盖默认设置。在这种情况下,你说第5列应该被渲染为一行。

看看这个例子来看看系列和数据之间的关系。

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

 
function drawChart() { 
 
    var data = google.visualization.arrayToDataTable([ 
 
     ["X", "C1", "C2", "C3", "C4", "C5"], 
 
     ["A", 1, 2, 3, 4, 5], 
 
     ["B", 2, 5, 1, 7, 9], 
 
     ["C", 6, 2, 4, 1, 8], 
 
     ["D", 7, 1, 2, 3, 6] 
 
    ]); 
 

 

 
    var options = { 
 
     seriesType: "bars", 
 
     series: { 
 
      // Make the first column (C1) a blue bar (bar because it is the default) 
 
      0: { 
 
       color: "blue" 
 
      }, 
 
      // Make the fourth column (C4) a green line (line because we overrode the default) 
 
      3: { 
 
       type: "line", 
 
       color: "green" 
 
      } 
 
     } 
 
    }; 
 
    
 
    var chart = new google.visualization.ComboChart(document.getElementById("chart")); 
 
    chart.draw(data, options); 
 
}
<script type="text/javascript" src="https://www.google.com/jsapi"></script> 
 
<div id="chart" style="width: 900px; height: 300px;"></div>