Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html lang="en" ng-app="myApp">
    
    <head>
        <meta charset="utf-8">
        <title>My AngularJS App</title>
    </head>
    
    <body ng-controller="stageController">
         <h1>Plot: {{type}}</h1>

        <div id="ctrls">
            <p class="button" ng-click="utopia();">Utopia</p>
            <p class="button" id="nightmare">Nightmare</p>
            <br/>
            <p class="button red" id="broken">Doesn't work</p>
            <p class="button green" ng-click="initData();">Restore</p>
        </div>
        <div id="debug">
             <h2>Actual value of data:</h2>

            <ul>
                <li ng-repeat="d in data">{{d[0]}}: {{d[1]}}%</li>
            </ul>
        </div>
        <!-- directive -->
        <div id="container" draw-pie-chart=""></div>
    </body>

</html>
              
            
!

CSS

              
                </style> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<style>
.ng-invalid {
    border: 1px solid red;
}
body {
    padding:10px;
}
h1 {
    font-size:24px;
    font-weight:bold;
}
#debug {
    border:1px solid #999999;
    color:#999999;
    padding:10px;
    position:absolute;
    top:46px;
    right:20px;
    width:140px;
    z-index:10;
}
#debug h2 {
    color:#333333;
    font-size:16px;
    margin-bottom:5px;
}
#debug li {
    font-size:14px;
    margin:3px 0 0;
}
#debug li:nth-child(even) {
    color:#000000;
}
#ctrls {
    position:absolute;
    z-index:10;
}
#container {
    margin:0 auto;
    width:210px;
}
.button {
    border:1px solid #666666;
    cursor:pointer;
    display:inline-block;
    font-size:14px;
    margin-top:10px;
    padding:5px 10px;
    text-align:center;
    width:90px;
}
.button.red {
    border-color:#FF0000;
    color:#FF0000;
}
.button.green {
    border-color:Green;
    color:Green;
}
              
            
!

JS

              
                'use strict';


// Declare app level module which depends on filters, and services
angular.module('myApp', ['myApp.directives']);


/* Controllers */

function stageController($scope) {

    $scope.type = 'Browser Market Share';

    $scope.initData = function () {
        $scope.data = [
           ['Chrome', 47.0],
           ['Firefox', 33.0],
           ['IE', 20.0]
        ];
    }

    $scope.utopia = function () {
        $scope.data = [
           ['Chrome', 99.0],
           ['Firefox', 1.0],
           ['IE', 0.0]
        ];
    }

    $scope.initData();

}


/* Directives */

angular.module('myApp.directives', []).

directive('drawPieChart', function () {
    // return the directive link function. (compile function not needed)
    return function (scope, element, attrs) {

        var container = $(element).attr("id");

        // watch the expression, and update the UI on change.
        scope.$watch('data', function () {
            drawPlot();
        }, true);

        var broken = function () {
            scope.data = [
             ['Chrome', 33.3],
             ['Firefox', 33.3],
             ['IE', 33.3]
            ];
        };

        var nightmare = function () {
            scope.$apply(function () {
                scope.data = [
                 ['Chrome', 0.0],
                 ['Firefox', 1.0],
                 ['IE', 99.0]
                ];
            });
        };

        var drawPlot = function () {
            var chart;
            chart = new Highcharts.Chart({
                chart: {
                    renderTo: container
                },
                credits: {
                    enabled: false
                },
                title: {
                    text: ''
                },
                tooltip: {
                    pointFormat: '{series.name}: <b>{point.percentage}%</b>',
                    percentageDecimals: 1
                },
                plotOptions: {
                    pie: {
                        dataLabels: {
                            enabled: false
                        }
                    }
                },
                series: [{
                    type: 'pie',
                    name: 'Browser share',
                    data: scope.data
                }]
            });
        }

        $("#nightmare").on('click', nightmare);
        $("#broken").on('click', broken);

    }
});
              
            
!
999px

Console