我正在尝试使用highcharts从php json中提取数据。
php工作正常,但我不知道如何使json成为输入。
特别是试图将数据放在单个Gauge Chart上,就像示例中的那个,但是我无法配置脚本来读取json。
URL si:php / KPItonsStock.php
<?php function getArraySQL(){ $startd = "29964"; $endd = "29968"; $dsn = "prueba"; $connect = odbc_connect( $dsn, '', '' ); $query = " Select SUM(TON_DESCARGADO) AS data from (Select unit,[load],enum_LOAD.[name],SUM(dumptons) as TON_DESCARGADO from hist_dumps inner join hist_loclist on hist_dumps.shiftindex = hist_loclist.shiftindex and hist_dumps.loc = hist_loclist.locid inner join enum_LOAD on hist_dumps.[load] = enum_LOAD.[num] where hist_dumps.shiftindex between '$startd' and '$endd' GROUP BY loc,UNIT,unit#,[load],enum_LOAD.[name])TEMP1 where unit = 'Stockpile' GROUP BY unit order BY UNIT"; if(!$rs = odbc_exec($connect, $query)) die(); $rawdata = array(); $i=0; while($row = odbc_fetch_array($rs)) { $rawdata[$i] = $row; $i++; } odbc_close( $connect ); return $rawdata; }; $data = getArraySQL(); echo json_encode(($data), JSON_NUMERIC_CHECK);
结果如下:
[{"data":29655.88482666}]
所以我需要将该URL的信息放到仪表图表中。
我尝试使用getjson,但我遗漏了一些东西,因为图表加载但不是数据。
这是ototinal highchart的例子
https://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/gauge-solid/
这是我的数据的示例
Highcharts Example ${demo.css} function visitorData (data) { $('#container').highcharts({ chart: { type: 'solidgauge' }, title: { text: 'Average Visitors' }, pane: { center: ['50%', '85%'], size: '140%', startAngle: -90, endAngle: 90, background: { backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || '#EEE', innerRadius: '60%', outerRadius: '100%', shape: 'arc' } }, yAxis: { min: 0, max: 40000, title: { text: 'Speed'}, stops: [ [0.1, '#55BF3B'], // green [0.5, '#DDDF0D'], // yellow [0.9, '#DF5353'] // red ], lineWidth: 0, minorTickInterval: null, tickPixelInterval: 400, tickWidth: 0, title: { y: -70 }, labels: { y: 16 } }, series: data, }); } $(document).ready(function() { $.ajax({ url: 'report2/KPItonsStock.php', type: 'GET', async: true, dataType: "json", success: function (data) { visitorData(data); } }); });
我得到了图形,但它没有加载任何数据
数据需要是一个数组。 让你的后端返回
[{ "data": [29655.88482666] }]
以上就是jQuery教程分享highchart加载图表但不加载JSON数据相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/jquerytutorial/524528.html