highcharts PHP中使用
官网
https://www.hcharts.cn/demo/highcharts
html
<div id="container" style="min-width:400px;height:400px"></div>
js
Highcharts.chart('container', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: '2018年1月浏览器市场份额'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: [{
name: 'Chrome',
y: 61.41,
sliced: true,
selected: true
}, {
name: 'Internet Explorer',
y: 11.84
}, {
name: 'Firefox',
y: 10.85
}, {
name: 'Edge',
y: 4.67
}, {
name: 'Safari',
y: 4.18
}, {
name: 'Sogou Explorer',
y: 1.64
}, {
name: 'Opera',
y: 1.6
}, {
name: 'QQ',
y: 1.2
}, {
name: 'Other',
y: 2.61
}]
}]
});
这里的数据通常都是从数据库查询处理出来的。
而它的格式是json的格式。
所以通过ajax获取比较方便一些。
public function get_series_data() {
if ($date = $_POST['date']) {
$sql = 'select count(*) as count ,appid from tf_bag_lucky_log where is_receive=1 and add_time > '.strtotime($date." 00:00").' and add_time < '.strtotime($date ." 23:59").' group by appid order by count desc';
} else {
$sql = 'select count(*) as count ,appid from tf_bag_lucky_log where is_receive=1 group by appid order by count desc';
}
// 统计
$data_list = Db::query($sql);
$series_data = [];
foreach ($data_list as $k=>&$v) {
$xcx_info = Db::name('xcx')->where('appid',$v['appid'])->find();
if ($k == 0) {
$series_data[$k] = [
'name' => $xcx_info['name'],
'y' => $v['count'],
'sliced' => true,
'selected' => true,
];
} else {
$series_data[$k] = [
'name' => $xcx_info['name'],
'y' => $v['count'],
];
}
}
$this->json->setErr(0, '操作成功');
$this->json->setAttr('data', $series_data);
$this->json->Send();
}
js改造
showContainer(date);
function showContainer(date) {
$.ajax({
url: "get_series_data",
data: {
"date" : date,
},
type: "POST",
dataType: "json",
success: function (data) {
Highcharts.chart('container', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: '金猪中奖来自小程序'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
series: [{
name: '占比',
colorByPoint: true,
data: data.data,
// data: [{
// name: 'Chrome',
// y: 1000,
// sliced: true,
// selected: true
// }, {
// name: 'Internet Explorer',
// y: 11.84
// }, {
// name: 'Firefox',
// y: 10.85
// }, {
// name: 'Edge',
// y: 4.67
// }, {
// name: 'Safari',
// y: 4.18
// }, {
// name: 'Other',
// y: 7.05
// }]
}],
});
},
error: function () {
alert("网络错误");
}
});

highcharts 非常灵活,非常方便。ajax,json获取数据,效果刚刚的。
highcharts PHP中使用的更多相关文章
- 如何在 Highcharts 图中当所占百分比为 0 时不显示0%
解决办法其实很简单,将enabled属性改为false即可: dataLabels: { enabled: false } 完成之后的显示如下
- Highcharts 总结
一.Highcharts series属性 1.下面是一个基本曲线图的例子: <html> <head> <meta charset="UTF-8" ...
- highchart 中数据千分位显示为空格而不是逗号的解决方案
thousandsSep: String 一千的分隔符 在highcharts.js 中找到 thousandsSep位置,把"" 改为 ","
- highcharts 时间少8小时问题
Highcharts 中默认开启了UTC(世界标准时间),由于中国所在时区为+8,所以经过 Highcharts 的处理后会减去8个小时. 如果不想使用 UTC,有2种方法可供使用: 1.在使用Hig ...
- 【HighCharts系列教程】三、图表属性——chart
一.chart属性说明 Chart是HighCharts图表中主要属性,包括了图表区域的颜色.线条.高度.宽度.对齐.图表类型等诸多属性,也是HighCharts图表中必须配置的属性之一. 配置cha ...
- 基于ssh框架的highcharts前后台数据交互实例
Highcharts 是一个用纯JavaScript编写的一个图表库, 能够很简单便捷的在web网站或是web应用程序添加有交互性的图表,并且免费提供给个人学习.个人网站和非商业用途使用.HighCh ...
- 网页图表Highcharts实践教程之图表代码构成
网页图表Highcharts实践教程之图表代码构成 Highcharts第一个实例 下面我们来实现本书的第一个Highcharts实例. [实例1-1]下面来制作北京连续一周最高温度折线图.操作过程如 ...
- highCharts使用记录
公司的架构师让我做一个mockup,要用到highCharts,,以前想接触的,没时间学习,也没有用过,正好工作可以用上了,可以边学边做了. 环境 <script src="./js/ ...
- Highcharts 使用总结
一.Highcharts series属性 1.下面是一个基本曲线图的例子: <html> <head> <meta charset="UTF-8" ...
随机推荐
- itertools模块(收藏)
Python的内建模块itertools提供了非常有用的用于操作迭代对象的函数. count().cycle().repeat() 首先,我们看看itertools提供的几个“无限”迭代器: > ...
- keras搭建深度学习模型的一些小tips
定义模型两种方法: 1.sequential 类仅用于层的线性堆叠,这是目前最常用的网络架构 2.函数式API,用于层组成的有向无环图,让你可以构建任意形式的架构 from keras import ...
- window.open和window.showModalDialog
window.open window.open是打开一个新窗口 在window.open打开的窗口中刷新父页面 opener.location.reload(); 打开一个窗口格式:属性可以任意设置 ...
- vue框架(二)_vue环境搭建及创建项目
1.node.js:概念介绍及安装 node.js:是一个基于chrome浏览器的v8引擎,可以运行javascript的环境(平台) 特性:异步IO模型 npm:是一个包管理器(工具),可以按装依赖 ...
- TensorFlow 开发环境搭建--Pycharm
今天动手开始搭建TensorFlow开发环境, 用PyCharm来跑MNIST中的例子.记录过程如下 下载安装 (1)首先安装AnaConda, AnaConda可以帮忙去管理安装包,帮忙创建虚拟环境 ...
- Java的redis控制台-Jedis
jedis 源码地址:https://github.com/xetorthio/jedis
- LR和SVM的相同和不同
之前一篇博客中介绍了Logistics Regression的理论原理:http://www.cnblogs.com/bentuwuying/p/6616680.html. 在大大小小的面试过程中,经 ...
- HDU 1586 log 的运用
log函数的应用,因为 log(a^b)=b*log(a); log(a*b)=log(a)+log(b); 比如 log10(123456789)==log10(1.23456789)+8; log ...
- linux常用命令:traceroute 命令
通过traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径.当然每次数据包由某一同样的出发点(source)到达某一同样的目的地(destination)走的路径可能会不一 ...
- 浅谈class私有变量
class 的前世今生 在 es6 之前,虽然 JS 和 Java 同样都是 OOP (面向对象)语言,但是在 JS 中,只有对象而没有类的概念. 在 JS 中,生成实例对象的传统方法是通过构造函数, ...