我在Web应用程序上使用HighCharts,以供参考。我从数据库中获取数据,以便为每个用户画一条线。

我遇到的问题是每天添加新的点,并且在说2-3周后,映射了太多的点,以至于该图变成地狱,并且还影响了Web应用程序的性能。

我希望有人能帮助我如何在一周后重置图形或从图形中删除最旧的点并添加新的点。没有运气图只是保持增长。

打印屏幕:


注意图表如何超出预定义的天数。

我的PHP和Mysql $ JavaScript代码:

    <script>
    $(function () {
        $('#home_manager').highcharts({
            title: {
                text: '',
                x: -20 //center
            },
            xAxis: {
                categories: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
            },
            yAxis: {
                title: {
                    text: 'Emails Sent'
                },
                plotLines: [
                    {
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }
                ]
            },
            tooltip: {
                valueSuffix: ''
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                borderWidth: 0
            },

            <?php


        class ManagerStats{

            public function con()
        {
            require_once('connect.php');
            $DB = new dbConnect();
            return $DB->connect();
        }

            public function teamChart(){




            $sql2 = "SELECT tbl_user.user_id, tbl_user.first_name, group_concat( tbl_statistics.sta_count ) AS data_for_user
            FROM tbl_user,tbl_statistics
            WHERE tbl_user.user_id = tbl_statistics.user_id
            GROUP BY tbl_user.user_id";

            $query = mysqli_query($this->con(), $sql2);



            if($query){

                $data = "";
                $data .="series: [";
                foreach($query as $v){

                    $data .= "{

                        name: '".$v['first_name']."',
                        data: [".$v['data_for_user']."]

                },";
            }
            $data .="]";
            echo $data;


        }


        }
    }

    $team = new ManagerStats(); $team->teamChart();


?>
        });
    });
</script>

最佳答案

为什么不将数据限制在SQL查询上?

就像是:

 $sql2 = "SELECT tbl_user.user_id, tbl_user.first_name, group_concat( tbl_statistics.sta_count ) AS data_for_user
            FROM tbl_user,tbl_statistics
            WHERE tbl_user.user_id = tbl_statistics.user_id
            GROUP BY tbl_user.user_id
            ORDER BY sat_date DESC LIMIT 7";


还是datediff来限制它?最近7天的内容如下:

 $sql2 = "SELECT tbl_user.user_id, tbl_user.first_name, group_concat( tbl_statistics.sta_count ) AS data_for_user
            FROM tbl_user,tbl_statistics
            WHERE tbl_user.user_id = tbl_statistics.user_id
            AND Datediff(now(), sat_date) <= 7
            GROUP BY tbl_user.user_id";

关于javascript - 一周后使用PHP重置HighChart,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24013733/

10-09 21:20