0

我有一个使用 Envision.js 库的假装销售图表。只要 Firebug 正在运行,它就可以很好地工作。它会绘制一个介于 20-25 之间的数字,当我关闭 Web 服务器时,它会在 0 处平展。但如果我关闭 firebug,则刷新;它所做的只是在零处变平​​。这与我的 ajax 函数的位置有关:myFunction(),但我不知道是什么。有人可以给我一个眼球吗?我只是什么都没看到。我确实知道这不是 Ajax 函数本身,因为我在另一个页面上使用完全相同的两个函数并且它们运行良好。我正在从服务器返回(4 和 200),所以我不知道......在此先感谢。

//Global Variables//////////



var counter = 0;
var myArray = [25, 24, 23, 22, 21, 20];
var resultToGraph;
var url = "http://myserver.com/ajax_info.txt";
var xmlhttp;
function loadXMLDoc(url, cfunc)
{
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=cfunc;
    xmlhttp.open("GET",url, true);
    xmlhttp.send();
}

function myFunction(){
    loadXMLDoc(url+'?_dc='+(new Date()).getTime(), function(){
    if(xmlhttp.readyState==4 && xmlhttp.status==200){
             resultToGraph  = myArray[Math.floor((Math.random()*5))];
    }
        else{
            resultToGraph = 0;
        }
    });
}

(function realtime_demo (container) {

  var
    x = [],
    dataA = [],
    data = [[x, dataA]],
    options, i, timesries;

  // Mock Data:
    function sample(i) {    
    x.push(i);
    dataA.push(i);  
    }

  // Initial Data:
    for (i = 0; i < 100; i++) {
    sample(i);
    }

  // Envision Timeseries Options
    options = {
    container : container,
    data : {
        detail : data,
        summary : data
    },
    defaults : {
        summary : {
        config : {
            colors : [ 'red'], //added to code...nothing there initiall**
            handles : { show : true } //changed from false **   
        }
        }
    }
    }

  // Render the timeseries
    timeseries = new envision.templates.TimeSeries(options);

  // Method to get new data
  // This could be part of an Ajax callback, a websocket callback,
  // or streaming / long-polling data source.
    function getNewData () {
    i++;

    // Short circuit (no need to keep going!  you get the idea)
    if (i > 5000) return;
    sample(i);
    animate(i);
    }

  // Initial request for new data
    getNewData();

  // Animate the new data
    function animate (i) {

      var
    start = (new Date()).getTime(),
    length = 500, // 500ms animation length
    max = i - 1,  // One new point comes in at a time
    min = i - 31, // Show 50 in the top
    offset = 0;   // Animation frame offset

    // Render animation frame
    (function frame () {

         var
            time = (new Date()).getTime(),
            tick = Math.min(time - start, length),
        offset = 0;
            //offset = (Math.sin(Math.PI * (tick) / length - Math.PI / 2) + 1) / 2;

      // Draw the summary first
        timeseries.summary.draw(null, {
        xaxis : {
            min : 0,
            max : max + offset
        }
        });

      // Trigger the select interaction.
      // Update the select region and draw the detail graph.
        timeseries.summary.trigger('select', {
        data : {
            x : {
            min : min + offset,
            max : max + offset
            }
        }
        });

        if (tick < length) {
        setTimeout(frame, 0);
        } else {
        // Pretend new data comes in every second
        setTimeout(getNewData, 0);
        }
    })();
    }
}
)(document.getElementById("container"));
4

0 回答 0