通過php動(dòng)態(tài)傳數(shù)據(jù)到highcharts
1:在平時(shí)工作中,在對數(shù)據(jù)進(jìn)行展示的時(shí)候,是直接通過后臺(tái)提供的接口來獲取json串,用來展示。今天別人問怎么在本地演示一下請求的動(dòng)態(tài)數(shù)據(jù)。
2:在本地搭建環(huán)境,我用的WampServer,下載地址:http://xiazai.jb51.net/201703/yuanma/WampServer_2.5_jb51.rar,瀏覽器打開localhost,文件存放在wamp/www目錄下

3:php代碼,沒有寫與數(shù)據(jù)庫實(shí)時(shí)請求的過程。
<?php
$b = array(
array('name'=>'北京', 'y'=>20.2),
array('name'=>'上海', 'y'=>9.6),
array('name'=>'武漢', 'y'=>16.6),
);
$data = json_encode($b);
echo($data);
?>
4:html文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<link rel="icon" >
<style>
</style>
<script src="https://img.hcharts.cn/jquery/jquery-1.8.3.min.js"></script>
<script src="https://img.hcharts.cn/highcharts/highcharts.js"></script>
<script src="https://img.hcharts.cn/highcharts/modules/exporting.js"></script>
<script src="https://img.hcharts.cn/highcharts-plugins/highcharts-zh_CN.js"></script>
</head>
<body>
<div id="container" style="min-width:400px;height:400px"></div>
<script>
$(function () {
$.getJSON('http://localhost/index-1.php', function (csv) {
console.log(csv)
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: ''
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
}
}
},
series: [{
type: 'line',
name: '',
data: csv,
}]
});
});
});
</script>
</body>
</html>
5:在這里,引入js文件,當(dāng)需要對一個(gè)相同的json串展示為不同的圖形時(shí),修改series里的type屬性,同時(shí)修改highcharts里的數(shù)據(jù)列參數(shù)plotOptions,就可以展示不同的圖形了,highcharts可顯示圖形類型。

php返回?cái)?shù)據(jù)格式:[{"name":"\u5317\u4eac","y":20.2},{"name":"\u4e0a\u6d77","y":9.6},{"name":"\u6b66\u6c49","y":16.6}],當(dāng)需要對請求的數(shù)據(jù)進(jìn)行處理時(shí),比如只需要其中一部分的數(shù)據(jù)時(shí),可以在通過get請求數(shù)據(jù)時(shí),對傳過來的數(shù)組進(jìn)行處理:

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!
- 在vue項(xiàng)目中引入highcharts圖表的方法(詳解)
- Vue 中使用vue2-highcharts實(shí)現(xiàn)top功能的示例
- Vue 中使用vue2-highcharts實(shí)現(xiàn)曲線數(shù)據(jù)展示的方法
- 在Vue中使用highCharts繪制3d餅圖的方法
- highcharts 在angular中的使用示例代碼
- jQuery插件HighCharts繪制簡單2D柱狀圖效果示例【附demo源碼】
- jQuery插件HighCharts繪制簡單2D折線圖效果示例【附demo源碼】
- jQuery插件HighCharts繪制2D餅圖效果示例【附demo源碼下載】
- jQuery插件HighCharts實(shí)現(xiàn)氣泡圖效果示例【附demo源碼】
- highCharts提示框中顯示當(dāng)前時(shí)間的方法
相關(guān)文章
php中cURL?error?60:SSL?certificate?problem:?unable?to?
PHP中cURL錯(cuò)誤60通常表示SSL證書問題,即無法獲取本地頒發(fā)機(jī)構(gòu)證書,這通常是由于cURL無法驗(yàn)證遠(yuǎn)程服務(wù)器的SSL證書導(dǎo)致的,本給大家介紹了如何解決php中cURL?error?60,需要的朋友可以參考下2023-12-12
php進(jìn)行支付寶開發(fā)中return_url和notify_url的區(qū)別分析
這篇文章主要介紹了php進(jìn)行支付寶開發(fā)中return_url和notify_url的區(qū)別,較為詳細(xì)的分析了return_url和notify_url的區(qū)別與用法,需要的朋友可以參考下2014-12-12
php htmlentities和htmlspecialchars 的區(qū)別
很多人都以為htmlentities跟htmlspecialchars的功能是一樣的,都是格式化html代碼的,我以前也曾這么認(rèn)為,但是今天我發(fā)現(xiàn)并不是這樣的。2008-08-08
php圖像處理函數(shù)imagecopyresampled用法詳解
這篇文章主要介紹了php圖像處理函數(shù)imagecopyresampled用法,結(jié)合實(shí)例形式詳細(xì)分析了imagecopyresampled函數(shù)的功能、參數(shù)、使用方法,需要的朋友可以參考下2016-12-12
PHP 處理TXT文件(打開/關(guān)閉/檢查/讀取)
php寫入txt、php讀取txt,在PHP處理TXT文件時(shí)經(jīng)常會(huì)使用到,本文整理了一些相關(guān)代碼,感興趣的朋友可以參考下哈2013-05-05
php 下 html5 XHR2 + FormData + File API 上傳文件操作實(shí)例分析
這篇文章主要介紹了php 下 html5 XHR2 + FormData + File API 上傳文件操作,結(jié)合實(shí)例形式分析了php 下使用html5 XHR2 + FormData + File API 實(shí)現(xiàn)上傳文件操作方法與相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2020-02-02

