在同一页上显示两个图形

Display two graphs on a same page

我想在不同的同一页上绘制两个图表 days.But 当第 3 天到来时它应该显示最后两天的图表(意味着第一天的图表不会显示,只有第 2 天和第 3 天) 就像队列 process.I 无法弄清楚我如何移动图形日-wise.I 与 oracle 10g 有数据库连接。

更新数据库后应该如下所示 -

这是我的代码=>

test.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Real Time Graph</title>
<?php
include("mydb.php");
// run query

$sql1 = "select to_char(WORKDATE,'dd-Mon-yyyy HH24:MI:SS') as WD,DATA from dat where to_char(WORKDATE,'dd/mm')='25/02'";
$stid1=oci_parse($conn, $sql1);
// set array
$arr1 = array();

if(!$stid1){
$e=oci_error($conn);
trigger_error(htmlentities($e[message],ENT_QUOTES),E_USER_ERROR);
}

$r1=oci_execute($stid1);

if(!$r1){
$e=oci_error($stid1);
trigger_error(htmlentities($e[message],ENT_QUOTES),E_USER_ERROR);
}

// look through query
while($row = oci_fetch_array($stid1,OCI_ASSOC)){

  // add each row returned into an array
  $arr1[] = array((strtotime($row['WD'])*1000) , (float)$row['DATA']);

}

//oci_free_statement($stid);
//oci_close($conn);
?>

<?php
include("mydb.php");
// run query

$sql2 = "select to_char(WORKDATE,'dd-Mon-yyyy HH24:MI:SS') as WD,DATA from dat where to_char(WORKDATE,'dd/mm')='26/02'";
$stid2=oci_parse($conn, $sql2);
// set array
$arr2 = array();
if(!$stid1){
$e=oci_error($conn);
trigger_error(htmlentities($e[message],ENT_QUOTES),E_USER_ERROR);
}

$r2=oci_execute($stid2);

if(!$r2){
$e=oci_error($stid2);
trigger_error(htmlentities($e[message],ENT_QUOTES),E_USER_ERROR);
}

// look through query
while($row = oci_fetch_array($stid2,OCI_ASSOC)){

  // add each row returned into an array
  $arr2[] = array((strtotime($row['WD'])*1000) , (float)$row['DATA']);

}

//oci_free_statement($stid);
//oci_close($conn);
?>


<?php
include("mydb.php");
// run query

$sql3 = "select to_char(WORKDATE,'dd-Mon-yyyy HH24:MI:SS') as WD,DATA from dat where to_char(WORKDATE,'dd/mm')='27/02'";
$stid3=oci_parse($conn, $sql3);
// set array
$arr3 = array();
if(!$stid3){
$e=oci_error($conn);
trigger_error(htmlentities($e[message],ENT_QUOTES),E_USER_ERROR);
}

$r3=oci_execute($stid3);

if(!$r3){
$e=oci_error($stid3);
trigger_error(htmlentities($e[message],ENT_QUOTES),E_USER_ERROR);
}

// look through query
while($row = oci_fetch_array($stid3,OCI_ASSOC)){

  // add each row returned into an array
 // $arr=array_slice($arr,1,50);
  $arr3[] = array((strtotime($row['WD'])*1000) , (float)$row['DATA']);

}

//oci_free_statement($stid);
//oci_close($conn);
?>



<script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="jquery.flot.js"></script>

<script type="text/javascript">

//$(document).ready(function(){
var updateinterval=5000;
var data1=[];
var data2=[];
var data3=[];
var data4=[];

