1

我有一个以 JSON 格式提供输出的 JSP 程序。我想highchart用那个输出更新车速表。我的仪表只从输出中获取一个值。它没有进一步更新。但我可以使用 alert 语句打印正确的值。任何人都可以帮助我吗?

这是我的代码:

$(function () {
var chart1=new Highcharts.Chart({
                chart:{
                    renderTo:'container',
                    type:'gauge',
                    alignTicks:false
                },
                title:{
                    text:'Speedometer'
                },
                pane:[{
                    startAngle:-150,
                    endAngle:150,
                    size:350,
                    background:{
                    outerRadius:'105%',
                    innerRadius:'72%',
                        backgroundColor:{
                            radialGradient:{
                                cx:0.5,
                                cy:0.6,
                                r:1.0
                            },
                            stops:[
                                [0.3,'#A7A9A4'],
                                [0.45,'#DDD'],
                                [0.7,'#EBEDEA']
                            ]
                        }
                    }
                },
               {
                    startAngle:-150,
                    endAngle:150,
                    size:210
                }],
                yAxis:[{
                    min:0,
                    max:100,
                    minorTickInterval:'auto',
                    tickPixelInterval:70,
                    plotBands:[{
                        from:0,
                        to:50,
                        color:'green'
                    },{
                        from:50,
                        to:80,
                        color:'yellow'
                    },{
                        from:80,
                        to:100,
                        color:'red'
                    }],
                   pane:0
                },{
                    min:0,
                    max:220 ,
                    tickPosition:'inside',
                    minorTickPosition:'inside',
                    minorTickInterval:'auto',
                    tickPixelInterval:60,
                    plotBands:[{
                        from:0,
                        to:70,
                        color:'red'
                    },{
                        from:70,
                        to:130,
                        color:'yellow'
                    },{
                        from:130,
                        to:220,
                        color:'green'
                    }],
                    pane:1
                }],
                series:[{
                    data:[70],
                    name:'Speed',
                    tooltip:{
                        valueSuffix:' km/h'
                    },
                    dataLabels:{
                        formatter:function(){
                              if(this.point.realVal)
                                return this.y;    
                              }
                },
                    yAxis:0
                },{
                    data:[100],
                    name:'RPM',
                    dataLabels:{
                        formatter:function(){
                                if(this.point.realVal1)
                                return this.y;                                    
                        }
                    },
                          yAxis:1
                }]
},
    function (chart) {
           setInterval(function () {
                                     var point = chart.series[0].points[0],
                                     point1=chart.series[1].points[0],
                                     newVal=[],newVal1=[],i,j;
                                 $.get('Db.jsp', null, function (tsv,state,xhr) {
                var data = eval ( '(' + xhr.responseText + ')' );
                                    for(i=0; i<data.points.length; i++){    
                                                                               $.each(data.points[i],function(key,val){
                                                    newVal.push(val);
                                    //alert(newVal);
                                    point.update(newVal);
                }
      }
     for(j=0; j<data.points.length; j++){   
                         $.each(data.values[j], function(key,val){
                                                       newVal1.push(val);
                                   //alert(newVal1);
                                   point1.update(newVal);
                                    }
                }
     });
  });
});
});                                          
4

0 回答 0