从json php使用datepicker更新jquery flot

从json php使用datepicker更新jquery flot,php,jquery,json,datepicker,flot,Php,Jquery,Json,Datepicker,Flot,脚本将根据所选的datepicker范围从-到-但仅到div结果,从php文件返回正确的json_encode数组 如何使用这个json_编码结果数据来绘制jquery flot $(function () { function updateResults() { // Load response from results.php into #results element $('#results').load('results.php',

脚本将根据所选的datepicker范围从-到-但仅到div结果,从php文件返回正确的json_encode数组

如何使用这个json_编码结果数据来绘制jquery flot

$(function () {
    function updateResults() {
        // Load response from results.php into #results element
        $('#results').load('results.php', 
        { // With these parameters
            from_date: fromDate.datepicker('getDate').toString(),
            to_date: toDate.datepicker('getDate').toString()
        });
    }

    //create a couple of date textboxes
    $.datepicker.setDefaults({
        dateFormat: 'dd/mm/yy',
        defaultDate: '-1w',
        changeMonth: true,
        changeYear: true,
        maxDate: 0,
        showButtonPanel: true,
        showWeek: true
    });

    var fromDate = $('#from').datepicker({
        onSelect: function () {
            var option = this.id == 'from' ? 'minDate' : 'maxDate';
            toDate.not(this).datepicker('option', option, $(this).datepicker('getDate'));
            updateResults(); // When a new date is selected update the results
        }
    });

    var toDate = $('#to').datepicker({
        onSelect: function () {
            updateResults(); // When a new date is selected update the results
        }
    });

    //Set the default from and to dates.
    fromDate.datepicker('setDate', '-1w');
    toDate.datepicker('setDate', '+0');
    updateResults(); // Initial call on load
});
load函数用于将HTML加载到DOM元素中。要加载JSON数据,请使用jQuery.getJSON函数,如下所示:

function updateResults() {
    $.getJSON('results.php', {
        from_date: fromDate.datepicker('getDate').toString(),
        to_date: toDate.datepicker('getDate').toString()
    }, function(data, status, xhr) {
        $.plot('#results', [data], options);
    });
}

这假设数据的flot格式正确。

检查unix/mysql timedata*1000->flot x轴时间是否正确?
Flot需要毫秒时间数据

results.php的结果是什么样的?是JSON吗?以flot的正确格式?它是HTML吗?results.php是$_POST,它使用from_date和to_date进行mysql查询,并输出echo json_encode和选定范围内的数据。它不是HTML格式的。我应该把这个函数放在哪里根据datepicker range select检索数据?在updateResults函数中,它用load函数替换旧代码。查看我的编辑。现在我在xaxis上的时间仅为1.1.1970。我认为JSON还可以:[[1431468001000,15.8],[1431468301000,15.8],[1431468601000,15.8]]看起来还可以。要说得更多,我必须更详细地查看数据/代码,例如,作为一个.奇怪的东西。如果我将显示的JSON放在JSON_encode中,它会显示在flot perfect中,但当它从mysql查询拉到JSON_encode时,它不会显示,并且日期总是1.1.1970。echo json\u encodearray$dataset,json\u数字\u检查;echo json_encodearray[[143154402000,16.6],[143154701000,16.6]],json_数字检查;但若我只是在屏幕上显示数组,它是相同的。