Giter Club home page Giter Club logo

tc-angular-chartjs's Introduction

tc-angular-chartjs

AngularJS directives for Chart.js

Build Status

Installation

Ensure you have installed Chart.js

npm

npm install tc-angular-chartjs --save

bower

Bower support has been dropped but you can still use tc-angular-chartjs with Bower using bower-npm-resolver.

download

You can download the source archive from the github releases page.

Just include dist/tc-angular-chartjs.js into your project.

Basic Usage

Add tc.chartjs to your modules dependencies e.g.

angular.module( 'app', ['tc.chartjs']);

You will then have access to the following directives:

  • tc-chartjs
  • tc-chartjs-line
  • tc-chartjs-bar
  • tc-chartjs-horizontalbar
  • tc-chartjs-radar
  • tc-chartjs-polararea
  • tc-chartjs-pie
  • tc-chartjs-doughnut
  • tc-chartjs-bubble

Just place one of these directives on a canvas element to create a Chart.js chart.

You will also want to give the chart some data, options and plugins. These can be provided via the chart-options, chart-data and chart-plugins attributes.

For data structures, options and inline plugins please refer to Chart.js documentation

You can also handle chart clicks via the chart-click attribute.

Example Pie Chart

<canvas
  tc-chartjs-pie
  chart-data="myData"
  chart-options="myOptions"
  chart-plugins="myPlugins"
  chart-click="onChartClick(event)"
></canvas>
$scope.myData = {
  // Chart.js data structure goes here
  // e.g. Pie Chart Data Structure http://www.chartjs.org/docs/#doughnut-pie-chart-data-structure
  labels: [
    "Red",
    "Blue",
    "Yellow"
  ],
  datasets: [
    {
      data: [300, 50, 100],
      backgroundColor: [
        "#FF6384",
        "#36A2EB",
        "#FFCE56"
      ],
      hoverBackgroundColor: [
        "#FF6384",
        "#36A2EB",
        "#FFCE56"
      ]
    }
  ]
};

$scope.myOptions =  {
  // Chart.js options go here
  // e.g. Pie Chart Options http://www.chartjs.org/docs/#doughnut-pie-chart-chart-options
};

$scope.myPlugins = [{
  // Chart.js inline plugins go here
  // e.g. http://www.chartjs.org/docs/latest/developers/plugins.html#using-plugins
}];

$scope.onChartClick = function (event) {
  console.log(event);
};

For more examples please view the demo folder.

Using the tc-chartjs directive

When using the tc-chartjs directive you will need to add an additional attribute to say which type of chart should be created.

Just attach a chart-type="" attribute to the canvas element.

<canvas
  tc-chartjs
  chart-type="doughnut"
  chart-data="myData"
  chart-options="myOptions"
></canvas>

Available Types:

  • line
  • bar
  • horizontalbar
  • radar
  • polararea
  • pie
  • doughnut
  • bubble

Passing another value to chart-type than the above will try to create a chart of that type, which is useful if you have extended Chart.js with custom chart types, e.g. through plugins.

Developing

This library is built using gulp so ensure you have it installed.

To build the dist files run the following:

npm run build

To run the tests:

npm test

To watch files and rebuild dist when changes are made:

npm start

Contributing

  • Open a Pull Request (PR)
  • Make sure your PR is on a new branch you created from the latest version of master branch
  • Please do not open a PR from your master branch
  • Open a PR even if your code is incomplete to start a discussion and to collect feedback
  • Please make sure all unit tests pass, and add new tests for any added features.

License

tc-angular-chartjs is dual licensed with the Apache-2.0 or MIT license.

See LICENSE-APACHE-2.0 and LICENSE-MIT for more details.

tc-angular-chartjs's People

Contributors

abarinoff avatar bostrom avatar carlcraig avatar cstefanache avatar danada avatar eiriksm avatar larsgk avatar lookfirst avatar polyglotm avatar ruicrsilva avatar seanhealy avatar vishnukarthikl 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

tc-angular-chartjs's Issues

Chart does not show - Failed to execute 'arc' on 'CanvasRenderingContext2D'

If the dataset is changed on a doughnut chart with the responsive option set to true, an Uncaught IndexSizeError occurs when the container is resized (when resize() is called in Chart.js).

There is an issue open on the Chart.js repo: chartjs/Chart.js#592

However, the issue above states the problem happens upon resizing the initial chart. I am not experiencing the issue on the initial draw, but on subsequent chart creations. Should be able to post a sample soon, just wondering if there are any obvious answers before I get too deep into this one.

Dynamic update of graph

Is it possible to update the data dynamically without re-rendering the whole graph from scratch?

Field main in bower.js

Hi,

The file bower.json[1] has a attribute 'main' with a array with two files, but is the normal and minify version.