function getdata(){
//data.shift();
data1=<?php echo json_encode($arr1); ?>;
data2=<?php echo json_encode($arr2); ?>;
data3=<?php echo json_encode($arr3); ?>;
data4=<?php echo json_encode($arr4); ?>;

}
var options={
                
                series: {
                        lines: {
                                show: true,
                                lineWidth: 3,
                                fill: true,
                                radius: 5
                                },
                        points:{
                                show: "triangle"
                                }
                        },
                xaxis: {
                            mode: "time",
                            TickSize: [20, "seconds"],
                            tickFormatter:function (v, axis) {
                                                var date = new Date(v);
                                                if (date.getSeconds() % 20 == 0) {
                                                                                    var dates=date.getDate() <4 ? "0" +date.getDate() : date.getDate();
                                                                                    var months=date.getMonth()< 10 ? "0" +(date.getMonth()+1) :date.getMonth();
                                                                                    var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
                                                                                    var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
                                                                                    var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
                                                                                    return dates+ "/"+ months +" "+hours + ":" + minutes + ":" + seconds;
                                                                                    } 
                                                            else {
                                                                    return "";
                                                                }
                                                            },
                        
                            axisLabel: "Time",
                            axisLabelUseCanvas: true,
                            axisLabelFontSizePixels: 12,
                            axisLabelFontFamily: 'Verdana, Arial',
                            axisLabelPadding: 10
                        },
                    yaxis: {
                            
                            axisLabel: "Data loading",
                            axisLabelUseCanvas: true,
                            axisLabelFontSizePixels: 12,
                            axisLabelFontFamily: 'Verdana, Arial',
                            axisLabelPadding: 6
                        },
               legend: {        
                            labelBoxBorderColor: "#B0D5FF"
                        },
                    grid: {
                            hoverable: true, 
                            clickable: true,
                            backgroundColor: { 
                                                colors: ["#B0D5FF", "#5CA8FF"] 
                                            }
                            }
};
   $(document).ready(function () {
            getdata();
            var dataset1=[
              { 
                label: "Day1", 
                data: data1, 
                points: { 
                            symbol: "triangle"
                        } 

             }

            ];
            var dataset2=[
            {
                label: "Day2",
                data: data2,
                points: {
                            symbol: "cross"
                        }
             }
            ];
            var dataset3=[
            {
                label: "Day3",
                data: data3,
                points: {
                            symbol: "square"
                        }
             }
            ];
            var dataset4=[
            {
                label: "Day4",
                data: data4,
                points: {
                            symbol: "diamond"
                        }
             }
            ];

        $.plot($("#flot-container"), [dataset1], options);
        $.plot($("#flot-container1"), [dataset2], options);
        $.plot($("#flot-container2"), [dataset3], options); 
        $.plot($("#flot-container3"), [dataset4], options);
        $.plot($("#flot-container4"), [dataset5], options); 


function update() {
                $.plot($("#flot-container"), dataset1, options);
$.plot($("#flot-container1"), dataset2, options);
$.plot($("#flot-container2"), dataset3, options);
$.plot($("#flot-container3"), dataset4, options);
$.plot($("#flot-container4"), dataset5, options);
    //              setTimeout(update, updateinterval);
                setInterval(update, updateinterval);
                }
 
    update();

});


</script>

</head>

<body>
    <center>
    <h3><b><u>Real-Time Chart</u></b></h3>

    <h2>DAY 1</h2>
<div id="flot-container" aligh="right-side" style="width:840px;height:280px;"></div>

<h2>DAY 2 </h2>
<div id="flot-container1" style="width:840px;height:280px;"></div>
<h2>DAY 3 </h2>
<div id="flot-container2" style="width:990px;height:280px;"></div>
</center>
    <div id="footer">
        Copyright &copy; 2007 - 2014 
    </div>
</body>
</html>

请帮忙。

对于每个新的一天,您都可以隐藏或删除顶部的 container-div 并在底部插入一个新的 container-div。然后你只需要绘制一张新图表。

这是一个工作演示 (fiddle):

$(function() {

  function getNewData() {
    var temp = [];
    for (var i = 0; i <= 10; i++) {
      temp.push([i, Math.random()]);
    }
    return temp;
  }

  $.plot("div.placeholder:first", [getNewData()]);
  $.plot("div.placeholder:last", [getNewData()]);

  function newChart() {
    $('div.placeholder:visible:first').hide();
    $('div.placeholder:last').after($('<div>').addClass('placeholder'));
    $.plot("div.placeholder:last", [getNewData()]);
  }

  $('#btn').on('click', newChart);
});