目前我正在使用Google图表在我的.net网络应用程序中显示报告。我正在使用谷歌组合图表,柱形图。这是我正在使用的示例代码。
*
当我执行此代码时,我正在设置水平网格线,但我想要一条垂直网格线也从“0”位置开始。我想要如下面的URL(图像)所示的垂直网格线。如何通过使用来实现它谷歌可视化API。你的帮助将是appriciated ...
答案 0 :(得分:-1)
我知道有两种可能的解决方案,但两种解决方案都规定水平月份值是连续的 - 意味着它应该是数据列类型之一:number,date,datetime或timeofday。你的是月份列的类型字符串。
解决方案1 - 使用月份数值,您可以使用日期并使用hAxis格式化:'某些日期格式'并且还使用了基线:0
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawVisualization);
function drawVisualization() {
// Some raw data (not necessarily accurate)
var data = google.visualization.arrayToDataTable([
['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'Rwanda', 'Average'],
[1, 165, 938, 522, 998, 450, 614.6],
[2, 135, 1120, 599, 1268, 288, 682],
[3, 157, 1167, 587, 807, 397, 623],
[4, 139, 1110, 615, 968, 215, 609.4],
[5, 136, 691, 629, 1026, 366, 569.6]
]);
var options = {
title : 'Monthly Coffee Production by Country',
vAxis: {title: 'Cups', gridlines:{count:3}},
hAxis: {title: 'Month', baseline:0},
seriesType: 'bars',
series: {5: {type: 'line'}}
};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
&#13;
解决方案2 - 这里也使用了月份的数值,但是这次使用了滴答:[{v:0}]
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawVisualization);
function drawVisualization() {
// Some raw data (not necessarily accurate)
var data = google.visualization.arrayToDataTable([
['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'Rwanda', 'Average'],
[1, 165, 938, 522, 998, 450, 614.6],
[2, 135, 1120, 599, 1268, 288, 682],
[3, 157, 1167, 587, 807, 397, 623],
[4, 139, 1110, 615, 968, 215, 609.4],
[5, 136, 691, 629, 1026, 366, 569.6]
]);
var options = {
title : 'Monthly Coffee Production by Country',
vAxis: {title: 'Cups', gridlines:{count:3}},
hAxis: {title: 'Month', ticks: [{v:0}]},
seriesType: 'bars',
series: {5: {type: 'line'}}
};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
&#13;