highcharts php请求mysql返回json数据作为数据源进行制图
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了highcharts php请求mysql返回json数据作为数据源进行制图,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2776字,纯文字阅读大概需要4分钟。
内容图文
直接上代码
【官方文档请参见http://www.highcharts.com/docs/working-with-data/getting-data-across-domains-jsonp】
【实例http://highcharts-mzm.rhcloud.com/】
1、index.html
<! DOCTYPE HTML > < html > < head > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" > < title >Highcharts Example</title><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script><style type="text/css"> ${demo.css}</style><script type="text/javascript"> $(document).ready(function() { var options = { chart: { renderTo: ‘container‘, type: ‘column‘ }, title: { text: ‘Highcharts Chart PHP with MySQL Example‘, x: -20//center }, subtitle: { text: ‘Source: dongqiudi.com‘, x: -20 }, xAxis: { categories: [], title: { text: ‘team‘ } }, yAxis: { title: { text: ‘score‘ }, plotLines: [{ value: 0, width: 1, color: ‘#808080‘ }] }, tooltip: { valueSuffix: ‘个‘ }, legend: { layout: ‘vertical‘, align: ‘right‘, verticalAlign: ‘middle‘, borderWidth: 0 }, series: [] }; var url ="http://yourip/getHighchartData.php?callback=?"; $.getJSON(url, function(data) { options.xAxis.categories = data[0][‘data‘]; //xAxis: {categories: []} options.series[0] = data[1]; options.series[1] = data[2]; var chart =new Highcharts.Chart(options); }); }); </script></head><body><script src="../../js/highcharts.js"></script><script src="../../js/modules/exporting.js"></script><div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div></body></html>
2、getHighchartData.php
<?php /* * Following code will list all the products */// array for JSON response$response = array(); // include db connect classrequire_once __DIR__ . ‘/db_connect.php‘; // connecting to db$db = new DB_CONNECT(); // 查询主场进球及主场失球数据$result = mysql_query("SELECT home_team, sum(score_home) as score_h, sum(score_visiting) as score_v FROM fbscore group by home_team") or die(mysql_error()); $bln = array(); $bln[‘name‘] = ‘team name‘; $rows[‘name‘] = ‘home score‘; $rows2[‘name‘] = ‘visiting score‘; // check for empty resultif (mysql_num_rows($result) > 0) { while ($r = mysql_fetch_array($result)) { // temp user array //$array = $row["score_home"];array_push($array, $row[score_home]); $bln[‘data‘][] = $r[‘home_team‘]; $rows[‘data‘][] = $r[‘score_h‘]; $rows2[‘data‘][] = $r[‘score_v‘]; } $rslt = array(); array_push($rslt, $bln); array_push($rslt, $rows); array_push($rslt, $rows2); // echoing JSON responseecho$_GET[‘callback‘]. ‘(‘. json_encode($rslt, JSON_NUMERIC_CHECK) . ‘)‘; //print json_encode($rslt, JSON_NUMERIC_CHECK); } else { echo "error!"; }
3、效果图
原文:http://www.cnblogs.com/marost/p/6235365.html
内容总结
以上是互联网集市为您收集整理的highcharts php请求mysql返回json数据作为数据源进行制图全部内容,希望文章能够帮你解决highcharts php请求mysql返回json数据作为数据源进行制图所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。