首页 > 其他 > 详细

angular中的echarts实例

时间:2020-08-12 17:12:38      阅读:124      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../lib/reset.css">
    <script src="../lib/angular-1.7.0/angular.min.js"></script>
    <script src="../lib/echarts/echarts.js"></script>
</head>
<body ng-app="app" ng-controller="myCtrl">
<div e-chart ec-data="option" style=‘width: 500px; height: 300px; float:left‘></div>
<script>
    var app=angular.module(‘app‘,[]);
    app.controller(‘myCtrl‘,function($scope){
        $scope.option={
            title: {
                text: ‘第一个 ECharts 实例‘
            },
            tooltip: {},
            legend: {
                data:[‘销量‘]
            },
            xAxis: {
                data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
            },
            yAxis: {},
            series: [{
                name: ‘销量‘,
                type: ‘bar‘,
                data: [5, 20, 36, 10, 10, 20]
            }]
        }
    });
    app.directive("eChart", function($http, $window) {
        function link($scope, element, attrs) {
            //初始化图表
            var myChart = echarts.init(element[0]);
            //监控option数据变化
            $scope.$watch(
                attrs["ecData"],
                function() {
                    var option = $scope.$eval(attrs.ecData);
                    if (angular.isObject(option)) {

                        //绘制图表
                        myChart.setOption(option);
                    }
                },
                true
            );

            $scope.getDom = function() {
                return {
                    height: element[0].offsetHeight,
                    width: element[0].offsetWidth
                };
            };
            //监控图表宽高变化,响应式
            $scope.$watch(
                $scope.getDom,
                function() {
                    // resize echarts图表
                    myChart.resize();
                },
                true
            );
        }
        return {
            //A 作为属性使用
            restrict: "A",
            link: link
        };
    });
</script>
</body>
</html>

  

angular中的echarts实例

原文:https://www.cnblogs.com/SpringAndMoon/p/13491379.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!