Question

I'm drawing a chart (Google Charts API) with this DataTable:

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]
]);

I need to figure out which are the lowest and highest values of the value column in the DataTable. There are some functions called google.visualization.data.max but there is not any actual code example on how to implement it. Anybody has used that feature before? Or, has someone another solution for this issue? Thanks!

Était-ce utile?

La solution

The function getColumnRange will return max and min. It also looks like you need to declare the column type and name for the number values.

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);

Autres conseils

//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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top