Jump to content

filter on google chart month wise


Senthilkumar

Recommended Posts

Dear Team, 

I am creating google pie chart from mysql database on my PHP project. 

My actual chart and output is 

image.png.f161144bd1fbc57ffb98b0c0187da60c.png

 

<script type="text/javascript">
      google.charts.load("current", {packages:["corechart"]});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          	  	   ['class Name','Students'],
                      <?php
 						$query = "select Brand, SUM(ASP) as sum from dbms.tiv_data where Category ='EXCAVATOR' AND Dealerid = '$Emp_No' group by Brand order by sum DESC";
                    $exec = mysqli_query($conn, $query);
					    while ($row = mysqli_fetch_array($exec)) {
							$Brand = $row['Brand'];
							$ASP = $row['sum'];
                            echo "['$Brand',$ASP],";
						}
				?>
             ]);

        var options = {
          is3D: true,
        };

        var chart = new google.visualization.PieChart(document.getElementById('Excavator_MS'));
        chart.draw(data, options);
      }
      </script>




			<div class="row " style="width:100%;margin-left:5px">
                  <div class="column card" style="width:33.33%;text-align:center">
                      <label style="text-align:center">Excavator</label>
                      <div id="Excavator_MS" style="width: 100%; height: 200px;" onclick="Excavator()"></div>
                  </div>
              </div>

 

But i want the filter option should be placed on the graph

image.png.0311fbf76321cf1210de8512b7910dca.png

My database is like bellow

image.thumb.png.c02fe676b32c18d748adc08b441f6120.png

I want once i select the month the chart data should change without refresh the page. Can any one help me how to do this

Link to comment
Share on other sites

PHP and JS scripts run in different space-time dimensions...

  • PHP runs on server and sends output to client browser, then
  • client browser runs the JS script

Solutions:

  • Ask Google to change their charts api to output the dropdown for you, or
  • Write you own code to creat pie chart (using SVG or Canvas), or
  • Create div with border. Put dropdown and google chart (without border) inside this div.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.