前端echarts基本图标样式展示

需要引入echarts的js包

html页面代码
 

 <div id="barhours" style="align:center; height:500px; width:95%;"></div>

javascript代码

var myChart1= echarts.init(document.getElementById('barhours'), 'macarons');
var option1 = {
		color:['Red','orange','#FDE11C','green','#1387F4','purple'],//这里设置柱状图颜色
		    title: {
		    left:'5%',
	        text:  ['图标'],//这里是图表标题名字  
	        backgroundColor:'#fff',
	        textStyle:{ 
	        	fontSize:12,
	        }
	    },
	    tooltip: {
	        trigger: 'axis',
	        backgroundColor:'#636363',
	        formatter: function (params) {//在这个方法里的效果:鼠标放入柱状图时需显示的数据
                //这里我是用的循环来做的操作
	        	var res="<div><p>"+params[0].name+"</p></div>";
	        	var num = 0;
	        	for(var i=0;i<params.length;i++){
        		num = num+params[i].data;
	        	}
	        	for(var i=0;i<params.length;i++){
        		res+='<p>'+params[i].seriesName+""+params[i].data+""+'</p>';
	        	}
	        	res+='<p>'+"总:"+num+'</p>';
        	return res;
	        	}  
	    },
	    legend: {
	    	textStyle: { //图例文字的样式
            fontSize: 9
        },
	        data:['0-100','100-500','500-1000','1000-2000','2000-10000','10000+']//这里与上面设置的color属性要对应
	    },
	    /*  grid: {
	        left: '10%',
	        right: '10%',
	        bottom: '13%',
	        top:'20%',
	        containLabel: true
	    },   */
	    
	    xAxis: {
	    	  name: 'X轴',
	         type: 'category',
		     boundaryGap: true,
		     axisLabel: {  
		    	   interval:0,  
		    	  // rotate:21 
		    	},
		     data: []
	    },
	    yAxis: {
	        type: 'value',
	        name: 'Y轴',
	        offset: 1,
	        splitNumber: 5,
	        axisLabel: {}
	    },
	     toolbox: {
	    	            show : true,
	    	            feature : {
	    	                mark : {show: true},
	    	                dataView : {show: true, readOnly: false},
	    	                magicType : {show: true, type: ['line', 'bar']},
	    	                restore : {show: true},
	    	                saveAsImage : {show: true}
	    	            }
	    	 },  
	    series: [{//在这里设置图标的数据显示
	 			name:'name1',
	            type:'bar',
	            stack: 'AB',
	            itemStyle : { normal: {label: {show: false}}},
	            barWidth:20,
	           data:[]
	       	  },{
	 			name:'name2',
	            type:'bar',
	            stack: 'AB',
	            barGap: '-100%',
	            barCategoryGap:'10',
	            barWidth:20,
	            itemStyle : { normal: {label: {show: false}}}, 
	            data:[]
	       	  },{
		 			name:'name3',
		            type:'bar',
		            stack: 'AB',
		            barGap: '-100%',
		            barCategoryGap:'10',
		            barWidth:20,
		            itemStyle : { normal: {label: {show: false}}}, 
		            data:[]
		       	  },{
			 			name:'name4',
			            type:'bar',
			            stack: 'AB',
			            barGap: '-100%',
			            barCategoryGap:'10',
			            barWidth:20,
			            itemStyle : { normal: {label: {show: false}}}, 
			            data:[]
			       	  },{
				 			name:'name5',
				            type:'bar',
				            stack: 'AB',
				            barGap: '-100%',
				            barCategoryGap:'10',
				            barWidth:20,
				            itemStyle : { normal: {label: {show: false}}}, 
				            data:[]
				       	  },{
					 			name:'name6',
					            type:'bar',
					            stack: 'AB',
					            barGap: '-100%',
					            barCategoryGap:'10',
					            barWidth:20,
					            itemStyle : { normal: {label: {show: false}}}, 
					            data:[]
					       	  }]
		};
$(function(){//页面启动加载
		onsize();
		myChart1.setOption(option1);
	    submit();
});
window.onresize = function(){
		onsize();
	}
function onsize(){
	 var h= $(window).height()-20;
  	 var w= $("#maxdiv").width(); 
  	myChart1.resize();
}
 function submit(){
	jQuery.ajax({
        "async":true,  //异步加载
        "data":{}, //参数json格式
        //"type":"POST",//提交方式
        "url":"",
        "dataType":"json",
         "success":function(res){
       	  //重置option中的data数据,为了避免冲突
   		   option1.series[0].data=[];
		   option1.series[1].data=[];
		   option1.series[2].data=[];
		   option1.series[3].data=[];
		   option1.series[4].data=[];
		   option1.series[5].data=[];
        	  //遍历数据
        	  if(res.result != null){
			   $.each(res.result, function(index, element) {
				   option1.xAxis.name="";
				   option1.xAxis.data[i]="";
				   option1.series[0].data[i]=element['后台返回参数名'];
				   option1.series[1].data[i]=element['后台返回参数名'];
				   option1.series[2].data[i]=element['后台返回参数名'];
				   option1.series[3].data[i]=element['后台返回参数名'];
				   option1.series[4].data[i]=element['后台返回参数名'];
				   option1.series[5].data[i]=element['后台返回参数名'];
			}) 
			}
			}
      	  myChart1.setOption(option1);
       }
      });
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值