1

工作聊天示例: http ://www.highcharts.com/demo/dynamic-update/gray

我试图让上述工作,除了上面的图表填充了随机数据的修改;我希望使用$.getJSON命令从非域数据库中提取数据并将其插入聊天。

到目前为止,我能够加载初始数据,以便它可以创建一个静态图表。为了使其静态,我不得不注释掉setInterval().

当我包含一些静态数据时,我在 Google Chrome ( ++ )setInterval()中的 JavaScript 控制台上收到错误消息。CtrlShiftJ

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Highcharts Example</title>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script type="text/javascript" src="date.js"></script>
        <script type="text/javascript">

        

        
        
$(function () {
    $(document).ready(function() {
        Highcharts.setOptions({
            global: {
                useUTC: false
            }
        });
    
    
                    
                    var jsonUrl = "http://www.somewebsite.co.uk/jsonusv.php?callback=?";                    
                    $.getJSON(jsonUrl,{lastdatetime: "",},function(zippy){                  
                        for (i=0; i<zippy.cpmdata.length; i++){
                                console.log("TIMESTAMP: "+zippy.cpmdata[i].timestamp+" AFTER: ");
                                zippy.cpmdata[i].timestamp =  Date.parse(zippy.cpmdata[i].timestamp).getTime(); 
                                
                                //var unixtime  Date.parse(temptime).getTime()/1000
                                console.log(" TESST "+zippy.cpmdata[i].timestamp+" \r\n");                              
                                console.log(" TESST zippy "+zippy.cpmdata[i].timestamp+" \r\n");
                                
                                
                                
                                
                                
                                
                                
        var chart;
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'spline',
                marginRight: 10,
                events: {
                    load: function() {
    
                        // set up the updating of the chart each second
                        
                        var series = this.series[0];
                        var tttt = "2012-11-13 17:17:00";
                        setInterval(function() { var x = Date.parse(tttt).getTime(),y = 8;
                        series.addPoint([x, y], true, true);
                        }, 5000);
                    }
                }
            },
            title: {
                text: 'Online Counter'
            },
            xAxis: {
                type: 'datetime',
                tickPixelInterval: 150
            },
            yAxis: {
                title: {
                    text: 'units/h'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            tooltip: {
                formatter: function() {
                        return '<b>'+ this.series.name +'</b><br/>'+
                        Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
                        Highcharts.numberFormat(this.y, 2)+" uSv/h";
                }
            },
            legend: {
                enabled: false
            },
            exporting: {
                enabled: false
            },
            series: [{
                name: 'units/h ',
                data: (function() {
                    // generate an array of random data
                    var data = [],
                        time = (new Date()).getTime(),
                        i;
                    
                    
                    console.log(" =============== \r\n");
                    console.log(" FINAL "+zippy.cpmdata[5].timestamp+" \r\n");
                    
                    for (i=0; i<zippy.cpmdata.length; i++){
                            data.push({
                            x: zippy.cpmdata[i].timestamp,
                            y: parseInt(zippy.cpmdata[i].cpm,10)
                            });
                        }
                    
                    return data;
                })()
            }]
        });                             
                                
    
                            }  });
                    console.log("==END==");                     
    });
    
});

        </script>
        


    </head>
    <body>
<script src="./js/highcharts.js"></script>
<script src="./js/modules/exporting.js"></script>
<script src="gray.js"></script> 

<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>

    </body>
</html>

我不断收到错误:

未捕获的错误:NOT_FOUND_ERR:DOM 异常 8 highcharts.js:167

我不知道为什么?

第二个问题是由于异步性质,$.getJSON我可以使用与原始方法相同的方法获取数据,$.getJSON但在调用中调用它以setInterval()动态更新数据。

4

0 回答 0