highcharts饼图展示

个人做项目期间遇到一个需要用图形来展示数据的模块 在网上找了很久 前两天是数据都拿到了 返回格式跟饼图的格式一模一样 就是不出来我想要的数据 然而今天看了一篇博主的博客发现是我想要的效果 使用了一下发现图形出来了 困扰了我这两天头疼的事情

在写展示图形的时候 js里要写两个方法  前提是dao层那边返回格式必须跟这个饼图要一样

<script type="text/javascript">
$(function() {
	getcount();
	showCharts();
});

var arr = [];
function getcount(){
	arr = [];
	$.ajax({
		async:false,
		type:'post',
		url: pro_Url+'/dict/serviceAction_typeCount',
		dataType:"json",
		success:function(data){
			$(data).each(function(i,item){
				console.log(item.name);
                arr.push([item.name,Number(item.y)]);
            }); 
		}
	})
}
function showCharts() {
	Highcharts.setOptions({ 
	    colors: [ '#6AF9C4','#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#058DC7','#64E572', '#FF9655', 
	'#FFF263'] 
	}); 
	var chart = Highcharts.chart('container', {
	chart: {
			plotBackgroundColor: null,
			plotBorderWidth: null,
			plotShadow: false
	},
	title: {
			text: '订单物料数量占比',
			style:{
				color: '#3E576F',
		        fontSize: '25px',
		        fontWeight: 'bold'
		    }
	},
	tooltip: {
			headerFormat: '{series.name}<br>',
			pointFormat: '{point.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) || '#058DC7'
							}
					},
					showInLegend: true ,
					states: {
							hover: {
									enabled: false
							}  
					},
					slicedOffset: 20,         // 突出间距
					point: {                  // 每个扇区是数据点对象,所以事件应该写在 point 下面
							events: {
									// 鼠标滑过是,突出当前扇区
									mouseOver: function() {
											this.slice();
									},
									// 鼠标移出时,收回突出显示
									mouseOut: function() {
											this.slice();
									},
									// 默认是点击突出,这里屏蔽掉
									click: function() {
											return false;
									}
							}
					}
			}
	},
	series: [{
		    size:'100%',
			type: 'pie',
			name: '服务',
		    data:  arr //放上面最后返回的数组
	}]
});
}

</script>

控制层 我最后返回的是list装的map集合

/**
	 * 查询类型的count
	 * @return
	 */
	public String typeCount() {
		List<Map<String, Object> > list=new ArrayList<>();
		Map<String, Object> dict=null ;
		try {
			List<Map<String, Object>> typeCount = this.serviceBiz.typeCount(request.getParameterMap(),null);
			for (Map<String, Object> map : typeCount) {//再次遍历
				dict= new HashMap<>();
				String name=(String) map.get("svr_type");
				dict.put("name",name);
				dict.put("y",map.get("count"));
				list.add(dict);
			}
			System.out.println(typeCount);
			System.out.println(list);
			super.writer(list);
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

记住一点 格式name是String y是int型 这里是f12打印

    1. {name: "咨询", y: 1}
    2. 1:{name: "建议", y: 2}
    3. 2:{name: "投诉", y: 1}

 

最后效果:34254

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值