Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.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 flot标记功能,未定义轴?_Javascript_Flot - Fatal编程技术网

Javascript flot标记功能,未定义轴?

Javascript flot标记功能,未定义轴?,javascript,flot,Javascript,Flot,使用以下选项创建图形时,flot会正确绘制图形: var options = { colors: trendcolors, series: { points: { show: true }, lines: { show: true }

使用以下选项创建图形时,flot会正确绘制图形:

var options = {
            colors: trendcolors,
            series: {
                points: {
                    show: true
                },
                lines: {
                    show: true
                }
            },
            xaxis: {
                mode: "time",
                axisLabel: "Date/Time",
                tickLength: 0
            },
            yaxis: {
                axisLabel: "Duration (Sec)"
            },
            selection: {
                mode: "x"
            },
            grid: {
                hoverable: true,
                clickable: true,
                markings: function (axes) {
                    var markings = [];
                    var date = new Date(axes.xaxis.min);
                    date.setUTCSeconds(0);
                    date.setUTCMinutes(0);
                    date.setUTCHours(0);
                    var i = date.getTime();
                    do {
                        markings.push({xaxis:{from: i, to: i + (24 * 60 * 60 * 1000) }, color: colormarking } );
                        i += ((24 * 60 * 60 * 1000) * 2);
                    } while (i < axes.xaxis.max);
                    return markings;
                }
            },
            legend: {
                labelFormatter: function(label, series) { 
                            return label + " (" + series.data.length + ")";
                        }
            }
        };

顺便说一下,fMarkings是在另一个js块中全局定义的。

markes参数需要一个函数或数组。不过,您所做的是在定义options对象时调用函数。在那里调用时,axes变量不存在。您需要的只是:

    grid: {
        hoverable: true,
        clickable: true,
        markings: fMarkings
    },
其中,F标记是一个函数,类似于:

fMarkings = function(axes){
   return arrayOfMarkings
}
fMarkings = function(axes){
   return arrayOfMarkings
}