1. 程式人生 > >jquery datepicker 點選同步重新整理echarts資料顯示功能

jquery datepicker 點選同步重新整理echarts資料顯示功能

 function doexit() {
        $.ajax({
            url:"<c:url value='/register/exit'/>",
            type:"post",
            dataType:"json",
            async:true,
            success:function(result){
                alert("退出成功");
                window.location.href="<c:url value='/register/login.jsp'/>";
            },
            error:function(){
                alert("退出失敗");
            }
        });

    }
    function doready(date){
        var dates = new Array();
        var datas = new Array();
        var surplusEnergy = new Array();
        var today;
        var yest;
        var supr;
        $.ajax({
            url: "<c:url value="/energyInfo/dateEnergyInfos"/>",
            type: "post",
            data: {"date": date},
            dataType: "json",
            async: false,
            success: function (result) {
                var datesa=date.split("/");
                date="";
                date = datesa[2]+"-"+datesa[0]+"-"+datesa[1];
                $.each(result, function (index, obj) {
                    dates.push(obj.dateEnergy);
                    datas.push(obj.todatEnergy);
                    surplusEnergy.push(obj.surplusEnergy);
                    if(obj.dateEnergy==date){
                        today = obj.todatEnergy;
                        yest = obj.yestdatEnergy;
                        supr = obj.surplusEnergy;
                    }
                });
            },
            error: function () {
            }
        });
        var lineChartData = {
            labels: dates,
            datasets: [
                {
                    label: "My First dataset",
                    fillColor: "rgba(255,44,44,0.2)",
                    strokeColor: "rgba(255,44,44,1)",
                    pointColor: "rgba(255,44,44,1)",
                    pointStrokeColor: "#fff",
                    pointHighlightFill: "#fff",
                    pointHighlightStroke: "rgba(255,44,44,1)",
                    data: datas
                },
                {
                    label: "My Second dataset",
                    fillColor: "rgba(48, 164, 255, 0.2)",
                    strokeColor: "rgba(48, 164, 255, 1)",
                    pointColor: "rgba(48, 164, 255, 1)",
                    pointStrokeColor: "#fff",
                    pointHighlightFill: "#fff",
                    pointHighlightStroke: "rgba(48, 164, 255, 1)",
                    data: surplusEnergy
                }
            ]

        }
        var chart1 = document.getElementById("line-chart").getContext("2d");
        window.myLine = new Chart(chart1).Line(lineChartData, {
            responsive: true
        });


        $("#dateEnergy").html(date);
        $("#today").html(today);
        $("#yest").html(yest);
        $("#supr").html(supr);

    }
後端請求的controller中的dateEnergyInfos函式: