jQuery和Flot堆叠线与实时图表

时间:2012-10-05 13:28:43

标签: jquery json stack real-time flot

当我在由JSON文件提供的基于行的实时图形上执行堆栈选项时,我会显示图例,但是我在图表上放松了这些线条。

没有堆叠也没有线路。 有没有人遇到过这个?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Real Time Chart</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript" src="../excanvas.min.js"></script>
<script language="javascript" type="text/javascript" src="../jquery-1.8.1.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.stack.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.axislabels.js"></script>
</head>
<body>
<h1>Test</h1>
<table>
    <tr>
        <td>
            <div id="controlm" style="width:1200px;height:600px; margin:0 auto;"></div>
        </td>
        <td>
            <p id="Legend" style="width:200px;margin-left:10px"></p>
        </td>
    </tr>
</table>
<script type="text/javascript">


$(function () {

    // variables setup
    var data = [];  
    var controlm = $("#controlm");
    var stack = 0, bars = true, lines = true, steps = false;
    var options = {
        series: {stack: stack,
                shadowSize: 0,
                lines: {show: lines, fill: false, steps: steps}
                },
        xaxis: { mode: "time", timeformat: "%Hh%M", axisLabel: 'Tijdlijn', position: 'bottom', axisLabelPadding: 10},
        yaxis: { mode: "number", tickSize: 100, max: 1000, axisLabel: "Aantal Jobs", position: 'left', axisLabelPadding: 10},
        grid: { hoverable: true, clickable: true, backgroundColor: { colors: ["#FFFFFF", "#999999"] }, markings: [{lineWidth:4, yaxis: {from: 3500, to: 3500}, color: "#000000"}]},
        legend: {container: $("#Legend"), show: true, backgroundOpacity:0}
    };

    function showTooltip(x, y, contents) {
        $('<div id="tooltip">' + contents + '</div>').css( {
            position: 'absolute',
            display: 'none',
            top: y + 15,
            left: x + 15,
            border: '1px solid #088A29',
            padding: '2px',
            'background-color': '#A9F5BC',
            opacity: 1
        }).appendTo("body").fadeIn(0);
    }

    var previousPoint = null;
    $("#controlm").bind("plothover", function (event, pos, item) {
        $("#x").text(pos.x.toFixed(2));
        $("#y").text(pos.y.toFixed(2));

            if (item) {
                if (previousPoint != item.dataIndex) {
                    previousPoint = item.dataIndex;

                    $("#tooltip").remove();
                    var x = item.datapoint[0].toFixed(2),
                        y = item.datapoint[1].toFixed(2);
                    var tooltipdate = new Date(parseInt(x));
                    var year = tooltipdate.getFullYear();
                    var month = (tooltipdate.getMonth() + 1);
                    if (month < 10) {month = "0" + month};                      
                    var day = tooltipdate.getDate();
                    if (day < 10) {day = "0" + day};
                    var hour = tooltipdate.getUTCHours();
                    if (hour < 10) {hour = "0" + hour};
                    var min =  tooltipdate.getMinutes();
                    if (min < 10) {min = "0" + min};
                    var content = day + "/" + month + "/" + year + " " + hour + ":" + min;
                    showTooltip(item.pageX, item.pageY,"<b>" + content + "</b><br />" + 
                                item.series.label);

                }
            }
            else {
                $("#tooltip").remove();
                previousPoint = null;            
            }
    });

    function fetchData() {

        $.ajax({
            // usually, we'll just call the same URL, a script
            // connected to a database, but in this case we only
            // have static example files so we need to modify the
            // URL
            url: "test/blabla.txt",
            method: 'GET',
            dataType: 'json',
            success: onDataReceived

        });

        function onDataReceived(series) {

            data = [series];
            //fill array
            $.each(series, function(key) {//, val) {
                data.push(series[key]);
            });

            $.plot(controlm, data, options);

        }           

        return data

    }

plot = $.plot(controlm, fetchData(), options);

function update() {
    plot.setData([fetchData()]);
    plot.draw();

    setTimeout(update, 120000);
}

update();
});
</script>

 </body>
