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 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?