【发布时间】:2017-05-23 10:23:09
【问题描述】:
我有以下代码前折线图。
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.charts.load('current', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.charts.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([
['SiteName', 'Availability'],
<?php
foreach($val as $data){
echo "['".$data['name']."', ".$data['avil']."],";
}
?>
]);
// Set chart options
var options = {
hAxis: {
title: 'Type'
},
vAxis: {
title: 'Total',
gridlines: {
color: 'transparent'
}
},
'title':'Uptime Percentage',
'width':830,
'height':300,
legend: {position: 'none'},
};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.LineChart(document.getElementById('chart_line'));
function selectHandler() {
var selectedItem = chart.getSelection()[0];
if (selectedItem) {
var topping = data.getValue(selectedItem.row, 0);
alert('The user selected ' + topping);
}
}
google.visualization.events.addListener(chart, 'select', selectHandler);
chart.draw(data, options);
}
</script>
为了删除水平线,我将 gridline 添加为透明的,为了不显示图例,我将其位置设为无。它工作但现在,我的 x 轴值显示不正确。见下文。
那么,我怎样才能正确显示我的 x 轴值???请帮帮我
【问题讨论】:
标签: php charts google-visualization