流程图不适用于时间和计数

发布于 2025-01-08 19:11:45 字数 2371 浏览 2 评论 0原文

嗨,我需要创建一个流程图。为此,我正在使用这个插件 http://people.iola.dk/olau/flot/ API.txt

我需要在 x 轴上显示时间 (h:m) 并在 y 轴上显示计数。为此我写了这样的脚本。但它不起作用。任何机构都可以帮助我。

var 运行 = false; 变量数组; var xscale = 10;

//该函数进行绘图 
函数绘制(){
    var timearr = getTimeArray();
    this.array=timearr;
    var sTime =“”;
    var oDate = new Date();
    var sTimestamp =“”;
    var exparr = "";
    for (var l = 0; l < 10; l++) {
        sTime = this.array[l][1];
        oDate.setUTCHours(
            parseInt(sTime.substr(0, 2), 10),
            parseInt(sTime.substr(3, 2), 10),
            0,
            0
        );
        sTimestamp = oDate.getTime();
        this.array[l]=[parseInt(l),parseInt(sTimestamp)];
    }
    $.plot(
        $("#graphdiv"),[
            {
                标签:“已登录”,
                数据:这个.array,
                行: { 显示: true, 填充: true, fillColor: "rgba(249, 28, 61,0.3)",lineWidth: 2.5 },
                //颜色:"rgba(249,28,61,1)"
                颜色:0
            }         
        ],
        {
        x 轴:{
            刻度:getTimeArray(1),
            模式:“时间”,
            时间格式:“%H:%M”

        },
        y 轴:{
            刻度: [0, 1, 2, 3,4,5, 6,7,8,9,10],
            分钟:0,
            刻度小数: 0
        },            
        网格: {
            显示:真实,
            颜色: '#474747',
            刻度颜色: '#474747',
            边框宽度:2,
            自动突出显示:真,
            鼠标活动半径:2
        }
    });
}

函数 getTimeArray(flg)
{
    数组=[];
    var d = new Date();
    var 小时='';
    var 分钟='';
    var timeString ='';

    for (var i = 9; i >= 0; i--){
        if(i<9)d = new Date( d.getTime() - 5*60*1000 );
        小时 = d.getHours();
        分钟 = d.getMinutes();
        if (小时 > 12) { 小时 = 小时 - 12; }
        if (小时 == 0) { 小时 = 12; }
        if (小时 < 10) { 小时 = "0" + 小时; }
        if (分钟 < 10) { 分钟 = "0" + 分钟; }
        timeString = 小时 + ':' + 分钟;
        如果(时间字符串!=未定义){
            数组[i]=[i,时间字符串];
        }
    }
    返回数组;
} 


函数初始化(){
    this.array = new Array();
    for (var i = 0; i < xscale; i++) {
        this.array[i] = [i, 0.0];
    }
}

函数刷新状态(){
    如果(!运​​行){
        运行=真;
        画();
        运行=假;
    }
}

$(文档).ready(函数() {
    初始化();
    刷新状态();
    setInterval("refreshStat()", 10);
});

Hi I need to create a flot graph. for that I am using this plugin http://people.iola.dk/olau/flot/API.txt.

I need to show time (h:m) on x axis and counts on y axis. For that I written this kind of a script. But its not working. Any body can help me please.

var running = false;
var array;
var xscale = 10;

//this function does the plotting 
function draw() {
    var timearr = getTimeArray();
    this.array=timearr;
    var sTime ="";
    var oDate = new Date();
    var sTimestamp ="";
    var exparr = "";
    for (var l = 0; l < 10; l++) {
        sTime = this.array[l][1];
        oDate.setUTCHours(
            parseInt(sTime.substr(0, 2), 10),
            parseInt(sTime.substr(3, 2), 10),
            0,
            0
        );
        sTimestamp = oDate.getTime();
        this.array[l]=[parseInt(l),parseInt(sTimestamp)];
    }
    $.plot(
        $("#graphdiv"),[
            {
                label: "Logged In",
                data: this.array,
                lines: { show: true, fill: true, fillColor: "rgba(249, 28, 61,0.3)",lineWidth: 2.5 },
                //color:"rgba(249, 28, 61, 1)"
                color:0
            }         
        ],
        {
        xaxis: {
            ticks: getTimeArray(1),
            mode: "time",
            timeformat: "%H:%M"

        },
        yaxis: {
            ticks: [0 , 1, 2, 3,4,5, 6,7,8,9,10],
            min: 0,
            tickDecimals: 0
        },            
        grid: {
            show: true,
            color: '#474747',
            tickColor: '#474747',
            borderWidth: 2,
            autoHighlight: true,
            mouseActiveRadius: 2
        }
    });
}

function getTimeArray(flg)
{
    array = [];
    var d = new Date();
    var hour='';
    var minute='';
    var timeString ='';

    for (var i = 9; i >= 0; i--){
        if(i<9)d = new Date( d.getTime() - 5*60*1000 );
        hour   = d.getHours();
        minute = d.getMinutes();
        if (hour   > 12) { hour = hour - 12;      }
        if (hour   == 0) { hour = 12;             }
        if (hour   < 10) { hour   = "0" + hour;   }
        if (minute < 10) { minute = "0" + minute; }
        timeString = hour + ':' + minute;
        if(timeString!=undefined){
            array[i]=[i,timeString];
        }
    }
    return array;
} 


function initialize() {
    this.array = new Array();
    for (var i = 0; i < xscale; i++) {
        this.array[i] = [i, 0.0];
    }
}

function refreshStat() {
    if (!running) {
        running = true;
        draw();
        running = false;
    }
}

$(document).ready(function () {
    initialize();
    refreshStat();
    setInterval("refreshStat()", 10);
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘味果▽酱 2025-01-15 19:11:45

您错误地处理了 flot 处理 xaxis 模式“时间”的方式。它想要的是代表 javascript 时间戳的整数 x 值。然后它负责将格式设置为 %H:%M

因此,您有一些复杂的代码来在 %H:%M 中生成值,然后将它们转换为时间戳并将它们传递到 flot 中,然后还指定要显示的刻度。相反,您可以生成所需的时间戳,将它们放入数据数组中,如下所示:

[[1329930943084,0],
 [1329931043084,1],
 ...
 [<timestamp>  ,10]]

就是这样,只需将其输入到 flot 中,无需在 x 或 y 轴上定义刻度。

此外,您的 setInterval 会引发错误,这可能就是您没有取得任何进展的原因。您可以使其更像这样:

setInterval(refreshStat, 10);

这是代码的超级简化版本: http://jsfiddle.net /ryleyb/MaJgn/

You have mistaken how flot deals with xaxis mode "time". What it wants is x values that are integers representing javascript timestamps. It then takes care of the formatting to %H:%M.

So you've got some convoluted code there to make values in %H:%M and then convert them to timestamps and pass them into flot, but then also specify which ticks to show. Instead, you can just generate the timestamps you want, put them into your data array like this:

[[1329930943084,0],
 [1329931043084,1],
 ...
 [<timestamp>  ,10]]

And that's it, just feed that into flot, no need to define the ticks on either x or y axis.

Further, your setInterval throws an error, which may have been why you weren't getting anywhere. You can make that more like this:

setInterval(refreshStat, 10);

Here is a super-simplified version of your code: http://jsfiddle.net/ryleyb/MaJgn/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文