duanduoding2238 2013-12-14 12:02
浏览 55
已采纳

Highcharts查询

I want to use the highcharts library but it doesn't work. I've checked it in JSFiddle it is working fine but it is not working in my browser.

What is the problem? please tell me.

Here is the code:

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/highcharts-more.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript">
$(function () {

$('#container').highcharts({

    chart: {
        type: 'gauge',
        plotBackgroundColor: null,
        plotBackgroundImage: null,
        plotBorderWidth: 0,
        plotShadow: false
    },

    title: {
        text: 'Speedometer'
    },

    pane: {
        startAngle: -90,
        endAngle: 90,
        center: ['50%', '100%'],
        background: [{
            backgroundColor: {
                linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
                stops: [
                    [0, '#FFF'],
                    [1, '#333']
                ]
            },
            borderWidth: 0,
            outerRadius: '109%'
            }, {
            backgroundColor: {
                linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
                stops: [
                    [0, '#333'],
                    [1, '#FFF']
                ]
            },
            borderWidth: 1,
            outerRadius: '107%'
        }, {
            // default background
        }, {
            backgroundColor: '#DDD',
            borderWidth: 0,
            outerRadius: '105%',
            innerRadius: '103%'
        }]
    },

    // the value axis
    yAxis: {
        min: 0,
        max: 200,

        minorTickInterval: 'auto',
        minorTickWidth: 1,
        minorTickLength: 10,
        minorTickPosition: 'inside',
        minorTickColor: '#666',

        tickPixelInterval: 30,
        tickWidth: 2,
        tickPosition: 'inside',
        tickLength: 10,
        tickColor: '#666',
        labels: {
            step: 2,
            rotation: 'auto'
        },
        title: {
            text: 'km/h'
        },
        plotBands: [{
            from: 0,
            to: 120,
            color: '#55BF3B' // green
        }, {
            from: 120,
            to: 160,
            color: '#DDDF0D' // yellow
        }, {
            from: 160,
            to: 200,
            color: '#DF5353' // red
        }]        
    },

    series: [{
        name: 'Speed',
        data: [80],
        tooltip: {
            valueSuffix: ' km/h'
        }
    }]

}, 
// Add some life
function (chart) {
    if (!chart.renderer.forExport) {
        setInterval(function () {
            var point = chart.series[0].points[0],
                newVal,
                inc = Math.round((Math.random() - 0.5) * 20);

            newVal = point.y + inc;
            if (newVal < 0 || newVal > 200) {
                newVal = point.y - inc;
            }

            point.update(newVal);

        }, 3000);
    }
});
    });
    </script>
    </head>

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

I also want to get the data from MYSQL database using AJAX which shows the current speed. I have written the query but I don't know how to use in this code.

Please tell me the method, I am new so I don't know how to use Highcharts

Here is my PHP code:

 $data = mysql_query("SELECT speed FROM gps WHERE DeviceId=25 ORDER BY TIME DESC LIMIT 1")
or die(mysql_error()); 
$table = array();
$table['cols'] = array(
array('label' => 'Speed', 'type' => 'number')
);
$rows = array();
while ($nt = mysql_fetch_array($data))
{               
$temp = array();

$temp[] = array('v' => $nt['speed']);

$rows[]['c'] = $temp;

}
$table['rows'] = $rows;
$jsonTable = json_encode($table); 

please tell me how can I use this in above HighChart

  • 写回答

2条回答 默认 最新

  • doune1000 2013-12-14 12:20
    关注

    Most likely you failed to load jQuery on which your code depends on. Adding this code before loading highcharts should do the trick.

    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    

    Also you can't purely use JavaScript to fetch data from a database. You will have to use a server scripting language such as PHP, Ruby, Python, ASP.Net e.t.c. JavaScript is client side only.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。