Maybe is necessary choose one. In projects created by angular-generator with Yeoman. When I execute grunt serve add both in my index.html:

 <script src="bower_components/tc-angular-chartjs/dist/tc-angular-chartjs.js"></script>
 <script src="bower_components/tc-angular-chartjs/dist/tc-angular-chartjs.min.js"></script>

[1] https://github.com/carlcraig/tc-angular-chartjs/blob/master/bower.json#L7

Chart re render makes the canvas blurred

Whenever the underlying data of the chart changes, and after the re render, the chart looks a bit blurred.
screen shot 2015-05-11 at 10 00 18 am
screen shot 2015-05-11 at 10 00 52 am

The crisp text is gone in the subsequent re renders.

Legends do not work

Hello, i try to use your component but the legend dont work, have a erro in console..
this error :
console
and this:
console-linha

It's a problem in component? or some conflict in my project only?

How to show legend?

I cannot show legend. What option should I insert?

This are my options:

$scope.options =  {
    showTooltips: true,
    tooltipEvents: ["mousemove", "touchstart", "touchmove"],
  segmentShowStroke : true,
  segmentStrokeColor : '#fff',
  segmentStrokeWidth : 24,
  percentageInnerCutout : 50,
  animation : true,
  animationSteps : 10,
  animateRotate : true,
  animateScale : false,
  onAnimationComplete : null,

pointDotRadius : 4,

//Number - Pixel width of point dot stroke
pointDotStrokeWidth : 1,

//Number - amount extra to add to the radius to cater for hit detection outside the drawn point
pointHitDetectionRadius : 20,

//Boolean - Whether to show a stroke for datasets
datasetStroke : true,

//Number - Pixel width of dataset stroke
datasetStrokeWidth : 2,

//Boolean - Whether to fill the dataset with a colour
datasetFill : true,

//String - A legend template
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].lineColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"


};

Chart Appears only on hover

Chart doesn't appear at the loading of the page. It appears only on hover.
I'm using "Chart.js": "^2.1.3" and
"tc-angular-chartjs": "^1.0.15"

Rotation

Can i show tc-angular-bar-chart as horizontal?

ReferenceError: Chart is not defined

I have included Chart.js and I still see the error Chart is not defined for some reason.

module.exports =
  angular.module('mymodule', ['tc.chartjs'
  ])

my view

<canvas tc-chartjs-pie chart-options="options" chart-data="data" auto-legend></canvas>

Pie and Doughnut chart specific click

Is there a way to impement on click on a single part of the graph?
I mean... can i open an alert by clicking on the green part and an url by clicking on the red one?

thanks
selezione_034

Some questions about the chart

I'd like to know if there is a way to zoom after i click on a part of the chart. I mean... as you see here i have a chart-line. I'd like to click on the red circle (day n°4) and it has to zoom in and show me 3 days before day n°4 and 3 days after. It has to zoom on click. The same thing must work on the other days.
Is there a way to do that? thanks :)
screenshot

The other thing i've noticed is that if you reload the page with the canvas display none, the graph won't show up even if you toggle dislplay none from the style. It shows only the legend. So i must reload the page to see the graph and there's no way to hide it on reload page. I must show it only when i click on a certain button.

Can you please give me some information about these things? Thanks again. :D

Show/Hide chart axis labels

Is there a way to show/hide the axis labels (line chart block chart ..) on mouse event ? or at least paint them white so that they won't be visible ?

Can't change the size of charts

I have a chart markup like this, where i set the width and height:
div class="col-md-8">
canvas tc-chartjs-bar width="600" height="400" chart-options="options" chart-data="data" auto-legend>/canvas>
/div>
However, when rendered, it changes the size to something completely different:
canvas class="ng-isolate-scope" auto-legend="" chart-data="data" chart-options="options" height="739" width="1109" tc-chartjs-bar="" style="width: 1109px; height: 739px;">/canvas>

If i remove the $scope.options, however, it renders fine, like this:
canvas class="ng-isolate-scope" auto-legend="" chart-data="data" chart-options="options" height="400" width="600" tc-chartjs-bar="" style="width: 600px; height: 400px;">/canvas>

