简体   繁体   English

如何通过使用php和mysql在highcharts中过滤日期

[英]How to filter date in highcharts by using php and mysql

I have two files 1. Analytics.php 2. data_edgefactor.php 我有两个文件1. Analytics.php 2. data_edgefactor.php

Analytics.php Code Analytics.php代码

<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 2. data_edgefactor.php代码

 <?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. 在这里一切正常,图表通过onclick功能根据用户显示,但是我需要过滤年份并根据用户选择年份显示图表。

How to do that. 怎么做。 Please help. 请帮忙。

You can filter your data during preprocessing, or use setExtremes to define your custom range on the axis. 您可以在预处理期间过滤数据,也可以使用setExtremes在轴上定义自定义范围。 http://api.highcharts.com/highcharts#Axis.setExtremes() http://api.highcharts.com/highcharts#Axis.setExtremes()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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