angularJs和echarts结合实例

最近在做图标展示用到


不多说直接上代码了;

<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
</head>
<body ng-app="app">
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
    <div  style="height:400px">
		<div ng-controller="sexChart" style="height:1400px">
			<sexbar id="sexBarcharts" legend="legend"  data="data"></sexbar>
		</div>
	</div>
    <!-- ECharts单文件引入 -->
    <!--<script src="G:/1115zhuomian/3banben/echarts.min.js"></script> -->
	<script src="G:/1115zhuomian/angularJsAndEcharts/angular.js"></script>
<script src="G:/1115zhuomian/angularJsAndEcharts/echarts.js"></script>  
	
    <script type="text/javascript">
       
       var app = angular.module('app', []); 
	   console.log("ceshi输出");


	   app.controller('sexChart', function($scope) {  
    $scope.legend = ["男", "女"];  
   // $scope.item = ['Jan', 'Feb', 'Mar', 'Apr', 'Mar', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];  
    $scope.data = [  
        {value:78, name:'男'},{value:56,name:'女'} //Berlin  
    ];  
});  

app.directive('sexbar', function() {  
    return {  
        scope: {  
            id: "@",  
            legend: "=",  
            //item: "=",  
            data: "="  
        },  
        restrict: 'E',  
        template: '<div style="height:400px;"></div>',  
        replace: true,  
        link: function($scope, element, attrs, controller) {
			var a = []; 
            var option = { 
				
				title:{
						text : '性别比例',//标题说明
						x:'center'//居中
					},
                // 提示框,鼠标悬浮交互时的信息提示  

                tooltip: {  
                    show: true,  
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },  
                // 图例  
                legend: {
					 x : 'center',
					 y : 'bottom',
                    data: $scope.legend  
                },  
               
                // 数据内容数组  
                series:	[
				{
							name:'',
							type: 'pie', 
							radius:"55%",
							center:['50%','50%'],
				
				label: { 
		            	 normal: { 
		            		 position: 'inner' //内置文本标签 
		            	 } 
		            },
		            labelLine: {
		                normal: {
		                    show: false
		                }
		            },
				

				data:$scope.data,

				
				 itemStyle : {
										normal: {
											label: {
											show: false
										},
											labelLine: {
												show: false
											}
										} ,
										emphasis: {
											label: {
												show: true,
												position: 'outer'
											},
											labelLine: {
												show: true,
												lineStyle: {
												color: 'red'
												},
												},
											}
									}
				}
				
				]
				  
            };  
            var myChart = echarts.init(document.getElementById($scope.id),'macarons');  
            myChart.setOption(option);  
        }  
    };  
}); 

    </script>
</body>









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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值