Giter VIP home page Giter VIP logo

angles's Introduction

Angles.js

An angular.js wrapper for the Chart.js library.

Chart.js Documentation

New Update of ChartJS (Beta) allow more interaction with graph ( tooltips and png/jpg export of graphs)

ChartJS

Basic Usage

To Use, make sure to include the following .js files above your app:

<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js"></script>
<script src="angles.js"></script>

Next, make sure to add "angles" to your Angular app requirements:

var app = angular.module("anglesExample", ["angles"]);

Charts are added using a canvas element with the following syntax, which corresponds to Chart.js. The data and options attributes refer to ng-models in the controller scope. You can name these whatever you want:

<canvas chart="Line" options="options" data="chart" width="500" height="300"></canvas>

Charts can also be added with shorter, aliased types

<canvas barchart options="options" data="chart" width="500" height="300"></canvas>

In your controller, make sure you provide the appropriate data and options per Chart.js documentation:

you can add responsive attribute to enable responsiveness of canvas

<canvas barchart responsive=true options="options" data="chart"></canvas>

the legend attribute auto generate a legend after canvas container

<canvas barchart legend=true options="options" data="chart"></canvas>

The template for this legend is a legendTemplate in the chart options

$scope.chart = {
    labels : ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
    datasets : [
        {
        	fillColor : "rgba(151,187,205,0)",
        	strokeColor : "#e67e22",
        	pointColor : "rgba(151,187,205,0)",
        	pointStrokeColor : "#e67e22",
        	data : [4, 3, 5, 4, 6]
        },
        {
        	fillColor : "rgba(151,187,205,0)",
        	strokeColor : "#f1c40f",
        	pointColor : "rgba(151,187,205,0)",
        	pointStrokeColor : "#f1c40f",
        	data : [8, 3, 2, 5, 4]
        }
    ], 
};

That's it. You can change the values of the chart just as you would with any other angular model.

Directives

linechart

For Chart.js Line Charts

<canvas linechart options="options" data="chart" width="300" height="300"></canvas>
OR
<canvas chart="Line" options="options" data="chart" width="300" height="300"></canvas>

barchart

For Chart.js Bar Charts

<canvas barchart options="options" data="chart" width="300" height="300"></canvas>
OR
<canvas chart="Bar" options="options" data="chart" width="300" height="300"></canvas>

radarchart

For Chart.js Radar Charts

<canvas radarchart options="options" data="chart" width="300" height="300"></canvas>
OR
<canvas chart="Radar" options="options" data="chart" width="300" height="300"></canvas>

polarchart

For Chart.js Polar Charts

<canvas polarchart options="options" data="chart" width="300" height="300"></canvas>
OR
<canvas chart="PolarArea" options="options" data="chart" width="300" height="300"></canvas>

piechart

For Chart.js Pie Charts

<canvas piechart options="options" data="chart" width="300" height="300"></canvas>
OR
<canvas charte="Pie" options="options" data="chart" width="300" height="300"></canvas>

doughnutchart

For Chart.js Doughnut Charts

<canvas doughnutchart options="options" data="chart" width="300" height="300"></canvas>
OR
<canvas chart="Doughnut" options="options" data="chart" width="300" height="300"></canvas>

Options and Data

You can provide options and data to all charts via the options and data attributes on the canvas elements.

<body ng-app="app">

    <div ng-controller="MainCtrl">
    
        <canvas donutchart options="myChartOptions" data="myChartData" width="300" height="300"></canvas>
    
    </div>


</body>
'use strict';