My $scope.options:
$scope.options = {
responsive: true,
scaleBeginAtZero : true,
scaleShowGridLines : true,
scaleGridLineColor : "rgba(0,0,0,.05)",
scaleGridLineWidth : 1,
barShowStroke : true,
barStrokeWidth : 2,
barValueSpacing : 5,
barDatasetSpacing : 1,
legendTemplate : "..."

Do you know what might be the cause of this?

WTF??

agario.core.js:7 exception thrown: IndexSizeError: Failed to execute 'arc' on 'CanvasRenderingContext2D': The radius provided (-6907) is negative.,Error: Failed to execute 'arc' on 'CanvasRenderingContext2D': The radius provided (-6907) is negative.
WATTT????!!

TypeError: Cannot read property 'generateLegend' of undefined

I am retrieving data to display within a chart from a web service. If I use the auto-legend attribute to turn on the legend, I get the following JavaScript error:

TypeError: Cannot read property 'generateLegend' of undefined

The chart and legend update appropriately once data is retrieved; if I use hardcoded data, this error is not thrown.

Hacking around:
I've verified the error isn't thrown (and things continue to work as far as I can tell) if I verify the chartObj exists prior to accessing; basically, wrapping lines 95 & 96.

if (chartObj) {
    angular.element($elem[0]).after(chartObj.generateLegend());
    legendElem = angular.element($elem[0]).next();
}

I'm not sure if there are more elegant approaches to resolve.?.?

grunt build error

Hi,

when I try to use grunt for some tasks I get the following error:

Warning: Unable to read "dist/client/bower_components/Chart.js" file (Error code: EISDIR). Use --force to continue.

AND:

Running "usemin:js" (usemin) task

Processing as JS - dist/client/app/b1767f47.vendor.js
Update the JS to reference our revved images

Processing as JS - dist/client/app/d2b1e490.app.js
Update the JS to reference our revved images

Processing as JS - dist/client/bower_components/Chart.js
Warning: EISDIR, illegal operation on a directory Used --force, continuing.

The "Chart.js" seems to be the problem, as a dot is bad practice to include in directory names

I have another issue open in angular-fullstack-generator: angular-fullstack/generator-angular-fullstack#898

Are global chart options available?

Hi, hopefully this isn't a severely dim-witted question but are global chart configs available? I was thinking maybe it was rolled into 'chart-options' but things like 'tooltipTemplate' don't seem to work. I've successfully used 'legendTemplate' from the individual chart options but cannot get the global settings correctly configured.

Thank you for reading,
G

How to combine two differents types of charts

There are any possible to create a barchart combined with line chart?¿. Is very hard to find a free library for commercial use.

If not, anyone know any jquery/angularjs directive/javascript lib to do that?

Performance

This may not be the correct place to ask this question. But before I consider implementing this module and ChartJs I am just curious how the performance is for large datasets?

Dynamic height?

Hi, In a previous correspondence, you helped me understand how to incorporate a new graph plugin using the tc-chart-type. That works superbly --> I am using HorizontalBar with tc-charts.

I wonder if you can help me with another situation - have you added any directive/wrapper that can help scale the height of the chart?

The predicament I am facing is this: If I have 30 bars, everything gets scrunched up. I'd like to specify a minimum bar height, say 40px. The graph should not reduce this height. If it needs to, it should overflow and add a vertical scroll bar. I've been tinkering with wrapping the canvas like so:

<div style="overflow:scroll;">
                        <canvas tc-chartjs chart-type="HorizontalBar" chart-data="data" chart-options="options" width="90%">
                        </canvas>
                    </div>

But this makes the canvas always overflow even when I have 2 or 3 bars - it makes the bar height too big. So I am not sure I can solve this with overflows - hence the thought about bar height

Tooltip

Is there a way to customize the tooltip? I mean adding some css to it..

Usage inside ng-repeat?

How do you use this inside a repeater?
I've tried both

<div class="panel chart-box" ng-repeat="chart in stats.charts">
    <canvas tc-chartjs-line chart-options="chartoptions" chart-data="chart.data" auto-legend></canvas>
</div>

as

<div class="panel chart-box" ng-repeat="chart in stats.charts" ng-init="chartdata=chart.data">
    <canvas tc-chartjs-line chart-options="chartoptions" chart-data="chartdata" auto-legend></canvas>
</div>

but in all cases, no charts are shown (debugging shows that there is no data).
Am I doing something wrong or is this not possible?

problem getting chartjs object in controller

based on issue #6 i added chart attribute to my canvas:

<canvas tc-chartjs chart-type="line" 
          chart-data="stream.chart.data" 
          chart-options="stream.chart.config" 
          chart="myChart"></canvas>

and in my controller wanted to access chartjs object:

...
$scope.myChart = null;
$scope.onButtonClicked = function () {
      console.log($scope.myChart);
};
...

but when onButtonClicked function executed, $scope.myChart is still null and I cant access to chartjs object in my controller.

Incorrect usage of ng-annotate

Howdy,

It looks like there was a recent update that implemented ng-annotate in the build process. Unfortunately, with it's current configuration, it's breaking my apps build process (which runs a concatenated file through ng-annotate). Although that's clearly a sign that I should fix that part of my build process, I'm sure fixing this would help others as well :).

