sunjavagroups / flot

Automatically exported from code.google.com/p/flot
MIT License
0 stars 0 forks source link

var axes = plot.getAxes();var dataset = plot.getData(); can not work in xaxis-time format #560

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
<script type="text/javascript">
$(function(){

    function update(){
    $.ajax({
    type: "POST",
    url: "get-today-infor.php",
    success: function(msg){

    var options = {
        xaxis: { mode: "time",timeformat: "%H:%M" , tickLength: 5 },
        series: {  lines: { show: true } },
        crosshair: { mode: "x" },
        grid: { hoverable: true, autoHighlight: false },
        selection: { mode: "x" }
    };

    var updateLegendTimeout = null;
    var latestPosition = null;

    var plot_big = $.plot($("#today-p"), [{data:msg , label: "总功率= 0.00"}], options);
    plot_big.draw();    

    var plot_small = $.plot($("#for_tip"), [msg], {
        series: {
            lines: { show: true, lineWidth: 1 },
            shadowSize: 0
        },
        xaxis: { ticks: [], mode: "time",timeformat: "%H:%M" },
        yaxis: { ticks: [], min: 0, autoscaleMargin: 0.1 },
        selection: { mode: "x" }
    });
    plot_small.draw();

function updateLegend() {
        updateLegendTimeout = null;

        var pos = latestPosition;

        var axes = plot.getAxes();
        alert("nb"+axes.xaxis.max);
        if (pos.x < axes.xaxis.min || pos.x > axes.xaxis.max ||
            pos.y < axes.yaxis.min || pos.y > axes.yaxis.max)
            return;

        var i, j, dataset = plot.getData();

        for (i = 0; i < dataset.length; ++i) {
            var series = dataset[i];
            // find the nearest points, x-wise
            for (j = 0; j < series.data.length; ++j)
                if (series.data[j][0] > pos.x)
                    break;

            // now interpolate
            var y, p1 = series.data[j - 1], p2 = series.data[j];
            if (p1 == null)
                y = p2[1];
            else if (p2 == null)
                y = p1[1];
            else
                y = p1[1] + (p2[1] - p1[1]) * (pos.x - p1[0]) / (p2[0] - p1[0]);

            legends.eq(i).text(series.label.replace(/=.*/, "= " + y.toFixed(2)));
        }
    }   

  $("#today-p").bind("plotselected", function (event, ranges) {
        // do the zooming
        plot_big = $.plot($("#today-p"), [{data:msg , label: "总功率= 0.00"}],
                      $.extend(true, {}, options, {
                          xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to }
                      }));
        // don't fire event on the overview to prevent eternal loop
        for_tip.setSelection(ranges, true);
    });

  $("#today-p").bind("plothover",  function (event, pos, item) {
        latestPosition = pos;
        if (!updateLegendTimeout)
            updateLegendTimeout = setTimeout(updateLegend, 50);
    });

    $("#for_tip").bind("plotselected", function (event, ranges) {
        plot_big.setSelection(ranges);
    });

   },
   error: function(){
    new Dialog('wait for a moment thanks...',{time:5000},{id:'dialog'}).show();
    window.location.reload();
   },
   dataType: 'json'
 });
 setTimeout(update, 1000000);   
 }
 update();
}); 
</script>

Original issue reported on code.google.com by xmphoe...@gmail.com on 24 Jun 2011 at 5:37

GoogleCodeExporter commented 8 years ago
Issue 561 has been merged into this issue.

Original comment by olau%iol...@gtempaccount.com on 24 Jun 2011 at 9:09

GoogleCodeExporter commented 8 years ago
Hi!

I'm sorry but you need to explain what the problem is, why you think it's a 
problem in Flot and not in your code (if you suspect your code is the problem, 
please do not add issues here, use the Google Group where the chance of getting 
help is much higher), and lastly, condense the testcase to something as small 
as possible and self-contained. The above is neither as small as possible or 
self-contained, you failed to provide the data set.

Original comment by olau%iol...@gtempaccount.com on 24 Jun 2011 at 9:13

GoogleCodeExporter commented 8 years ago
yes you are right !
I make a mistake in my code !  
change this is code:
var axes = plot.getAxes();dataset = plot.getData();
for :
var axes = plot_big.getAxes();dataset = plot_big.getData();
that is ok !

Original comment by xmphoe...@gmail.com on 26 Jun 2011 at 1:51

GoogleCodeExporter commented 8 years ago
yes you are right !
I make a mistake in my code !  
change this is code:
var axes = plot.getAxes();dataset = plot.getData();
for :
var axes = plot_big.getAxes();dataset = plot_big.getData();
that is ok !

Original comment by xmphoe...@gmail.com on 26 Jun 2011 at 1:51

GoogleCodeExporter commented 8 years ago

Original comment by olau%iol...@gtempaccount.com on 27 Jun 2011 at 10:44

GoogleCodeExporter commented 8 years ago

Original comment by dnsch...@gmail.com on 4 Jun 2012 at 2:52