echart-helper是一款辅助echarts开发的jQuery插件,能够帮助开发者快速构建echart图表。
引入jquery、echarts及echarts.helper三个文件即可
<script src="jquery-1.9.1.min.js"></script>
<script src="echarts.min.js"></script>
<script src="echarts.helper.js"></script>
完整使用说明请前往看云:https://www.kancloud.cn/qw_xingzhe/echart-helper/668005
以下为部分使用说明
html
<div class="echart-canvas"
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"}'></div>
js(后续js部分标签绑定与此处相同,皆省略)
$('body').EChartHelper();
html
<div class="canvas-box echart-canvas-01"></div>
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);
html
<div class="canvas-box echart-canvas-02"></div>
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"}
}
});
html
<div class="canvas-box echart-canvas-04"></div>
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"}
}
});
简单数据格式请求
<div class="echart-canvas canvas-box echart-canvas-01-01"
echart-url='./data_simple.js'
echart-config='{data_name:"分值占比",type:"pie",name_key:"title",value_key:"get_score"}'></div>
完整数据格式请求
<div class="echart-canvas canvas-box echart-canvas-01-01"
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"}'></div>
需要引入样式文件(此处以 wonderland 为例),可配置自定义样式:http://echarts.baidu.com/theme-builder/ 下载引入后即可配置使用。
js
<script src="jquery-1.9.1.min.js"></script>
<script src="echarts.min.js"></script>
<script src="./theme/wonderland.js"></script>
<script src="../echarts.helper.js"></script>
<script>
$('body').EChartHelper({
'theme':'wonderland',
});
</script>
在 chartOption 内以图表类型为 key 传入需要自定义的配置内容即可。 具体配置内容请参考 echarts 官方文档。
$('body').EChartHelper({
'chartOption':{
'pie':{
title : {
subtext: '纯属虚构123',
},
}
}
});
a) 雷达图 radar
相对于饼图增加了一个总数字段
html
<div class="echart-canvas"
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:"得分"}'></div>
b) 柱状图 bar html
<div class="echart-canvas"
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} 秒"}}}'></div>
c) 折线图 line
此处仅需要将柱状图 echart-config 中 type 属性改为 line 即可
html
<div class="echart-canvas"
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:"单题用时/秒"}' ></div>
d) 组合折线图 line
会自动将x轴无数据的字段填充0
html
<div class="echart-canvas"
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} 人次"}}}'></div>
e) 组合柱状图 bar
同理,修改组合折线图 echart-config 中的 type 值为 bar 即可
html
<div class="echart-canvas"
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} 人次"}}}'></div>
f) 组合柱状图+折线图 bar+line
将 echart-config 中相关字段使用数组配置
html
<div class="echart-canvas"
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} 秒"}}]}'></div>
g) 仪表盘 gauge html
<div class="echart-canvas"
echart-data='{"get_score_proportion_centesimal":70.833333333333}'
echart-config='{type:"gauge",data_name:"得分统计",name_value:"正确率",value_key:"get_score_proportion_centesimal"}' ></div>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型