The specific issue can be seen here: https://github.com/carlcraig/tc-angular-chartjs/blob/master/src/tc-angular-chartjs.js#L20.

Lines 20-26 explicitly define the "$inject" property of each directive/factory, but that's unnecessary as ng-annotate already handles this. Due to that, every "$inject" property ends up duplicated in dist/tc-angular-chartjs.js.

If you were to run the dist file through ng-annotate again, you'd get the following error:

error: conflicting inject arrays

The simple fix is to remove lines 20-26 from src/tc-angular-chartjs.js.

Nothing but PIE works

Hi, hope you Ok

Im having this weird issue with the lib, i cant make any chart to work but PIE one, this is my example

/Using jade/
canvas(tc-chartjs-doughnut chart-options="vm.options" chart-data="vm.data")

it just goes and render a pie chart, same with line, bar .. and whatnot

is dat a bug or am i doing something wrong?

ill post my controller as well

/Ctrl/

(function() {
'use strict';

angular
    .module('4kidz')
    .controller('Reports', Reports);

    Reports.$inject = ['$rootScope'];

    function Reports($rootScope) {

        var vm = this;

        vm.data = [
      {
        value: 300,
        color:'#F7464A',
        highlight: '#FF5A5E',
        label: 'Red'
      },
      {
        value: 50,
        color: '#46BFBD',
        highlight: '#5AD3D1',
        label: 'Green'
      },
      {
        value: 100,
        color: '#FDB45C',
        highlight: '#FFC870',
        label: 'Yellow'
      }
    ];

    // Chart.js Options
    vm.options =  {

      // Sets the chart to be responsive
      responsive: true,

      //Boolean - Whether we should show a stroke on each segment
      segmentShowStroke : true,

      //String - The colour of each segment stroke
      segmentStrokeColor : '#fff',

      //Number - The width of each segment stroke
      segmentStrokeWidth : 2,

      //Number - The percentage of the chart that we cut out of the middle
      percentageInnerCutout : 0, // This is 0 for Pie charts

      //Number - Amount of animation steps
      animationSteps : 100,

      //String - Animation easing effect
      animationEasing : 'easeOutBounce',

      //Boolean - Whether we animate the rotation of the Doughnut
      animateRotate : true,

      //Boolean - Whether we animate scaling the Doughnut from the centre
      animateScale : false,

      //String - A legend template
      legendTemplate : ''

    };

    }

})();

Multi-coloured Bars?

Anyway to achieve multi-coloured bars (within each dataset)? I see there are forks of ChartJS that do this. EG:

fillColor : ["green","red","yellow","blue"],
strokeColor : ["green","red","yellow","blue"]

...But they don't seem to play well with this Angular directive.

Any guidance would be really appreciated.

Dynamic chart data updates

We need to build a way to update the chart incrementally without re-rendering the whole chart.

This is based of the discussion in #6

Graphs too wide in Bootstrap

When I place a line chart inside a bootstrap panel body, the graph is 30 pixels too wide. It seems that the width calculation doesn't account for padding in the parent container (15px left, 15px right).
This hack fixes it for me:

canvas {
    padding-right: 30px;
}

This is the html:

<div class="row">
    <div class="col-md-6">
        <div class="panel panel-default">
            <div class="panel-body">
                <canvas tc-chartjs chart-type="line" chart-data="data" chart-options="myOptions" auto-legend></canvas>
            </div>
        </div>
    </div>
</div>

How to add Custom legends ?

I would like to show values along with labels in the pie and doughnut chart legends. Please tell how to do that. How to add custom legends in tc-angular-chartjs. I have seen the documentation but could not understand. Please Help.

chart-doughnut inside ng-repeat

Hi everybody,

I'm trying to show multiple charts inside of ng-repeat. I don't know what I'm doing worng, but It is not showing any charts.

<div class = "box-body" id = "{{'criterion_'+ $index}}">
    {{criterion.data}}
<canvas id = "{{'doughnut_'+ $index}}" class="chart chart-doughnut" data = "criterion.data" labels="labels" colours= "colours">
</canvas> 
</div>

criterion.data shows the correct data.

Thank you!!

Showing data values

How do I display the the values in a Doughnut Chart? I want them to be shown permanently and not only on hover.

ng-show ng-hide not working properly

I have a div which encloses a chart which has ng-show property on it.

<button ng-click="showGraph=!showGraph" ng-init="showGraph=false">toggle</button>
<div ng-show="showGraph">
  <canvas tc-chartjs-bar chart-data="data"></canvas>
</div>

But when showGraph property is changed to true, the div becomes visible but the graph is not rendered. But where as if ng-init="showGraph=true" is set then the chart is rendered properly first and the subsequent toggle work fine. I also checked the same for pie chart and ng-show/hide is working fine.

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.