</html>

JSON数据的一部分:

[ { "label": "Totaal Jobs QOS : 41", "data": [[1349364129000,42],[1349364427000,42],[1349364727000,42],[1349365026000,42],[1349365327000,42],[1349365628000,42],[1349365927000,42],[1349366225000,42],[1349366532000,42],[1349366826000,42],[1349367126000,42],[1349367428000,42],[1349367728000,42],[1349368026000,42],[1349368324000,42],[1349368626000,42],[1349368926000,42],[1349369226000,42],[1349369527000,42],[1349369826000,42],[1349370126000,42],[1349370424000,42],[1349370726000,42],[1349371026000,42],[1349371325000,42],[1349371626000,42],[1349371926000,42],[1349372226000,42],[1349372526000,42],[1349372827000,42],[1349373127000,42],[1349373426000,42],[1349377412000,42],[1349377685000,42],[1349377984000,42],[1349378286000,42],[1349378588000,42],[1349378885000,42],[1349379187000,46],[1349379484000,50],[1349379785000,50],[1349380085000,50],[1349380391000,50],[1349380682000,50],[1349380989000,50],[1349381289000,50],[1349381583000,50],[1349381885000,50],[1349382186000,50],[1349382488000,50],[1349382782000,50],[1349383085000,50],[1349383382000,50],[1349383686000,50],[1349383986000,50],[1349384283000,50],[1349384589000,50],[1349384883000,50],[1349385186000,50],[1349385486000,50],[1349385789000,50],[1349386089000,50],[1349386389000,50],[1349386689000,50],[1349386989000,50],[1349387286000,50],[1349387589000,50],[1349387888000,50],[1349388189000,50],[1349388486000,50],[1349388789000,50],[1349389086000,50],[1349389385000,50],[1349389689000,50],[1349389989000,50],[1349390289000,50],[1349390589000,50],[1349390887000,50],[1349391189000,50],[1349391486000,50],[1349391789000,50],[1349392087000,50],[1349392386000,50],[1349392685000,50],[1349392990000,50],[1349393285000,50],[1349393589000,50],[1349393887000,50],[1349394184000,50],[1349394485000,50],[1349394789000,50],[1349395083000,50],[1349395384000,50],[1349395688000,50],[1349395985000,50],[1349396283000,50],[1349396590000,50],[1349396886000,50],[1349397187000,50],[1349397484000,50],[1349397784000,50],[1349398085000,50],[1349398390000,50],[1349398686000,50],[1349398984000,50],[1349399290000,50],[1349399589000,50],[1349399887000,50],[1349400186000,50],[1349400485000,50],[1349400787000,50],[1349401084000,50],[1349401385000,50],[1349401687000,50],[1349401990000,50],[1349402286000,50],[1349402589000,50],[1349402890000,50],[1349403189000,50],[1349403484000,50],[1349403784000,50],[1349404087000,50],[1349404384000,50],[1349404689000,50],[1349404990000,50],[1349405286000,50],[1349405586000,50],[1349405889000,50],[1349406189000,50],[1349406485000,50],[1349406786000,50],[1349407087000,50],[1349407389000,50],[1349407684000,50],[1349407987000,50],[1349408291000,50],[1349408589000,50],[1349408886000,50],[1349409185000,50],[1349409487000,50],[1349409786000,50],[1349410086000,50],[1349410389000,50],[1349410687000,50],[1349410984000,50],[1349411284000,50],[1349411590000,50],[1349411890000,50],[1349412189000,50],[1349412487000,50],[1349412785000,50],[1349413086000,50],[1349413387000,50],[1349413687000,50],[1349413989000,50],[1349414286000,50],[1349414590000,50],[1349414886000,50],[1349415186000,50],[1349415484000,50],[1349415784000,50],[1349416087000,50],[1349416389000,50],[1349416689000,50],[1349416986000,50],[1349417289000,50],[1349417584000,50],[1349417884000,50],[1349418186000,50],[1349418486000,50],[1349418785000,50],[1349419090000,50],[1349419389000,50],[1349419689000,50],[1349419989000,50],[1349420286000,50],[1349420586000,50],[1349420890000,50],[1349421186000,50],[1349421486000,50],[1349421784000,50],[1349422086000,50],[1349422384000,50],[1349422686000,50],[1349422989000,50],[1349423285000,50],[1349423584000,50],[1349424449000,38],[1349424726000,38],[1349425030000,38],[1349425330000,38],[1349425629000,38],[1349425926000,38],[1349426225000,38],[1349426526000,38],[1349426829000,38],[1349427124000,38],[1349427427000,38],[1349427727000,38],[1349428029000,38],[1349428327000,38],[1349428630000,38],[1349428930000,38],[1349428951000,38],[1349429526000,38],[1349429825000,38],[1349430123000,38],[1349430424000,38],[1349430725000,38],[1349431029000,38],[1349431329000,38],[1349431624000,38],[1349431927000,38],[1349432226000,38],[1349432525000,38],[1349432830000,38],[1349433125000,38],[1349433424000,38],[1349433726000,38],[1349434024000,38],[1349434324000,38],[1349434624000,38],[1349434924000,39],[1349435230000,39],[1349435526000,39],[1349435826000,39],[1349436127000,39],[1349436426000,39],[1349436727000,39],[1349437024000,39],[1349437326000,39],[1349437629000,39],[1349437929000,41],[1349438226000,41],[1349438527000,41],[1349438827000,41],[1349439127000,41],[1349439428000,41],[1349439728000,41],[1349440024000,41],[1349440324000,41],[1349440630000,41],[1349440927000,41],[1349441229000,41],[1349441524000,41],[1349441827000,41],[1349442127000,41],[1349442430000,41],[1349442726000,41],[1349443027000,41],[1349443326000,41],[1349443627000,41],[1349443925000,41],[1349444230000,41],[1349444527000,41],[1349444826000,41],[1349445126000,41],[1349445427000,41],[1349445726000,41],[1349446030000,41],[1349446324000,41],[1349446630000,41],[1349446927000,41],[1349447227000,41],[1349447527000,41],[1349447824000,41],[1349448126000,41],[1349448426000,41],[1349448727000,41],[1349449027000,41],[1349449329000,41],[1349449627000,41],[1349449926000,41],[1349450226000,41]] }, { "label": "Totaal Jobs QXS : 1", "data": [[1349364129000,1],[1349364427000,1],[1349364727000,1],[1349365026000,1],[1349365327000,1],[1349365628000,1],[1349365927000,1],[1349366225000,1],[1349366532000,1],[1349366826000,1],[1349367126000,1],[1349367428000,1],[1349367728000,1],[1349368026000,1],[1349368324000,1],[1349368626000,1],[1349368926000,1],[1349369226000,1],[1349369527000,1],[1349369826000,1],[1349370126000,1],[1349370424000,1],[1349370726000,1],[1349371026000,1],[1349371325000,1],[1349371626000,1],[1349371926000,1],[1349372226000,1],[1349372526000,1],[1349372827000,1],[1349373127000,1],[1349373426000,1],[1349377412000,1],[1349377685000,1],[1349377984000,1],[1349378286000,1],[1349378588000,1],[1349378885000,1],[1349379187000,1],[1349379484000,1],[1349379785000,1],[1349380085000,1],[1349380391000,1],[1349380682000,1],[1349380989000,1],[1349381289000,1],[1349381583000,1],[1349381885000,1],[1349382186000,1],[1349382488000,1],[1349382782000,1],[1349383085000,1],[1349383382000,1],[1349383686000,1],[1349383986000,1],[1349384283000,1],[1349384589000,1],[1349384883000,1],[1349385186000,1],[1349385486000,1],[1349385789000,1],[1349386089000,1],[1349386389000,1],[1349386689000,1],[1349386989000,1],[1349387286000,1],[1349387589000,1],[1349387888000,1],[1349388189000,1],[1349388486000,1],[1349388789000,1],[1349389086000,1],[1349389385000,1],[1349389689000,1],[1349389989000,1],[1349390289000,1],[1349390589000,1],[1349390887000,1],[1349391189000,1],[1349391486000,1],[1349391789000,1],[1349392087000,1],[1349392386000,1],[1349392685000,1],[1349392990000,1],[1349393285000,1],[1349393589000,1],[1349393887000,1],[1349394184000,1],[1349394485000,1],[1349394789000,1],[1349395083000,1],[1349395384000,1],[1349395688000,1],[1349395985000,1],[1349396283000,1],[1349396590000,1],[1349396886000,1],[1349397187000,1],[1349397484000,1],[1349397784000,1],[1349398085000,1],[1349398390000,1],[1349398686000,1],[1349398984000,1],[1349399290000,1],[1349399589000,1],[1349399887000,1],[1349400186000,1],[1349400485000,1],[1349400787000,1],[1349401084000,1],[1349401385000,1],[1349401687000,1],[1349401990000,1],[1349402286000,1],[1349402589000,1],[1349402890000,1],[1349403189000,1],[1349403484000,1],[1349403784000,1],[1349404087000,1],[1349404384000,1],[1349404689000,1],[1349404990000,1],[1349405286000,1],[1349405586000,1],[1349405889000,1],[1349406189000,1],[1349406485000,1],[1349406786000,1],[1349407087000,1],[1349407389000,1],[1349407684000,1],[1349407987000,1],[1349408291000,1],[1349408589000,1],[1349408886000,1],[1349409185000,1],[1349409487000,1],[1349409786000,1],[1349410086000,1],[1349410389000,1],[1349410687000,1],[1349410984000,1],[1349411284000,1],[1349411590000,1],[1349411890000,1],[1349412189000,1],[1349412487000,1],[1349412785000,1],[1349413086000,1],[1349413387000,1],[1349413687000,1],[1349413989000,1],[1349414286000,1],[1349414590000,1],[1349414886000,1],[1349415186000,1],[1349415484000,1],[1349415784000,1],[1349416087000,1],[1349416389000,1],[1349416689000,1],[1349416986000,1],[1349417289000,1],[1349417584000,1],[1349417884000,1],[1349418186000,1],[1349418486000,1],[1349418785000,1],[1349419090000,1],[1349419389000,1],[1349419689000,1],[1349419989000,1],[1349420286000,1],[1349420586000,1],[1349420890000,1],[1349421186000,1],[1349421486000,1],[1349421784000,1],[1349422086000,1],[1349422384000,1],[1349422686000,1],[1349422989000,1],[1349423285000,1],[1349423584000,1],[1349449329000,1],[1349449627000,1],[1349449926000,1],[1349450226000,1]] }, { "label": "Totaal Jobs SDM : 34", "data": [[1349449329000,34],[1349449627000,34],[1349449926000,34],[1349450226000,34]] }, { "label": "Totaal Jobs SIS : 1", "data": [[1349364129000,1],[1349364427000,1],[1349364727000,1],[1349365026000,1],[1349365327000,1],[1349365628000,1],[1349365927000,1],[1349366225000,1],[1349366532000,1],[1349366826000,1],[1349367126000,1],[1349367428000,1],[1349367728000,1],[1349368026000,1],[1349368324000,1],[1349368626000,1],[1349368926000,1],[1349369226000,1],[1349369527000,1],[1349369826000,1],[1349370126000,1],[1349370424000,1],[1349370726000,1],[1349371026000,1],[1349371325000,1],[1349371626000,1],[1349371926000,1],[1349372226000,1],[1349372526000,1],[1349372827000,1],[1349373127000,1],[1349373426000,1],[1349377412000,1],[1349377685000,1],[1349377984000,1],[1349378286000,1],[1349378588000,1],[1349378885000,1],[1349379187000,1],[1349379484000,1],[1349379785000,1],[1349380085000,1],[1349380391000,1],[1349380682000,1],[1349380989000,1],[1349381289000,1],[1349381583000,1],[1349381885000,1],[1349382186000,1],[1349382488000,1],[1349382782000,1],[1349383085000,1],[1349383382000,1],[1349383686000,1],[1349383986000,1],[1349384283000,1],[1349384589000,1],[1349384883000,1],[1349385186000,1],[1349385486000,1],[1349385789000,1],[1349386089000,1],[1349386389000,1],[1349386689000,1],[1349386989000,1],[1349387286000,1],[1349387589000,1],[1349387888000,1],[1349388189000,1],[1349388486000,1],[1349388789000,1],[1349389086000,1],[1349389385000,1],[1349389689000,1],[1349389989000,1],[1349390289000,1],[1349390589000,1],[1349390887000,1],[1349391189000,1],[1349391486000,1],[1349391789000,1],[1349392087000,1],[1349392386000,1],[1349392685000,1],[1349392990000,1],[1349393285000,1],[1349393589000,1],[1349393887000,1],[1349394184000,1],[1349394485000,1],[1349394789000,1],[1349395083000,1],[1349395384000,1],[1349395688000,1],[1349395985000,1],[1349396283000,1],[1349396590000,1],[1349396886000,1],[1349397187000,1],[1349397484000,1],[1349397784000,1],[1349398085000,1],[1349398390000,1],[1349398686000,1],[1349398984000,1],[1349399290000,1],[1349399589000,1],[1349399887000,1],[1349400186000,1],[1349400485000,1],[1349400787000,1],[1349401084000,1],[1349401385000,1],[1349401687000,1],[1349401990000,1],[1349402286000,1],[1349402589000,1],[1349402890000,1],[1349403189000,1],[1349403484000,1],[1349403784000,1],[1349404087000,1],[1349404384000,1],[1349404689000,1],[1349404990000,1],[1349405286000,1],[1349405586000,1],[1349405889000,1],[1349406189000,1],[1349406485000,1],[1349406786000,1],[1349407087000,1],[1349407389000,1],[1349407684000,1],[1349407987000,1],[1349408291000,1],[1349408589000,1],[1349408886000,1],[1349409185000,1],[1349409487000,1],[1349409786000,1],[1349410086000,1],[1349410389000,1],[1349410687000,1],[1349410984000,1],[1349411284000,1],[1349411590000,1],[1349411890000,1],[1349412189000,1],[1349412487000,1],[1349412785000,1],[1349413086000,1],[1349413387000,1],[1349413687000,1],[1349413989000,1],[1349414286000,1],[1349414590000,1],[1349414886000,1],[1349415186000,1],[1349415484000,1],[1349415784000,1],[1349416087000,1],[1349416389000,1],[1349416689000,1],[1349416986000,1],[1349417289000,1],[1349417584000,1],[1349417884000,1],[1349418186000,1],[1349418486000,1],[1349418785000,1],[1349419090000,1],[1349419389000,1],[1349419689000,1],[1349419989000,1],[1349420286000,1],[1349420586000,1],[1349420890000,1],[1349421186000,1],[1349421486000,1],[1349421784000,1],[1349422086000,1],[1349422384000,1],[1349422686000,1],[1349422989000,1],[1349423285000,1],[1349423584000,1],[1349424449000,1],[1349424726000,1],[1349425030000,1],[1349425330000,1],[1349425629000,1],[1349425926000,1],[1349426225000,1],[1349426526000,1],[1349426829000,1],[1349427124000,1],[1349427427000,1],[1349427727000,1],[1349428029000,1],[1349428327000,1],[1349428630000,1],[1349428930000,1],[1349428951000,1],[1349429526000,1],[1349429825000,1],[1349430123000,1],[1349430424000,1],[1349430725000,1],[1349431029000,1],[1349431329000,1],[1349431624000,1],[1349431927000,1],[1349432226000,1],[1349432525000,1],[1349432830000,1],[1349433125000,1],[1349433424000,1],[1349433726000,1],[1349434024000,1],[1349434324000,1],[1349434624000,1],[1349434924000,1],[1349435230000,1],[1349435526000,1],[1349435826000,1],[1349436127000,1],[1349436426000,1],[1349436727000,1],[1349437024000,1],[1349437326000,1],[1349437629000,1],[1349437929000,1],[1349438226000,1],[1349438527000,1],[1349438827000,1],[1349439127000,1],[1349439428000,1],[1349439728000,1],[1349440024000,1],[1349440324000,1],[1349440630000,1],[1349440927000,1],[1349441229000,1],[1349441524000,1],[1349441827000,1],[1349442127000,1],[1349442430000,1],[1349442726000,1],[1349443027000,1],[1349443326000,1],[1349443627000,1],[1349443925000,1],[1349444230000,1],[1349444527000,1],[1349444826000,1],[1349445126000,1],[1349445427000,1],[1349445726000,1],[1349446030000,1],[1349446324000,1],[1349446630000,1],[1349446927000,1],[1349447227000,1],[1349447527000,1],[1349447824000,1],[1349448126000,1],[1349448426000,1],[1349448727000,1],[1349449027000,1],[1349449329000,1],[1349449627000,1],[1349449926000,1],[1349450226000,1]] }, { "label": "Totaal Jobs SOS : 44", "data": [[1349364129000,45],[1349364427000,45],[1349364727000,45],[1349365026000,45],[1349365327000,45],[1349365628000,45],[1349365927000,45],[1349366225000,45],[1349366532000,45],[1349366826000,45],[1349367126000,45],[1349367428000,45],[1349367728000,45],[1349368026000,45],[1349368324000,45],[1349368626000,45],[1349368926000,45],[1349369226000,45],[1349369527000,45],[1349369826000,45],[1349370126000,45],[1349370424000,45],[1349370726000,45],[1349371026000,45],[1349371325000,45],[1349371626000,45],[1349371926000,45],[1349372226000,45],[1349372526000,45],[1349372827000,45],[1349373127000,45],[1349373426000,45],[1349377412000,45],[1349377685000,45],[1349377984000,45],[1349378286000,45],[1349378588000,45],[1349378885000,45],[1349379187000,45],[1349379484000,45],[1349379785000,45],[1349380085000,45],[1349380391000,45],[1349380682000,45],[1349380989000,45],[1349381289000,45],[1349381583000,45],[1349381885000,45],[1349382186000,45],[1349382488000,45],[1349382782000,45],[1349383085000,45],[1349383382000,45],[1349383686000,45],[1349383986000,45],[1349384283000,45],[1349384589000,45],[1349384883000,45],[1349385186000,45],[1349385486000,45],[1349385789000,45],[1349386089000,45],[1349386389000,45],[1349386689000,45],[1349386989000,45],[1349387286000,45],[1349387589000,45],[1349387888000,45],[1349388189000,45],[1349388486000,45],[1349388789000,45],[1349389086000,45],[1349389385000,45],[1349389689000,45],[1349389989000,45],[1349390289000,45],[1349390589000,45],[1349390887000,45],[1349391189000,45],[1349391486000,45],[1349391789000,45],[1349392087000,45],[1349392386000,45],[1349392685000,45],[1349392990000,45],[1349393285000,45],[1349393589000,45],[1349393887000,45],[1349394184000,45],[1349394485000,45],[1349394789000,45],[1349395083000,45],[1349395384000,45],[1349395688000,45],[1349395985000,45],[1349396283000,45],[1349396590000,45],[1349396886000,45],[1349397187000,45],[1349397484000,45],[1349397784000,45],[1349398085000,45],[1349398390000,45],[1349398686000,45],[1349398984000,45],[1349399290000,45],[1349399589000,45],[1349399887000,45],[1349400186000,45],[1349400485000,45],[1349400787000,45],[1349401084000,45],[1349401385000,45],[1349401687000,45],[1349401990000,45],[1349402286000,45],[1349402589000,45],[1349402890000,45],[1349403189000,45],[1349403484000,45],[1349403784000,45],[1349404087000,45],[1349404384000,45],[1349404689000,45],[1349404990000,45],[1349405286000,45],[1349405586000,45],[1349405889000,45],[1349406189000,45],[1349406485000,45],[1349406786000,45],[1349407087000,45],[1349407389000,45],[1349407684000,45],[1349407987000,45],[1349408291000,45],[1349408589000,45],[1349408886000,45],[1349409185000,45],[1349409487000,45],[1349409786000,45],[1349410086000,45],[1349410389000,45],[1349410687000,45],[1349410984000,45],[1349411284000,45],[1349411590000,45],[1349411890000,45],[1349412189000,45],[1349412487000,45],[1349412785000,45],[1349413086000,45],[1349413387000,45],[1349413687000,45],[1349413989000,45],[1349414286000,45],[1349414590000,45],[1349414886000,45],[1349415186000,45],[1349415484000,45],[1349415784000,45],[1349416087000,45],[1349416389000,45],[1349416689000,45],[1349416986000,45],[1349417289000,45],[1349417584000,45],[1349417884000,45],[1349418186000,45],[1349418486000,45],[1349418785000,45],[1349419090000,45],[1349419389000,45],[1349419689000,45],[1349419989000,45],[1349420286000,45],[1349420586000,45],[1349420890000,45],[1349421186000,45],[1349421486000,45],[1349421784000,45],[1349422086000,45],[1349422384000,45],[1349422686000,45],[1349422989000,45],[1349423285000,45],[1349423584000,45],[1349424449000,44],[1349424726000,44],[1349425030000,44],[1349425330000,44],[1349425629000,44],[1349425926000,44],[1349426225000,44],[1349426526000,44],[1349426829000,44],[1349427124000,44],[1349427427000,44],[1349427727000,44],[1349428029000,44],[1349428327000,44],[1349428630000,44],[1349428930000,44],[1349428951000,44],[1349429526000,44],[1349429825000,44],[1349430123000,44],[1349430424000,44],[1349430725000,44],[1349431029000,44],[1349431329000,44],[1349431624000,44],[1349431927000,44],[1349432226000,44],[1349432525000,44],[1349432830000,44],[1349433125000,44],[1349433424000,44],[1349433726000,44],[1349434024000,44],[1349434324000,44],[1349434624000,44],[1349434924000,44],[1349435230000,44],[1349435526000,44],[1349435826000,44],[1349436127000,44],[1349436426000,44],[1349436727000,44],[1349437024000,44],[1349437326000,44],[1349437629000,44],[1349437929000,44],[1349438226000,44],[1349438527000,44],[1349438827000,44],[1349439127000,44],[1349439428000,44],[1349439728000,44],[1349440024000,44],[1349440324000,44],[1349440630000,44],[1349440927000,44],[1349441229000,44],[1349441524000,44],[1349441827000,44],[1349442127000,44],[1349442430000,44],[1349442726000,44],[1349443027000,44],[1349443326000,44],[1349443627000,44],[1349443925000,44],[1349444230000,44],[1349444527000,44],[1349444826000,44],[1349445126000,44],[1349445427000,44],[1349445726000,44],[1349446030000,44],[1349446324000,44],[1349446630000,44],[1349446927000,44],[1349447227000,44],[1349447527000,44],[1349447824000,44],[1349448126000,44],[1349448426000,44],[1349448727000,44],[1349449027000,44],[1349449329000,44],[1349449627000,44],[1349449926000,44],[1349450226000,44]] }] 

1 个答案:

答案 0 :(得分:1)

您提供给Flot的数据格式不正确 改变“data = [series];”到“data = [];”

使用堆叠插件时,请确保基于时间的数据系列已对齐(所有系列的开始/结束日期相同)。如果不是,则可能不会显示所有数据点。

为了使代码更清晰,你也可以这样做:

    function updateData() {
        $.ajax({
            // usually, we'll just call the same URL, a script
            // connected to a database, but in this case we only
            // have static example files so we need to modify the
            // URL
            url: "blabla.txt",
            method: 'GET',
            dataType: 'json',
            success: onDataReceived

        });

        function onDataReceived(series) {
            plot.setData(series);
            plot.setupGrid();
            plot.draw();
        }           
    }

var plot = $.plot(controlm, [], options);

setInterval(updateData, 120000);
updateData();