Issues with displaying charts have been reported for generator-angular-fullstack and angular-chart.js

After working with Angular for some time, I decided to give Yeoman and generator-angular-fullstack a try. My main goal was to use angular-chart.js to display a chart in a particular view called poll.html. Surprisingly, everything loaded correctly except for the chart itself. I double-checked the Devtools and saw that all the necessary files like chart.js, angular-chart.js, and angular-chart.css were loading as expected with a status 200. Despite trying to troubleshoot by using sample data, the issue persisted. Here are the steps I took along with relevant code snippets. For the complete source code, visit https://github.com/MichaelLeeHobbs/freeTheVote.

Your help is greatly appreciated!

To get started, I used Daftmonk's generator-angular-fullstack for the project seed. Then, I utilized Bower to install angular-chart.js (with the command: bower install --save angular-chart.js)

In my index.html:

<script src="bower_components/Chart.js/Chart.js"></script>
<script src="bower_components/angular-chart.js/dist/angular-chart.js"></script>

In app.js:

angular.module('freeTheVoteApp', [
 'ngCookies',
 'ngResource',
 'ngSanitize',
 'ngRoute',
 'ui.bootstrap',
 'validation.match',
 'chart.js'
])

In poll.controller.js:

angular.module('freeTheVoteApp')
.controller('PollCtrl', function ($scope, $http) {
   var self = this;
   this.polls = [];

   $http.get('/api/polls').then(function(response) {
     self.polls = response.data;
   });

   $scope.options = ['a', 'b', 'c'];
   $scope.votes = ['3', '5', '13'];
});

And finally, in poll.html:

<navbar></navbar>
<div class="mainContent container">
  <div class="row">
    <div class="col-lg-12">
      <div class="col-md-4 col-lg-4 col-sm-6" ng-repeat="aPoll in poll.polls">
        <h3>{{aPoll.name}}</h3>
        <ol>
          <li ng-repeat="options in aPoll.options">{{options}}
            <span> votes: {{aPoll.votes[$index]}}</span>
          </li>
        </ol>
        <canvas id="{{'doughnutChart' + $index}}" class="chart chart-doughtnut" chart-data="votes" chart-labels="options"></canvas>
      </div>
    </div>
  </div>
</div>
<footer></footer>

Answer №1

In order to make the directive element work correctly, it is necessary to use data instead of chart-data, and labels instead of chart-labels

<canvas id="{{'doughnutChart' + $index}}" 
  class="chart chart-doughtnut" 
  data="votes" 
  labels="options">
</canvas>

The data should be organized as a two-dimensional array like this:

$scope.options = [['a', 'b', 'c']];

For more information, check out this Plunkr

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

If the first dropdown menu has a sub-element, then the user should be able to select the same value in the second dropdown menu using jQuery

To trigger an alert, two HTML select option dropdowns must both have the value DIP EDU. My current code successfully accomplishes this, but there is a scenario where some options in the first dropdown may contain sub-elements. For example, selecting MBA wi ...

Create an image of a static map from Google

I have incorporated the Google Static Map API into my Angularjs Application to display images of Google maps. Browse here for a glimpse Everything operates smoothly when there are fewer map coordinates. However, when I increase the number of map coordina ...

Storing information in a loop using AngularJS's ng-repeat functionality

I have a language table, a table with custom tablenames, and a table with translations. My goal is to insert a new table in all languages. In my Controller, I am calculating the number of elements in my language table and then generating the view: var co ...

Error Encountered in Visual Studio Code: TypeScript - tsconfig.json and packages.json Schemas Not Loading

Currently, I am working on an Angular front end using Visual Studio Code for an application with a C# windows service back end. After focusing on the back end for a few days without touching the front end, I realized that Visual Studio Code was no longer a ...

Exploring the Wonders of React Memo

I recently started delving into the world of React. One interesting observation I've made is that when interacting with componentized buttons, clicking on one button triggers a re-render of all button components, as well as the parent component. impo ...

