Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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_Jquery_Date_Flot - Fatal编程技术网

Javascript Flot图表显示日期

Javascript Flot图表显示日期,javascript,jquery,date,flot,Javascript,Jquery,Date,Flot,首先,请原谅我的英语! 我想用jquery显示flot图表。我的代码如下: charts.chart_simple = { // data data: { d1: [] }, // will hold the chart object plot: null, // chart options options: { grid: { color:

首先,请原谅我的英语! 我想用jquery显示flot图表。我的代码如下:

charts.chart_simple = 
{
    // data
    data: 
    {
        d1: []
    },

    // will hold the chart object
    plot: null,

    // chart options
    options: 
    {
        grid: 
        {
            color: "#dedede",
            borderWidth: 1,
            borderColor: "transparent",
            clickable: true, 
            hoverable: true
        },
        series: {
            lines: {
                show: true,
                fill: false,
                lineWidth: 2,
                steps: false
            },
            points: {
                show:true,
                radius: 5,
                lineWidth: 3,
                fill: true,
                fillColor: "#000"
            }
        },
        xaxis: {
            mode: "time",
            tickColor: 'transparent',
            tickDecimals: 2,
            tickSize: 2
        },
        yaxis: {
            tickSize: 10
        },
        legend: { position: "nw", noColumns: 2, backgroundColor: null,                   backgroundOpacity: 0 },
        shadowSize: 0,
        tooltip: true,
        tooltipOpts: {
            content: "%s : %y.3",
            shifts: {
                x: -30,
                y: -50
            },
            defaultTheme: false
        }
    },

    placeholder: "#chart_simple",

    // initialize
    init: function()
    {
        // this.options.colors = ["#72af46", "#466baf"];
        this.options.colors = [successColor, primaryColor];
        this.options.grid.backgroundColor = { colors: ["#fff", "#fff"]};

        var that = this;

        if (this.plot == null)
        {
            this.data.d1 = new Array();
            var o = 0;
            for(var i = 0; i < data.length; i++){                   
                var group = data[i];

                for(var e = 0; e < group.length; e++){                      
                    var elem = new Array(date, intVal);

                    this.data.d1[o] = elem;
                    o++;
                }                   
            }               
        }
        this.plot = $.plot(
            $(this.placeholder),
            [{
                label: "Consumo Medio", 
                data: this.data.d1,
                lines: { fill: 0.05 },
                points: { fillColor: "#fff" }
            }], this.options);
    }
};

// uncomment to init on load
charts.chart_simple.init();
charts.chart\u简单=
{
//资料
数据:
{
d1:[]
},
//将保存图表对象
绘图:空,
//图表选项
选项:
{
网格:
{
颜色:“dedede”,
边框宽度:1,
边框颜色:“透明”,
可点击:正确,
可悬停:正确
},
系列:{
线路:{
秀:没错,
填充:假,
线宽:2,
步骤:false
},
要点:{
秀:没错,
半径:5,
线宽:3,
填充:是的,
填充颜色:“000”
}
},
xaxis:{
模式:“时间”,
tickColor:'透明',
小数点:2,
尺寸:2
},
亚克斯:{
尺码:10
},
图例:{位置:“nw”,无列:2,背景颜色:null,背景不透明度:0},
阴影大小:0,
提示:正确,
工具提示:{
内容:“%s:%y.3”,
班次:{
x:-30,
y:-50
},
defaultTheme:false
}
},
占位符:“图表简单”,
//初始化
init:function()
{
//this.options.colors=[“#72af46”、“#466baf”];
this.options.colors=[successColor,primaryColor];
this.options.grid.backgroundColor={colors:[“#fff”,“#fff”]};
var=这个;
if(this.plot==null)
{
this.data.d1=新数组();
VarO=0;
对于(var i=0;i
问题在于变量“日期”。如果我输入一个数字,它就工作得很好。
变量“date”的格式为->2014-02-26

您必须使用时间戳。有关解释和示例,请参见。

非常感谢您的回复

最后我找到了解决办法

var data1 = new Array();
    var o = 0;

    for(var i = 0; i < data.length; i++){

        var group = data[i];

        for(var e = 0; e < group.length; e++){

            var date = group[e][0];
            var year = date.substring(0,4)
            var month = date.substring(5,7)
            var day = date.substring(8,10)
            console.log(year + " | " + month + " | " + day);

            var elem = new Array(gd(year, month, day), (group[e][1]/group[e][2]));

            data1[o] = elem;
            o++;
        }

    }

var dataset = [
    {
        label: "Consumo Semana",
        data: data1,
        color: "#FF0000",
        xaxis:2,
        points: { fillColor: "#FF0000", show: true },
        lines: { show: true }
    }
];

var dayOfWeek = ["Dom", "Lun", "Mar", "Mie", "Jue", "Vie", "Sab"];

var options = {
        series: {
             shadowSize: 5
        },
        xaxis: {
            mode: "time",
            tickSize: [1, "month"],
            tickLength: 0,
            axisLabel: "2012",
            axisLabelUseCanvas: true,
            axisLabelFontSizePixels: 12,
            axisLabelFontFamily: 'Verdana, Arial',
            axisLabelPadding: 10
        },
       yaxis: {
            color: "black",
            tickDecimals: 2,
            axisLabel: "Gold Price  in USD/oz",
            axisLabelUseCanvas: true,
            axisLabelFontSizePixels: 12,
            axisLabelFontFamily: 'Verdana, Arial',
            axisLabelPadding: 5
        },
        xaxes: [{
            mode: "time",       
            tickFormatter: function (val, axis) {           
                return dayOfWeek[new Date(val).getDay()];
            },
            color: "black",
            position: "top",       
            axisLabel: "Weekday",
            axisLabelUseCanvas: true,
            axisLabelFontSizePixels: 12,
            axisLabelFontFamily: 'Verdana, Arial',
            axisLabelPadding: 5
        },
        {
            mode: "time",
            timeformat: "%d/%m",
            tickSize: [1, "day"],
            color: "black",       
            axisLabel: "Date",
            axisLabelUseCanvas: true,
            axisLabelFontSizePixels: 12,
            axisLabelFontFamily: 'Verdana, Arial',
            axisLabelPadding: 10
        }],
        grid: {
            hoverable: true,
            borderWidth: 2,
            borderColor: "#633200",
            backgroundColor: { colors: ["#ffffff", "#EDF5FF"] }
        },
        colors: ["#FF0000", "#0022FF"]
    };


        $.plot($("#chart_simple_2"), dataset, options);


function gd(year, month, day) {
return new Date(year, month - 1, day).getTime();
}
var data1=新数组();
VarO=0;
对于(变量i=0;i
问题在于我引入日期数据的方式。通过本教程,我找到了答案

再次非常感谢


问候

您应该对此进行详细说明,使其成为一页资源,供遇到此问题的人使用,而不仅仅是提供链接。这取决于日期变量的填充方式(客户端/服务器端)。在这里描述所有的可能性都太过分了。考虑到
date='2014-02-26'
newdate(date)
可能会奏效