npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

anychart-angularjs

v1.2.1

Published

AngularJS v1.x directives for AnyChart

Downloads

763

Readme

AngularJS v1.x directives for AnyChart

AngularJS v1.x directives for AnyChart provide an easy way to use AnyChart JavaScript Charts with AngularJS Framework.

Table of Contents

Download and install

Package managers

You can install AngularJS-plugin using npm, bower or yarn:

  • npm install anychart-angularjs
  • bower install anychart-angularjs
  • yarn add anychart-angularjs

Direct download

You can download AngularJS plugin directly from the dist folder.

Quick start

Here is a basic sample that shows how to add a chart:

<!DOCTYPE html>

<!-- Add the "ng-app" directive to activate MyApp module. -->
<html lang="en" ng-app="MyApp">
<head>
    <meta charset="UTF-8">
    <title>Anychart AngularJS plugin demo</title>
    
    <!-- Add libraries to work with. -->
    <script src="angular.min.js"></script>
    <script src="anychart-bundle.min.js"></script>
    <script src="anychart-angularjs.js"></script>

    <style>
        html, body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>

    <script>
        (function() {
            'use strict';
            
            // Declare your own module and controller
            // and inject anychart-angularjs module to
            // start working.
            angular
                    .module('MyApp', ['anychart-angularjs'])
                    .controller('MyCtrl', ['$scope', function($scope) {
                    
                        // In this basic case you just need to
                        // provide the data set to visualize.
                        $scope.myData = [
                            ["Chocolate", 5],
                            ["Rhubarb compote", 2],
                            ["Crêpe Suzette", 2],
                            ["American blueberry", 2],
                            ["Buttermilk", 1]
                        ];
                    }]);
        })();
    </script>
</head>

<!-- Add your controller -->
<body ng-controller="MyCtrl">

    <!-- Add AnyChart directives. It’s as easy as pie (chart)! --> 
    <div
            anychart
            ac-type="pie"
            ac-data="myData"
            ac-title="Simple Pie Demo"
            ac-legend="true"
            style="width: 100%; height: 100%">
    
    </div>
</body>
</html>

AnychartService

AnychartService is an Angular Service. It is used to share data between scopes and to provide more opportunities for developers. To use it in your module use the standard Angular DI mechanism.

By default, AnychartService, as a shareable object, contains two fields:

  • AnychartService.charts - an array that contains chart instances for dashboarding purposes.
  • AnychartService.chart - current chart. Auto or manually created. It is useful for any deferred actions like async data loading.
angular
       .module('MyApp', ['anychart-angularjs'])
       .controller('MyCtrl', ['$scope', '$http', 'AnychartService', function($scope, $http, AnychartService) {
           var service = AnychartService;
           $http.get('sample1.json').then(function(response) {
               if (service.chart) // If a chart is successfully instantiated.
                   service.chart.data(response.data);
           });
       }]);

Available Directives

Directive | Code sample | Description --- | --- | --- anychart | <div anychart></div> | Supports attributes specific to this directive and generates a chart from anychart module (not gantt, map or stock chart types) anygantt | <div anygantt></div> | Supports attributes specific to this directive and generates a chart from anygantt module (ganttResource and ganttProject) anymap | <div anymap></div> |Supports attributes specific to this directive and generates a chart from anymap module (choropleth, bubbleMap, etc.). anystock | <div anystock></div> | Supports attributes specific to this directive and generates a chart from anystock module (anychart.stock). anychart-stage | <div anychart-stage></div> | Generates anychart stage to deal with complex charts and any kind of custom drawing.

anychart directive attributes

This directive is used to work with charts from anychart module.

Attribute | View Sample | Controller Sample | Description --- | --- | --- | --- ac-type | <div anychart ac-type="line"></div> | - | Kind of chart to create. In a sample, anychart.line() constructor is called. ac-data | <div anychart ac-data="myData"></div> | $scope.myData = [ ... ];| Data to be put into a $scope of your controller in a field named myData. This value is a data source for a chart. Please note that for anychart directive we set the data with chart.data()-method. If chart doesn't have this method, use ac-instance directive instead (described below).
ac-title | <div anychart ac-title="My Custom Title"></div> | - | Sets a string value to a chart title. ac-legend | <div anychart ac-legend="true"></div> | - | A string representation of a boolean flag. Enables/disables a legend. ac-instance | <div anychart ac-instance="myChart"></div> | $scope.myChart = chart; | Chart instance is created in a controller manually and it is used instead of auto-created. In this case a chart can be configired using Anychart API and access to the settings is not available via these ac-attributes. To make it work, create an instance manually, configure it and put into a $scope in specified field. ac-chart-draw | <div anychart ac-chart-draw="afterDrawHandler"></div> | $scope.afterDrawHandler = function(chart) { ... }; | Function called after the chart is drawn. Takes a chart itself as and argument.

Please note: No need to set a container of a chart and call chart.draw(). The plugin does it automatically.

Sample:

<div anychart ac-data="myData" ac-type="pie" ac-chart-draw="afterDrawHandler"></div>
angular
        .module('MyApp', ['anychart-angularjs'])
        .controller('MyCtrl', ['$scope', function($scope) {
            $scope.myData = [
                ["Chocolate", 5],
                ["Rhubarb compote", 2],
                ["Crêpe Suzette", 2],
                ["American blueberry", 2],
                ["Buttermilk", 1]
            ];
            
            $scope.afterDrawHandler = function(chart) {
                chart.title('After draw title');
            }
        }]);

anychart-stage directive attributes

This directive is used to draw anychart stage for custom drawing and complex charts.

Attribute | View Sample | Controller Sample | Description --- | --- | --- | --- ac-instance | <div anychart-stage ac-instance="myStage"></div> | $scope.myStage = stage; | A stage instances is created in a controller manually and it is used instead of auto-created. In this case a stage is configured using Anychart API and access to the settings is not available via these ac-attributes. To make it work, create an instance manually, configure it and put into a $scope into a specified field.

AnychartService can be used it to deal with anychart stage. Take a look at this sample:

angular
       .module('MyApp', ['anychart-angularjs'])
       .controller('MyCtrl', ['$scope', 'AnychartService', function($scope, AnychartService) {
           var data = [
               ["Chocolate", 5],
               ["Rhubarb compote", 2],
               ["Crêpe Suzette", 2],
               ["American blueberry", 2],
               ["Buttermilk", 1]
           ];
       
           var pie = anychart.pie(data);
           pie.title("Top 5 pancake fillings");
           pie.bounds(0, 0, '50%', '100%');
       
           var line = anychart.line(data);
           line.title("Top 5 pancake fillings");
           line.bounds('50%', 0, '50%', '100%');
       
           var afterDrawCallback = function(chart) {
               chart.title('After Draw Title');
           };
       
           AnychartService.charts.push(
                   {
                       chart: pie,
                       chartDraw: afterDrawCallback
                   },
                   line
           );
       
       }]);

This is what happens in the sample above:

  • Instances of anychart.pie and anychart.line are created.
  • Data, bounds, title and so one are configured.
  • Charts art put into AnychartService.charts. Note that we wrap pie-chart into an object with one additional field:: chartDraw. chartDraw is a function that is called after pie chart is drawn with a single argument that is pie chart itself.
  • Controller of anychart-stage directive processes the AnychartService.charts array.

anygantt directive attributes

This directive is used to deal with charts from anygantt module (ganttResource, ganttProject).

Attribute | View Sample | Controller Sample | Description --- | --- | --- | --- ac-type | <div anygantt ac-type="ganttProject"></div> | - | Kind of gantt chart to be created. In a sample, anychart.ganttProject()-constructor will be called. ac-data | <div anygantt ac-data="myData"></div> | $scope.myData = tree; | Just as the corresponding directive of anychart-directive, data tree is put into a $scope in a specified field.
ac-title | <div anygantt ac-title="My Custom Title"></div> | - | Sets a string value to a chart title. ac-instance | <div anygantt ac-instance="myChart"></div> | $scope.myChart = chart; | Works with a predefined chart instance (see anychart directive). ac-chart-draw | <div anygantt ac-chart-draw="afterDrawHandler"></div> | $scope.afterDrawHandler = function(chart) { ... }; | Works the same way as described in anychart directive. ac-splitter-position | <div anygantt ac-splitter-position="300"></div> | - | Sets gantt chart splitter position.

anymap directive attributes

This directive is used to deal with charts from anymap module (choropleth, bubbleMap, etc).

Attribute | View Sample | Controller Sample | Description --- | --- | --- | --- ac-type | <div anymap ac-type="map"></div> | - | See anychart directive corresponding attribute. ac-data | <div anymap ac-data="myData"></div> | $scope.myData = data; | See anychart directive corresponding attribute.
ac-title | <div anymap ac-title="My Custom Title"></div> | - | See anychart directive corresponding attribute. ac-legend | <div anymap ac-legend="true"></div> | - | See anychart directive corresponding attribute. ac-instance | <div anymap ac-instance="myChart"></div> | $scope.myChart = chart; | See anychart directive corresponding attribute. ac-chart-draw | <div anymap ac-chart-draw="afterDrawHandler"></div> | $scope.afterDrawHandler = function(chart) { ... }; | See anychart directive corresponding attribute. ac-geo-data | <div anymap ac-geo-data="anychart.maps.australia"></div> | - | Required attribute. Differs from ac-data: ac-geo-data sets geo data source, ac-data is a data for the default map series.

anystock directive attributes

Works only with ac-instance and ac-chart-draw attributes because of the specifics of Stock Chart setup.

Demos overview

See these samples to learn how things work:

Contacts

Links

License

AngularJS v1.x directives for AnyChart include two parts:

  • code of the plugin that allows to use Javascript library (in this case, AnyChart) with AngularJS 1.x. You can use, edit, modify it, use it with other Javascript libraries without any restrictions. It is released under Apache 2.0 License.
  • AnyChart JavaScript library. It is released under Commercial license. You can test this plugin with the trial version of AnyChart. Our trial version is not limited by time and doesn't contain any feature limitations. Check details here.

If you have any questions regarding licensing - please contact us. [email protected] Analytics