playing with JSON data in angular

Currently, I am utilizing AngularJS and making use of $http.get to fetch a JSON response which I then assign to $scope.myObjects. After implementing ng-repeat="object in myObjects" in the HTML, everything seems to be functioning properly. My query pertai ...

Guide on implementing hover effects in React components

Within my component SecondTest, I have defined an object called useStyle which sets the background color to red. Is it feasible to add a hover effect to this object? const useStyle = { backgroundColor: "red", }; function SecondTest() { return < ...

Can you provide some insight on how to store XMLHttpRequest response in Javascript for future

I have a function in my codebase that is responsible for loading HTML templates asynchronously: loadTemplate: function(url) { return new Promise(function(resolve, reject) { var xhr = new XMLHttpRequest(); xhr.open("GET" ...

Non-negotiable, non-deletable component of a text field

My goal is to create a textarea with a default value that cannot be removed by the user, but they should be able to add extra text after it. <textarea>This is constant</textarea> As shown above, the textarea has a default value. How can I ...

Showing information from a JSON file in a layout

Hey there! I could really use some assistance in displaying my data. So, I've got this custom provider that calls my API, and everything is running smoothly. Currently, I'm focusing on the page titled 'playing', and here's a glim ...

Ensuring the correct range with HTML TextBoxFor

Is there a way to validate user input in a TextBoxFor to ensure it is less than a certain number at run-time? Here is the current code snippet for reference - <div class="col-md-3 input-group"> <span class="input-group-addon ...

Improving the Roman Numeral Kata with JavaScript

As a newcomer to the world of coding, I have taken on the challenge of mastering the Roman Numeral Kata using Javascript. I am pleased to report that all the specifications are passing successfully. After refactoring the spec file, I am now focusing on re ...

Revamp local route variables in Express.js without the need for a page refresh

Currently, I am working on a project using node.js along with the express.js framework and EJS for template handling. Below is my routing code: app.get('/',function(req,res) { res.render('index', { matches: [], status_messag ...

Obtain the OAuth redirect code from the POST data on my Angular webpage

As a newcomer to AngularJS, I am facing an issue that has been persistent for hours despite my attempts to resolve it. Previously, I successfully developed a web application that connected with Google using OAuth 2.0 to retrieve Analytics data. However, af ...

Creating a Duplicate of an iframe with jQuery

Hey there, I have a dilemma with two divs. One is for displaying content, and the other is a video player that I want to pause and resume on scroll using jQuery. My goal is to pause the video in the "myplayer" div on scroll and have it resume playing from ...

jQuery show/hide function malfunctioning

Currently, I am attempting to create a basic show/hide interaction for a div using jQuery. The goal is to make the artists-home div vanish and be replaced by the .ken-gallery when the .artist-ken is clicked. Here is my current code, although it is not fun ...

The Rails application is loading JavaScript three times

I am encountering an issue with my ajax function where it is being triggered multiple times upon click instead of just once. $(document).on('click', '.newGameItem', function() { console.log('start click event'); var a ...

Clickable link that directs to a particular tab on a webpage (cbpFWTabs)

I have been utilizing tabs from the codrops Tab Styles Inspiration and I am looking for a way to open specific tabs using URLs. For instance, if I wanted to open tab3, I could link it as www.google.com/index#tab3. Below is the code I am currently using: ...

Navigating through hashed URLs with a Flexslider component

I have a website under construction that utilizes a flexslider, and I am looking to incorporate URL hash navigation. My goal is to extract the slide index based on the URL hash. I have examined the code for manual navigation where the index of the clicked ...

Utilizing Sails.js: Invoking a YouTube service through a controller

I am facing an issue while trying to integrate Youtube Data API with Node.js in Sails.js. The problem lies with the "fs.readFile" function. Upon launching the service, it returns "undefined". Below is the code snippet for YoutubeService : module.exports ...