Styling AngularJS Pie Charts

Is it possible to customize the appearance of a pie chart created with angularjs-chart in order to achieve a design similar to this:

https://i.sstatic.net/xYcu9.png

While there are some examples available on the angularjs-chart website, one particular example stands out:https://i.sstatic.net/XXRqb.png

This specific design would suit my requirements perfectly, but I need to adjust the color and make the lines thinner to match the image above.

I attempted to use chart-colors and chart-options. However, the former does not seem to be effective and I am unsure how to utilize the options feature.

Below is the code snippet:

In the controller:

app.controller('DashboardController', function DashboardController ($scope) {
    $scope.labels = ["Download Sales"];
    $scope.data = [100];
});

In HTML:

<canvas id="doughnut" class="chart chart-doughnut"
    chart-data="data" chart-labels="labels">
</canvas> 

However, the resulting chart differs from my expectations:https://i.sstatic.net/KI5r9.png

Answer №1

Initially, ensure that your $scope.data array is set up like this...

$scope.data = [
   [100]
];

To customize the color of a pie or doughnut chart, specify the backgroundColor property with an array of color values in $scope.datasetOverride

$scope.datasetOverride = [{
   backgroundColor: ['#67d2c4']
}];

If you want to adjust the thickness of the line, assign a number to the cutoutPercentage property in $scope.options

$scope.options = {
   cutoutPercentage: 80
}

Don't forget to include the chart-dataset-override directive in your HTML markup.

:: See a demonstration below ::

var app = angular.module('app', ['chart.js']);

app.controller("DashboardController", function($scope) {
   $scope.labels = ["Download Sales"];
   $scope.data = [
      [100]
   ];
   $scope.options = {
      cutoutPercentage: 80 //customize this as needed
   }
   $scope.datasetOverride = [{
      backgroundColor: ['#67d2c4']
   }];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/angular.chartjs/latest/angular-chart.min.js"></script>
<div ng-app="app" ng-controller="DashboardController">
   <canvas class="chart chart-doughnut" chart-data="data" chart-labels="labels" chart-options="options" chart-dataset-override="datasetOverride"></canvas>
</div>

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

Utilize the jQuery function as a callback argument

There is a jQuery plugin that I am currently working on: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head><title></title> <script type="text/javascript" sr ...

Resolve the issue of Dojo images not appearing on a div in Internet Explorer

I am trying to incorporate images into a dojo chart using the given code: var l_images = ["images/clearnight.png","images/clear.png","images/partlyCloudy.png","images/cloudy.png","images/showers.png","images/rain.png","images/thunderstorms.png","images/ic ...

If I do not utilize v-model within computed, then computed will not provide a value

I'm fairly new to coding in JS and Vue.js. I've been attempting to create a dynamic search input feature that filters an array of objects fetched from my API based on user input. The strange issue I'm coming across is that the computed metho ...

Is there a way to display a PHP error message while submitting the form asynchronously?

Utilizing phpMailer in combination with AJAX to send emails. The objective is to send the email and then showcase any error messages from submit.php on contact.php Currently, every submission displays "Message sent" even if it was not actually sent. Con ...

Unlocking the potential of a local mongoDB database in an Angular application without the need for a server - a truly client-side experience with the MAN stack

I have organized a mongoDB database with extensive data stored in multiple collections, all residing in a 'data' folder within the directory of my node app. I am now looking to develop a front-end interface for the database, including CRUD funct ...

Is there a bug in IE9 with CSS precedence?

Two CSS rules are in place: .avo-lime-table th, .avo-lime-table td { background-color: grey; } Next rule: .avo-lime { background-color: green; } All is functioning correctly in FireFox, Chrome, Opera and Safari. However, as usual, Microsoft&apos ...

Tips on utilizing the useState hook for storing numerous key objects?

Currently, I am working with a candlestick chart for a cryptocurrency that displays data over different timeframes such as 1 minute and 30 minutes. Below is the code snippet that sets the initial state to show a 1-hour chart when a user first visits: const ...

Error encountered due to an unhandled promise rejection of type

I am currently using async/await to execute a query to the database and receive the result. However, I encountered an error in the browser console that says: Unhandled promise rejection TypeError: "games is undefined" In my code, there are two function ...

Error: The <Class> cannot be accessed until it has been initialized

I have a basic autoloader method that initializes and returns an instance of a class using require() The require statement includes some logic that requests information from a database and checks if the class exists in the filesystem. let elementClass = r ...

Microsoft Edge and Google Fonts display strong and distinctive lettering

When using Microsoft Edge on Windows 10, all text appears with bold UTF-8 characters: https://i.sstatic.net/JfN0S.png I'm unsure of what the issue is. Is there a solution available? ...

Is there a way to transform data from a CSV format to a JSON format?

I've written the code to fetch data from a device in CSV format. Here are some sample data values: 1,1.635946,1.636609,1.640240,1.636091 2,1.642825,1.640267,1.639013,1.636568 3,1.636835,1.636022,1.637664,1.637144 4,1.641332,1.641166,1.637950,1.640 ...

The Ineffectiveness of the Form Class

I have been trying to personalize the appearance of my bootstrap form by applying my own custom CSS. However, despite creating a class for my form and making changes to its CSS properties, the style of the form remains unchanged. Take a look at my form: ...

Optimal method for showcasing a multitude of columns on an HTML page

Seeking to showcase a vast array of data in HTML (over 10,000 columns with approximately 200-300 rows) to present a schedule. The information will be structured as movable blocks containing text and background colors. Is it feasible to exhibit such a mas ...

Disable the parent CSS styling when focusing on the child button

Within an anchor tag, I have a div element. The CSS on the :active state is set to transform the element, but I want to avoid this behavior when focusing on the child element bx--overflow-menu. I am working with NextJS using styled-jsx and SaSS. Here is my ...

How to Implement Custom Header in AngularJs during Initialization

Let's say I have a delicious Angular application called chococalateApp that relies on 3 other modules: Product, Sales, and LogIn. My app is based on a RESTful API. After a successful login, the server sends an authentication token that needs to be ap ...

Tips on invoking a Stencil component function or method from beyond the Vue instance

Is it possible to trigger a function in a Stencil component from the parent Vue instance? For example, I would like to call the callChild() method in the Vue instance, which will then trigger the doSomething() function in the Stencil component. The main ...

Transforming the data from my Event Viewer into a sleek and functional HTML table

I am working on a command to extract Event Viewer data and display it in a more user-friendly format. My goal is to convert the output to an HTML table and save it to a text file for inclusion in an email report. Here is what I have so far: $endTime = Get- ...

Attempting to incorporate a border underneath the H1 title labeled MY TODO LIST

<html lang="fr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" conte ...

Update button text in real-time using JavaScript

I am currently working on a dropdown list that contains 5 elements displayed inside a button when pressed. I want the button to show a default text "Filter by:" before displaying the selected tab value. Additionally, I need the caret symbol to be visible. ...

The object you are attempting to use does not have the capability to support the property or method called 'after'

When attempting to add a div tag dynamically using javaScript, I encountered an issue with the .after function not working in IE9+. The error message "SCRIPT438:Object doesn't support property or method 'after'" appeared in the console. If a ...