Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jqPlot中的时间间隔问题_Javascript_Jquery_Jqplot - Fatal编程技术网

Javascript jqPlot中的时间间隔问题

Javascript jqPlot中的时间间隔问题,javascript,jquery,jqplot,Javascript,Jquery,Jqplot,我是jqplot的新手,但我正在一个非常重要的项目中使用它。我试图让x轴每天都有一个“滴答声”——到目前为止,有多个滴答声。以下是一个屏幕截图: 下面是代码(我在其中还添加了一个最小值和最大值作为): 即使我手动设置如下点击: $(document).ready(function(){ var ajaxDataRenderer = function(url, plot, options) {

我是jqplot的新手,但我正在一个非常重要的项目中使用它。我试图让x轴每天都有一个“滴答声”——到目前为止,有多个滴答声。以下是一个屏幕截图:

下面是代码(我在其中还添加了一个最小值和最大值作为):

即使我手动设置如下点击:

 $(document).ready(function(){

                            var ajaxDataRenderer = function(url, plot, options) {
                                var ret = null;
                                $.ajax({
                                    async: false,
                                    url: url,
                                    type: "GET",
                                    dataType:"json",
                                    data: {metricName: ""},
                                    success: function(data) {
                                        ret = data;
                                    },
                                    error:function (xhr, ajaxOptions, thrownError){
                                        alert(xhr.responseText);
                                    }    
                                });
                                return ret;
                            };

                            //var jsonurl = "reports/reportData.json";
                            var jsonurl = "tenant/metrics/get.json";

                            var today = new Date();

                            var plot2 = $.jqplot('chart2', jsonurl,{
                                title: "",
                                dataRenderer: ajaxDataRenderer,
                                dataRendererOptions: {unusedOptionalUrl: jsonurl},
                                axes: {
                                    xaxis: {
                                        'numberTicks' : 7,
                                        min: '2012-10-05',
                                        max: today,
                                        renderer:$.jqplot.DateAxisRenderer,
                                        rendererOptions:{tickRenderer:$.jqplot.CanvasAxisTickRenderer},
                                        ticks: ['2012-10-05','2012-10-06','2012-10-07','2012-10-08', today],
                                        tickOptions:{formatString:'%Y-%#m-%#d'

                                        }
                                        //rendererOptions: {sdaTickInterval: [1, 'month']}

                                    },
                                    yaxis: {
                                        label: "MB",
                                        tickOptions:{formatString:'%d '},
                                        // Comment the next line out to allow negative values (and therefore rounded ones)
                                        min: 0
                                    }
                                }   
                            });
                        });
标记与正确日期不符。以下是一个屏幕截图:

有没有明智的方法可以做到这一点?我希望每个x轴记号仅为一个日期,并且数据输入标记位于该记号的轴上

这快把我逼疯了!请帮忙

还有,这是我的json

[[["2012-10-05 10:57:16AM", 0],["2012-10-05 11:02:14AM", 2449],["2012-10-08 08:17:47AM", 9639],["2012-10-08 08:17:53AM", 224768],["2012-10-09 07:43:19AM", 9640],["2012-10-09 07:44:01AM", 224769]]]

格式字符串不正确,因为它不包含时间戳;尝试将其更改为以下内容:

tickOptions:{formatString:'%y-%#m-%#d%n%#I:%#M:%#S%p}
或者,如果不需要时间戳,请保持格式字符串不变,并从JSON中删除时间戳

编辑

如果上述格式字符串不起作用,请尝试使用以下值操纵值以匹配:

// Year
%Y  2008
%y  08

// Month
%m  09
%#m  9
%B  September
%b  Sep

// Day
%d  05
%#d  5
%e  5
%A  Sunday
%a  Sun
%w  0, 0 = Sunday, 6 = Saturday
%o  th, The ordinal suffix string following the day of the month

// Hour
%H  23
%#H  3
%I   11
%#I  3
%p  PM, AM or PM

// Minute
%M  09
%#M  9

// Second
%S  02
%#S  2
%s  1206567625723, Unix timestamp, seconds past 1970-01-01 00:00:00

// Millisecond
%N  008
%#N  8

我希望这有帮助

你可以发布你的JSON;我敢打赌你的问题可能就在那里。刚刚发布。这有帮助吗?也许是时间戳把它扔了?这非常有帮助,让我走上了正确的道路!主要的问题是时间戳使得网格在某种意义上“过于精确”,因为我只希望它们落在准确的日期上。因此,我必须更改服务器端/JSON上的内容,使时间戳不会出现在传入的JSON中,然后更改JS中的max/min日期,使其不包含时间戳。谢谢你的帮助!
// Year
%Y  2008
%y  08

// Month
%m  09
%#m  9
%B  September
%b  Sep

// Day
%d  05
%#d  5
%e  5
%A  Sunday
%a  Sun
%w  0, 0 = Sunday, 6 = Saturday
%o  th, The ordinal suffix string following the day of the month

// Hour
%H  23
%#H  3
%I   11
%#I  3
%p  PM, AM or PM

// Minute
%M  09
%#M  9

// Second
%S  02
%#S  2
%s  1206567625723, Unix timestamp, seconds past 1970-01-01 00:00:00

// Millisecond
%N  008
%#N  8