1

我正在使用此 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 中value列的最低值和最高值。有一些名为google.visualization.data.max的函数,但没有任何关于如何实现它的实际代码示例。有人用过这个功能吗?或者,有人对此问题有其他解决方案吗?谢谢!

4

2 回答 2

12

该函数getColumnRange将返回最大值和最小值。看起来您还需要为数字值声明列类型和名称。

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);
于 2012-06-09T03:29:31.337 回答
-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>
于 2020-09-25T09:22:25.963 回答