【Echarts】Echarts2.0动态加载柱状图~
来源:互联网 发布:全民突击刷钻石软件 编辑:程序博客网 时间:2024/05/22 00:43
Echarts在数据可视化方面广泛使用,记录一个使用Echarts动态加载折线图和柱状图的例子。方便以后使用。
与上一篇不同的是,本例子将整个chart放在AJAX的success中加载,而不是只将series[]数据部分加载。【Echarts】2.0官方API:http://echarts.baidu.com/echarts2/doc/example.html
【Echarts】3.0官方API:http://echarts.baidu.com
js代码:
// 经济发展主要指标配置项function getEconomicsEcharts() {$.ajax({type : 'GET',async : false,url : location.protocol + "/bonc_kmioc_ind/fullscreenOverview/getEconomicsEcharts",data : {year : "2015"},success : function(result) {var myChart = echarts.init(document.getElementById('industryAddedChart'));var data = result.dataArr;var xAxisArr = result.xAxisArr;var legendArr = result.legendArr;// 经济发展主要指标配置项var industryAddedOption = {grid : {show : true,top : 28,right : 20,borderColor : 'transparent'},legend : {right : 50,data : [ '2010年', '2015年' ],color : '#fff',icon : 'bar',itemWidth : 10,itemHeight : 10,textStyle : {color : '#fff',weight : 'bold'}},calculable : true,xAxis : [ {axisLabel : {interval : 0,rotate : 37,textStyle : {color : '#fff',// weight: 'bold',fontSize : 12}},axisLine : { // 轴线show: true,lineStyle : {//轴线颜色样式color : "#fff",type : 'solid',width : 1}},axisTick : {show : false,},type : 'category',data : xAxisArr} ],yAxis : [ {axisLabel : {textStyle : {color : '#fff',// weight: 'bold',fontSize : 12}},axisLine : { // 轴线show: true,lineStyle : {//轴线颜色样式color : "#fff",type : 'solid',width : 1}},left : '5%',splitLine : {show : false},type : 'value',splitArea : {show : true,areaStyle : {color : [ '#131e2b', 'transparent' ]}},name : '(亿元)',nameLocation : 'end',nameTextStyle : {color : '#fff',// weight: 'bold',fontSize : 12,fontFamily : 'MicrosoftYaHei'},} ],series : [{name : '2010年',type : 'bar',data : data[1],itemStyle : {normal : {color : new echarts.graphic.LinearGradient(0, 0, 0, 1, [ {offset : 0,color : '#2ECBB8'}, {offset : 1,color : '#0C5C67'} ])},},barWidth : 20,label : {normal : {show : true,position : 'top',textStyle : {color : '#fff',fontSize : 12,fontFamily : 'MicrosoftYaHei'}},},},{barGap : '22%',name : '2015年',type : 'bar',data : data[0],barWidth : 22,itemStyle : {normal : {color : new echarts.graphic.LinearGradient(0, 0, 0, 1, [ {offset : 0,color : '#C43144'}, {offset : 1,color : '#413577'} ])},},label : {normal : {show : true,position : 'top',textStyle : {color : '#fff',fontSize : 12,fontFamily : 'MicrosoftYaHei'}},},}]};myChart.setOption(industryAddedOption);}});}
service层方法:
/** * 获取经济指标统计图数据 * * @param statisticalYear * @return */@Overridepublic Map<String, Object> getEconomicsEcharts(String statisticalYear) {Map<String, Object> data = new HashMap<String, Object>();List<EconomicsNorm> list = economicsNormDao.fingEconomicsInfo(statisticalYear);if (list != null && list.size() != 0) {int countTimes = getCountTimes(list.size());String[] xAxisArray = new String[countTimes];String[] legendArr = new String[] { "2010", "2015" };String[] firstArr = new String[countTimes];for (int i = 0; i < countTimes; i++) {xAxisArray[i] = list.get(list.size() - countTimes + i).getNormName();firstArr[i] = list.get(list.size() - countTimes + i).getNormValue();}data.put("xAxisArr", xAxisArray);data.put("dataArr", firstArr);data.put("legendArr", legendArr);} else {data.put("xAxisArr", new String[0]);data.put("dataArr", new Double[0][0]);data.put("legendArr", new String[0]);}return data;}
结果:
0 0
- 【Echarts】Echarts2.0动态加载柱状图~
- 【Echarts】Echarts2.0动态加载折现图和柱状图~
- 【Echarts】Echarts2.0动态加载扇形图。
- SSM echarts 柱状图 动态加载
- ECharts2.0柱状图横向显示
- ECharts2.0横向显示柱状图
- Echarts2 柱状图
- echarts动态加载数据,显示柱状图,饼图图表
- echarts柱状图带加载动画
- Echarts2.0和Echarts3.0添加柱状图标签值
- echarts异步加载柱状图数据叠加
- ECharts 柱状图动态获取json数据
- ECharts 柱状图动态获取json数据
- Echarts动态加载
- echarts动态加载data
- Echarts报表动态加载
- echarts动态加载数据
- Echarts动态加载数据
- Spring MVC框架errors标签的使用
- 实现缓存对话框类,设置注册表
- linux php安装redis扩展
- MD5算法C/C++的实现
- Android 自定义背景系列
- 【Echarts】Echarts2.0动态加载柱状图~
- UWP入门(九)-- 枚举和查询文件和文件夹
- volatile不能保证原子性,也就不能保证线程安全
- superset介绍跟环境搭建
- CCF习题 201703-4 地铁修建(dijkstra 或者 最小生成树)
- xshell+xftp在Linux的tomcat下部署web项目
- 醉了,删除文件夹失败的原因竟是它.....
- 浅谈Web网站架构演变过程
- 使用Gson反序列化时导致实体类的默认值失效了,坑点。