简体   繁体   中英

How to filter date in highcharts by using php and mysql

I have two files 1. Analytics.php 2. data_edgefactor.php

Analytics.php Code

<script type="text/javascript">
   function show_auth(auth_id){
   $.post("analysis_table/show_table_ef.php", {AUTHID_TEST_EF: ""+auth_id+""}, function(data_ef){           

    if(data_ef.length > 0) {
    //////////////////////DATA OUTPUT//////////////////////

        document.getElementById('get_table_ef').innerHTML = data_ef;
    }

}); 

 $.post("analysis_table/data_edgefactor.php", {AUTHID_TEST_EF: ""+auth_id+""}, function(data_ef){   

        var options = {
        chart: {
                renderTo: 'container_edgefactor',
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },

             xAxis: {
                 title: {
                    text: 'Year'
                },
                 categories: []
                },

               yAxis: {
                    title: {
                        text: 'Number of Citations'
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },

            series: [{
                type: 'line',
        name: 'Citations',
                data: []
            }]
        }

        $.getJSON("analysis_table/data_edgefactor.php", {AUTHID_TEST_EF:auth_id}, function(data_ef) {
        options.series[0].data = data_ef;
            chart = new Highcharts.Chart(options);
        });

}); 

  }
</script>


  <?php
    echo '<a href="#" style="text-decoration:none; color: #000;" onClick="show_auth('.$id_auth.')">'.$get_auth.'</a>'; ?>                                                             

 <div id="container_edgefactor" style="width: 900px; height: 400px; "></div>

 <select name="from_year">
      <option value="1988">1988</option>
      <option value="1989">1989</option>
      <option value="1990">1990</option>
 </select>
       and 
 <select name="to_year">
      <option value="1991">1991</option>
      <option value="1992">1992</option>
      <option value="1993">1993</option>
 </select>

  <input id="fixsubmit" type="submit" name="update_citations" value="Update Graph">

2.data_edgefactor.php code

 <?php

  include '../connect.php';

  $get = $_REQUEST['AUTHID_TEST_EF'];
  $result_citations = mysql_query("SELECT year, citations, auth_id FROM subj_area  WHERE auth_id='$get'");
$rows_citations = array();
  while($r_citations = mysql_fetch_array($result_citations)) {
$row_citations[0] = $r_citations[0];
$row_citations[1] = $r_citations[1];
array_push($rows_citations,$row_citations);
  }

 print json_encode($rows_citations, JSON_NUMERIC_CHECK);

?>

Here everything is working fine, the graph is showing according to the user by onclick function, but i need to filter the year and show the graph according to user chooses the year.

How to do that. Please help.

You can filter your data during preprocessing, or use setExtremes to define your custom range on the axis. http://api.highcharts.com/highcharts#Axis.setExtremes()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM