php 占比图,ECharts-Helper: echart-helper是一款辅助echarts开发的jQuery插件,能够帮助开发者快速构建echart图表。...

ECharts-Helper

项目介绍

echart-helper是什么?

echart-helper是一款辅助echarts开发的jQuery插件,能够帮助开发者快速构建echart图表。

安装教程

引入jquery、echarts及echarts.helper三个文件即可

实现原理

将 echarts 各类通用配置预先放入插件中,减少后续相关配置信息的写入,同时,任意内容均可通过配置进行覆盖(可完全复制使用echarts原生格式)。

将后端数据自动格式化成 echarts 所需格式,减少数据再次整理的过程。

实现功能

html标签绑定数据,渲染图表

js调用生成图表

异步请求url渲染图表

配置使用主题

可自定义基础配置模版

使用说明

以下为部分使用说明

html

echart-data='[{"title":"基础知识","get_score":11},{"title":"加分知识","get_score":12},{"title":"未分组","get_score":8}]'

echart-config='{data_name:"分值占比",title:"分组得分占比图",type:"pie",name_key:"title",value_key:"get_score"}'>

js(后续js部分标签绑定与此处相同,皆省略)

$('body').EChartHelper();

761a5750f9f26716d224712905f55910.png

js调用渲染

html

js

var drawData = {

echart_data : [{"title":"基础知识","get_score":11},{"title":"加分知识","get_score":12},{"title":"未分组","get_score":8}],

echart_config : {title:"分组得分占比图",type:"pie",name_key:"title",value_key:"get_score"}

};

$('.canvas-box echart-canvas-01').drawEChart(drawData);

js 简单定义数据

html

js

// data_simple.js 在 demo中返回数据为:[{"title":"基础知识","get_score":11},{"title":"加分知识","get_score":12},{"title":"未分组","get_score":8}]

$('.echart-canvas-02').getDrawEChart({

'url' : './data_simple.js',

'drow_data' : {

echart_config : {title:"分组得分占比图",type:"pie",name_key:"title",value_key:"get_score"}

}

});

js 完整定义数据,自定义请求类型

html

js

// data_profession.js 在 demo中返回数据为:{"code":1,"dataset":[{"title":"基础知识","get_score":5},{"title":"加分知识","get_score":10},{"title":"未分组","get_score":5}]}

$('.echart-canvas-04').getDrawEChart({

'url' : './data_profession.js',

'type' : 'POST',

'data' : {p:1},

'success_key' : 'code', // 数据请求成功标识字段名

'success_val' : '1', // 数据请求成功标识字段值

'data_key' : 'dataset', // 数据使用字段

'drow_data' : {

echart_config : {title:"分组得分占比图",type:"pie",name_key:"title",value_key:"get_score"}

}

});

异步请求,url标签绑定

简单数据格式请求

echart-url='./data_simple.js'

echart-config='{data_name:"分值占比",type:"pie",name_key:"title",value_key:"get_score"}'>

完整数据格式请求

echart-ajax='{url:"./data_profession.js",success_key:"code",success_val:1,data_key:"dataset"}'

echart-config='{data_name:"分值占比",type:"pie",name_key:"title",value_key:"get_score"}'>

配置主题

需要引入样式文件(此处以 wonderland 为例),可配置自定义样式:http://echarts.baidu.com/theme-builder/ 下载引入后即可配置使用。

js

$('body').EChartHelper({

'theme':'wonderland',

});

2b21862755544e51e67386cc639bb625.png

配置模版

在 chartOption 内以图表类型为 key 传入需要自定义的配置内容即可。

具体配置内容请参考 echarts 官方文档。

$('body').EChartHelper({

'chartOption':{

'pie':{

title : {

subtext: '纯属虚构123',

},

}

}

});

其他配置展示

a) 雷达图 radar

相对于饼图增加了一个总数字段

html

echart-data='[{"title":"基础知识","get_score":11,"group_total_score":13},{"title":"加分知识","get_score":5,"group_total_score":5},{"title":"未分组","get_score":1,"group_total_score":6}]'

echart-config='{type:"radar",name_key:"title",value_key:"get_score",max_key:"group_total_score",data_name:"得分"}'>

abdf1f0f296db8c6357b8c94a064631e.png

b) 柱状图 bar

html

echart-data='[{"use_second":99,"topic_tip":"第1题"},{"use_second":6,"topic_tip":"第2题"},{"use_second":3,"topic_tip":"第3题"},{"use_second":4,"topic_tip":"第4题"}]'

echart-config='{type:"bar",name_key:"topic_tip",value_key:"use_second",data_name:"单题用时/秒"}'

echart-option='{yAxis: {axisLabel: {formatter: "{value} 秒"}}}'>

874b4c130ee9bc29b215102dd4da1bd8.png

c) 折线图 line

此处仅需要将柱状图 echart-config 中 type 属性改为 line 即可

html

echart-data='[{"use_second":99,"topic_tip":"第1题"},{"use_second":6,"topic_tip":"第2题"},{"use_second":3,"topic_tip":"第3题"},{"use_second":4,"topic_tip":"第4题"}]'

echart-config='{type:"line",name_key:"topic_tip",value_key:"use_second",data_name:"单题用时/秒"}' >

8657c6436cce519f0230c8035e3d6bc9.png

d) 组合折线图 line

会自动将x轴无数据的字段填充0

html

echart-data='[{"count":2,"day":"2017-09-17","project_name":"中级PHP工程师"},{"count":3,"day":"2017-09-16","project_name":"中级PHP工程师"},{"count":1,"day":"2017-09-10","project_name":"中级PHP工程师"},{"count":2,"day":"2017-08-30","project_name":"极速职业测评"},{"count":1,"day":"2017-08-30","project_name":"中级PHP工程师"},{"count":1,"day":"2017-08-29","project_name":"极速职业测评"},{"count":1,"day":"2017-08-29","project_name":"中级PHP工程师"},{"count":1,"day":"2017-08-28","project_name":"极速职业测评"},{"count":1,"day":"2017-08-27","project_name":"极速职业测评"},{"count":1,"day":"2017-08-26","project_name":"极速职业测评"},{"count":1,"day":"2017-08-25","project_name":"极速职业测评"},{"count":2,"day":"2017-08-24","project_name":"极速职业测评"},{"count":2,"day":"2017-08-24","project_name":"中级PHP工程师"},{"count":1,"day":"2017-08-23","project_name":"中级PHP工程师"},{"count":1,"day":"2017-08-21","project_name":"中级PHP工程师"}]'

echart-config='{type:"line",name_key:"day",value_key:"count",data_key:"project_name"}'

echart-option='{yAxis: {axisLabel: {formatter: "{value} 人次"}}}'>

ec20bcd6aa1c14170d27be6cef007a9a.png

e) 组合柱状图 bar

同理,修改组合折线图 echart-config 中的 type 值为 bar 即可

html

echart-data='[{"count":2,"day":"2017-09-17","project_name":"中级PHP工程师"},{"count":3,"day":"2017-09-16","project_name":"中级PHP工程师"},{"count":1,"day":"2017-09-10","project_name":"中级PHP工程师"},{"count":2,"day":"2017-08-30","project_name":"极速职业测评"},{"count":1,"day":"2017-08-30","project_name":"中级PHP工程师"},{"count":1,"day":"2017-08-29","project_name":"极速职业测评"},{"count":1,"day":"2017-08-29","project_name":"中级PHP工程师"},{"count":1,"day":"2017-08-28","project_name":"极速职业测评"},{"count":1,"day":"2017-08-27","project_name":"极速职业测评"},{"count":1,"day":"2017-08-26","project_name":"极速职业测评"},{"count":1,"day":"2017-08-25","project_name":"极速职业测评"},{"count":2,"day":"2017-08-24","project_name":"极速职业测评"},{"count":2,"day":"2017-08-24","project_name":"中级PHP工程师"},{"count":1,"day":"2017-08-23","project_name":"中级PHP工程师"},{"count":1,"day":"2017-08-21","project_name":"中级PHP工程师"}]'

echart-config='{type:"bar",name_key:"day",value_key:"count",data_key:"project_name"}'

echart-option='{yAxis: {axisLabel: {formatter: "{value} 人次"}}}'>

c437a6678aef582f0c1dbd298517b05d.png

f) 组合柱状图+折线图 bar+line

将 echart-config 中相关字段使用数组配置

html

echart-data='[{"use_second":140,"get_score":0,"get_score_proportion_centesimal":0,"participator":"第84位考生"},{"use_second":52,"get_score":10,"get_score_proportion_centesimal":40,"participator":"第86位考生"},{"use_second":162,"get_score":15,"get_score_proportion_centesimal":50,"participator":"第88位考生"}]'

echart-config='{type:["bar","line"],name_key:"participator",value_key:["get_score_proportion_centesimal","use_second"],data_name:["正确率","用时"]}'

echart-option='{yAxis: [{axisLabel: {formatter: "{value} %"}},{axisLabel: {formatter: "{value} 秒"}}]}'>

ba11ab3c2255f1611211061ff79a12cc.png

g) 仪表盘 gauge

html

echart-data='{"get_score_proportion_centesimal":70.833333333333}'

echart-config='{type:"gauge",data_name:"得分统计",name_value:"正确率",value_key:"get_score_proportion_centesimal"}' >

2105ec736b1bb00730f3f5a6954c41b8.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值