我正在使用此DataTable绘制图表(Google Charts API):
chart_data = new google.visualization.DataTable();
chart_data.addColumn('string','date');
chart_data.addColumn('number','value');
chart_data.addRows([
["10 May",0.23],
["11 May",0.26],
["12 May",0.29],
["13 May",0.23],
["14 May",0.21],
["15 May",0.25],
["16 May",0.28]
]);
我需要弄清楚DataTable中值列的最低和最高值。有一些名为 google.visualization.data.max 的函数,但是没有关于如何实现它的任何实际代码示例。有人之前使用过这个功能吗?或者,有人为此问题提供另一种解决方案吗?谢谢!
答案 0 :(得分:11)
函数getColumnRange
将返回max和min。看起来您还需要声明数字值的列类型和名称。
chart_data = new google.visualization.DataTable();
chart_data.addColumn('string','date');
chart_data.addColumn('number','some number');
chart_data.addRows([
["10 May",0.23],
...
["16 May",0.28]
]);
alert("Max: " + chart_data.getColumnRange(1).max);
alert("Min: " + chart_data.getColumnRange(1).min);
答案 1 :(得分:-1)
//If your fetching data from Mysql
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['LIFESTYLE','TECHNOLOGY LEVELS',{ role: 'style' }],
<?php
$query = "SELECT question,useranswer from quiz";
$exec = mysqli_query($con,$query);
while($row = mysqli_fetch_array($exec)){
echo "['".$row['question']."',".$row['useranswer'].",'gold'],";
}
?>
]);
data.getColumnRange(1).max;
//alert("Min: " + data.getColumnRange(1).min);
var options = {
title: 'LIFESTYLE CHART',
// pieHole: 0.5,
// pieSliceTextStyle: {
// color: 'black',
// },
// legend: 'none'
};
var chart = new google.visualization.ColumnChart(document.getElementById("columnchart12"));
chart.draw(data,options);
}
</script>