duanmoen784988 2016-05-30 11:03
浏览 36

在PHP中提交日期范围后刷新高图表

am working in PHP. i am using High Chart , dynamically taking data from DB. Now i want to show data between certain date range. Data between certain date range is successfully fetched from DB but now how to refresh the Chart ??

JS Code :

` function piechart() {

        var date_from   = $("#date_from").val();
        var date_to     = $("#date_to").val();
        var dataString = 'date_from=' + date_from + '&date_to=' + date_to;

        $.ajax({
            type: "GET",
            url: "pages/dashboard/chart_data.php",
            data: dataString,
            cache: false,
            success: function(html) {

        }
        });

        return false;
        }
    $(document).ready(function() {
        var options = {
            chart: {
                renderTo: 'container',
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            title: {
                text: 'Current Year Sales Report'
            },
            tooltip: {
                formatter: function() {
                    return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
                }
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        color: '#000000',
                        connectorColor: '#000000',
                        formatter: function() {
                            return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
                        }
                    }
                }
            },
            series: [{
                type: 'pie',
                name: 'Sales (Rupees)',
                data: []
            }]
        }

        $.getJSON("chart_data.php", function(json) {
            options.series[0].data = json;
            chart = new Highcharts.Chart(options);
        });



    });  

`

and chart_data.php

`

if($date_from !='' AND $date_to !='')
{
    $where = "tran_date >='$date_from' AND tran_date <= '$date_to'";
    echo $db->piechart($where);
}
else
echo $db->piechart();

?> `

Any help will be highly appreciated.

  • 写回答

1条回答 默认 最新

  • dongsuiwo0279 2016-05-30 11:22
    关注

    It looks like it is JavaScript question. You should move your code inside

    `$(document).ready(function() {`
    

    block into the function and execute it each time your date range fields are changed or then document is loaded first time.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据