angular.module('app', ['angles']).controller('MainCtrl', function( $scope ) {

    $scope.myChartData = [
    	{
    		value: 30,
    		color:"#F7464A"
    	},
    	{
    		value : 50,
    		color : "#E2EAE9"
    	},
    	{
    		value : 100,
    		color : "#D4CCC5"
    	},
    	{
    		value : 40,
    		color : "#949FB1"
    	},
    	{
    		value : 120,
    		color : "#4D5360"
    	}
    ];
  
    //Globals
    $scope.myChartOptions = {
        // Boolean - Whether to animate the chart
        animation: true,
    
        // Number - Number of animation steps
        animationSteps: 60,
    
        // String - Animation easing effect
        animationEasing: "easeOutQuart",
    
        // Boolean - If we should show the scale at all
        showScale: true,
    
        // Boolean - If we want to override with a hard coded scale
        scaleOverride: false,
    
        // ** Required if scaleOverride is true **
        // Number - The number of steps in a hard coded scale
        scaleSteps: null,
        // Number - The value jump in the hard coded scale
        scaleStepWidth: null,
        // Number - The scale starting value
        scaleStartValue: null,
    
        // String - Colour of the scale line
        scaleLineColor: "rgba(0,0,0,.1)",
    
        // Number - Pixel width of the scale line
        scaleLineWidth: 1,
    
        // Boolean - Whether to show labels on the scale
        scaleShowLabels: true,
    
        // Interpolated JS string - can access value
        scaleLabel: "<%=value%>",
    
        // Boolean - Whether the scale should stick to integers, not floats even if drawing space is there
        scaleIntegersOnly: true,
    
        // Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
        scaleBeginAtZero: false,
    
        // String - Scale label font declaration for the scale label
        scaleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
    
        // Number - Scale label font size in pixels
        scaleFontSize: 12,
    
        // String - Scale label font weight style
        scaleFontStyle: "normal",
    
        // String - Scale label font colour
        scaleFontColor: "#666",
    
        // Boolean - whether or not the chart should be responsive and resize when the browser does.
        responsive: false,
    
        // Boolean - Determines whether to draw tooltips on the canvas or not
        showTooltips: true,
    
        // Array - Array of string names to attach tooltip events
        tooltipEvents: ["mousemove", "touchstart", "touchmove"],
    
        // String - Tooltip background colour
        tooltipFillColor: "rgba(0,0,0,0.8)",
    
        // String - Tooltip label font declaration for the scale label
        tooltipFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
    
        // Number - Tooltip label font size in pixels
        tooltipFontSize: 14,
    
        // String - Tooltip font weight style
        tooltipFontStyle: "normal",
    
        // String - Tooltip label font colour
        tooltipFontColor: "#fff",
    
        // String - Tooltip title font declaration for the scale label
        tooltipTitleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
    
        // Number - Tooltip title font size in pixels
        tooltipTitleFontSize: 14,
    
        // String - Tooltip title font weight style
        tooltipTitleFontStyle: "bold",
    
        // String - Tooltip title font colour
        tooltipTitleFontColor: "#fff",
    
        // Number - pixel width of padding around tooltip text
        tooltipYPadding: 6,
    
        // Number - pixel width of padding around tooltip text
        tooltipXPadding: 6,
    
        // Number - Size of the caret on the tooltip
        tooltipCaretSize: 8,
    
        // Number - Pixel radius of the tooltip border
        tooltipCornerRadius: 6,
    
        // Number - Pixel offset from point x to tooltip edge
        tooltipXOffset: 10,
    
        // String - Template string for single tooltips
        tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>",
    
        // String - Template string for single tooltips
        multiTooltipTemplate: "<%= value %>",
    
        // Function - Will fire on animation progression.
        onAnimationProgress: function(){},
    
        // Function - Will fire on animation completion.
        onAnimationComplete: function(){}
    };

};

angles's People

Contributors

adam7 avatar albertorico avatar carlcraig avatar designershao avatar diegocstn avatar dmitrytsybin avatar ekampf avatar gonewandering avatar gorangajic avatar jmtt89 avatar koningskristof avatar marcgibbons avatar matiassingers avatar mhdonnelly avatar mikos avatar nateredding avatar ndeverge avatar paul-todd avatar rogeriopvl avatar willmcclellan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angles's Issues

A release would do fine

I went ahead with what I mentioned in #71 and created a tiny library for custom charts that mixes well with angles. I was going to write the bower dependencies to add angles, but it doesn't have a release.
That would rock.

Add new charts?

If the chart is not there already, how can I add a new chart using the directive?

If I simply append the chart html to a container it doesn't work. Any ideas?

No tooltip show up but great graphs!

HI,
I know this should work out of the box but for me it does not.
I have been very happy with the renderings, colors, options etc.
However I would really like to get tooltips working.

Here is My graphs:
image

Add bower support

I tried installing via Bower and got another repo:

github.com/pvledoux/angles.git

Which seems to be an older fork of your project. Perhaps adding your project to the bower registry could be a good idea?

should unbind the 'resize' event

Should unbind the 'resize' event. if not unbind, the window would be binded the 'resize' event twice when we back to the view which contains the angles, and then the browser become unresponsive.

Wrong display with a custom scale when all values are positive

I configured the options like this:
$scope.chartOptions = {
scaleOverride: true,
scaleStartValue: -100,
scaleSteps: 10,
scaleStepWidth: 20
};

When the chart has mixed positive and negative values the chart looks OK,
but when all the values are positive the chart looks like this:
image

the values are:
[
{
"StartDate": "/Date(1433106000000)/",
"EndDate": "/Date(1433192400000)/",
"StartDateFormatted": "1",
"EndDateFormatted": "2",
"Performance": 3.37662337662
},
{
"StartDate": "/Date(1433192400000)/",
"EndDate": "/Date(1433278800000)/",
"StartDateFormatted": "2",
"EndDateFormatted": "3",
"Performance": 6.70125378297
},
{
"StartDate": "/Date(1433278800000)/",
"EndDate": "/Date(1433365200000)/",
"StartDateFormatted": "3",
"EndDateFormatted": "4",
"Performance": 1.0989010989
},
{
"StartDate": "/Date(1433365200000)/",
"EndDate": "/Date(1433451600000)/",
"StartDateFormatted": "4",
"EndDateFormatted": "5",
"Performance": 5.05737356566
},
{
"StartDate": "/Date(1433451600000)/",
"EndDate": "/Date(1433538000000)/",
"StartDateFormatted": "5",
"EndDateFormatted": "6",
"Performance": 0.76335877863
},
{
"StartDate": "/Date(1433538000000)/",
"EndDate": "/Date(1433624400000)/",
"StartDateFormatted": "6",
"EndDateFormatted": "7",
"Performance": 4.50077599586
},
{
"StartDate": "/Date(1433624400000)/",
"EndDate": "/Date(1433710800000)/",
"StartDateFormatted": "7",
"EndDateFormatted": "8",
"Performance": 5.26315789474
},
{
"StartDate": "/Date(1433710800000)/",
"EndDate": "/Date(1433797200000)/",
"StartDateFormatted": "8",
"EndDateFormatted": "9",
"Performance": 0.25839793282
}
]

The values are starting from the bottom of the chart instead of starting from the zero line.

Guidelines to add new charts

I have a couple of custom charts I'd like to use with the wrapper. I think is also easier adding the custom charts to the wrapper than the original Chart.js library.
As seen on #55 and #61, there's a need for guidelines for the community for adding new types of chart and their correspondent directives. @gonewandering, if you have no problem with adding charts to the wrapper, would like to hear what you think about coding styles or anything related. I'd be glad to send PR with some new directives.

Infinite digest loop when calling method in data=""

if I do something like:

<canvas piechart options="pieoptions" data="getPieCss(result_content.ranking_score)" width="54" height="54" class="pie" ng-class="{test:result_content.ranking_score}"></canvas>

with the method being:

scope.getPieCss = function(score){

      if(parseInt(score)>0){
        return [ { value: 100, color: "#423D41" } ];
      }else{
        return [ { value: 100, color: "#e0e1e3" } ];
      }
    };

in an ng-repeat, I am getting an infinite digest loop error for some reason... is that a coding error on my side or a problem with piechart?

Exception when used with late data binding

I am using Angles with a forked version of chartjs (https://github.com/Regaddi/Chart.js). I get the following error when I use it in a late databinding situation:

TypeError: Cannot read property 'labels' of undefined
at calculateDrawingSizes (http://localhost:8081/vendor/nnnick-chartjs/Chart.js:1484:24)
at new Bar (http://localhost:8081/vendor/nnnick-chartjs/Chart.js:1333:3)
at Bar (http://localhost:8081/vendor/nnnick-chartjs/Chart.js:556:10)
at Object. (http://localhost:8081/vendor/angles/angles.js:46:28)
at Object.ng.config.$provide.decorator.$delegate.proto.$watch.applyFunction as fn
at Scope.$get.Scope.$digest (http://localhost:8081/vendor/angular/angular.js:12357:29)
at Scope.ng.config.$provide.decorator.$delegate.proto.$digest (:844:31)
at Scope.$get.Scope.$apply (http://localhost:8081/vendor/angular/angular.js:12622:24)
at Scope.ng.config.$provide.decorator.$delegate.proto.$apply (:855:30)
at done (http://localhost:8081/vendor/angular/angular.js:8234:45)

I think the problem is that the $watch function gets called once before the promise has been resolved. It looks like there might have once been protection against this as there is a comment in the Angles code saying to "if data not defined, exit". However there is no code to exit.

            $scope.$watch("data", function (newVal, oldVal) { 
                // if data not defined, exit
                if ($scope.chart) { type = $scope.chart; }
                ...
            }

The error occurs when 'newVal' is undefined.

No versioning

I'm a newcomer.

I think the project must adopt a versioning.
It's absolutely necessary to know the change-log and to know if our application use the last version of the module.

I'd like to recommand @lgsilver to publish a release with a version number everytime an important bug is fixed.

Thanks

'chartCreated' is undefined error

When data for the chart is not immediately available, e.g. it is coming
from a JSON request, an error is thrown because chartCreated does not
exist on the initial call to $scope.$watch("tooltip"

I will submit a pull request with a fix for this issue

add stacked bar functionality

It would be nice if one could easily create stacked bars as well as the default Chartjs charts.

If you add https://github.com/Regaddi/Chart.StackedBar.js as a dependency to this project and add the stacked bar directives as follows, it works great!

angles.directive('stackedbarchart', function () { return angles.chart('StackedBar'); });
angles.directive('stackedbar', function () { return angles.chart('StackedBar'); });

I can issue a pr that

  • adds stacked bar as a dependency
  • adds the stacked bar directives
  • updates the readme accordingly

This is an excellent wrapper around chartjs and it would be nice to see it incorporate some of the open extensions. I can help!

let me know

Set chart title

Is there a way to set a title to the chart or to a specific axis?

Thanks

Multiline tooltip

Hello,

I Was wondering if there was someone that could explain me how to format the tooltip on multiple lines?
I am using bootstrap grid system and I have two divs that take 6 cols each, and they each have a polar graph with tooltips. However the title is too long (overflowing over the other div) and gets cut.

Any help will be appreciated!

Donutchart bug

Typo in donutchart directive.

should be chart.Doughnut($scope.data, $scope.options); instead of chart.Donut($scope.data, $scope.options);

Bower "Invalid version: 1.0"

Hi,

The version specified in your bower.json is wrong. It is 1.0, it should be 1.0.0.
It gives an error:

There were errors, here's a summary of them:
- angles invalid version: 1.0
An error was caught when reading the bower.json: invalid version: 1.0

Here is some more info: bower/bower#144

Thanx for this nice wrapper.

Alex

An element ID is required.

Sweet directives bro.

But why do you use the id attribute and query for the element where the element is passed into the link function.

var ctx = document.getElementById($attrs.id)
rather than
var ctx = $elem.getContext('2d')

And you dont use the id in the isolation scope right?

Bower package

Any thoughts on making the code into a bower package?

Add the tooltip feature

This is for for me the last big feature angles need to be the perfect tool for charts with angular.

Do you plan to add it ?
I would enjoy trying to contribute on it as i can.

I am always getting this error. Thoughts

Hi,
I have had success using chartJS out of the box and wanted to use with Angular. So I found your directive. Very nice. Unfortunately, I get the following:

TypeError: undefined is not a function
at Object. (http://localhost:8000/app/bower_components/angles.js:49:28)
at Object.applyFunction as fn
Angles.js: line 49 is "chart[type]($scope.data, $scope.options);"

I have followed your options:
-add directive as an attribute
-add $scope.options and $scope.data as your example.
I am not an angular expert nor ChartJS rather I'm learning all of this.
These charts as are to be used to show usage on my player.
https://musicplay.firebaseapp.com/#/metrics

Currently using line-charts from N3 but they have resize issues. So I opted to ChartJS with Angles.

Let me know if this is a known issue. or is there an FAQ.

Thanks,

Jacques

Error: [$compile:nonassign]

Hi

I use code like this

html <canvas chart="Line" data="chart" legend=true width="500" height="300"></canvas>

but its generate error something like this

Error: [$compile:nonassign] http://errors.angularjs.org/1.2.10/$compile/nonassign?p0=undefined&p1=chart at Error (native)

How to fix it? thanks

Using "chart" and "type" attributes in canvas tag causes exception

I'm seeing an issue where using the "type" attribute in a canvas tag to specify chart type seems to cause an exception to be thrown (TypeError: undefined is not a function). For example, doing something like

<canvas chart type="Line" ...></canvas>

rather than

<canvas linechart ...></canvas>

causes an exception to be thrown (at line 62 in angles.js).

...
chartCreated = chart[type]($scope.data, $scope.options);
...

If the type attribute is used to specify the chart type within a canvas tag, the type variable in angles.js appears to be undefined, so the function can't be called. Specifying the chart type in a canvas tag using an aliased type (ex. linechart) seems to work just fine, however.

Not 100% sure if the root of the problem lies within angles itself, or if it's an issue on my end. Just thought I would post my experience here to be safe.

Angles is ignoring my options object

I have this in the controller:

  $scope.chartData = { //omitted for brevity... }

  $scope.chartOptions = {
    animation: false,
    showScale: false
  };

and this in the view:

<canvas linechart legend="true" responsive="true" options="chartOptions" data="chartData"></canvas>

But animations are run, and the scale is shown.
Any hints of what am I doing wrong?

Phonegap compability with the Ionic framework

I'm trying to get Chart.js to work for a phonegap project using the ionic framework (www.ionicframework.com). This framework also uses angular. However I'm getting the following error when using the angles directive:

TypeError: Property 'undefined' of object [object Object] is not a function
    at Object.fn (http://localhost:8000/lib/ionic/js/angles/angles.js:41:28)
    at Scope.$digest (http://localhost:8000/lib/ionic/js/ionic.bundle.js:19300:29)
    at Scope.$apply (http://localhost:8000/lib/ionic/js/ionic.bundle.js:19553:24)
    at done (http://localhost:8000/lib/ionic/js/ionic.bundle.js:15311:45)
    at completeRequest (http://localhost:8000/lib/ionic/js/ionic.bundle.js:15512:7)
    at XMLHttpRequest.xhr.onreadystatechange (http://localhost:8000/lib/ionic/js/ionic.bundle.js:15455:11) 

Any idea what could be causing this?

Directives need to destroy chart when directive is destroyed

We're using ng-view in our application. Navigating to and from a view with a chart and a view without a chart I found two things happening:

  • When moving from chart to non-chart, the non-chart view throws rendering errors when the browser window resizes (Chart js registers an event handler for window resize, and loops through instances to redraw them).
  • The number of instances in Chart.instances increases each time the user navigates to the view containing a chart, it never decreases when user navigates away from the chart view.

The following is needed in the link function:

$scope.$on("$destroy", function(){
    if (chartCreated){
        chartCreated.destroy();
    }
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.