Styling Based on Conditions in Angular

Exploring the unique function of conditional formatting in Microsoft Excel, where color bars are utilized to represent percentages in comparison to the highest value.

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

Is there a way to replicate this functionality using HTML5 with CSS or JavaScript? Perhaps incorporating an additional Angular library as well?

I'm considering utilizing clip-path, but I am aware that this feature may not be universally supported across all browsers.

Answer №1

Is this what you're looking for?

In vanillaJS, it's quite simple to achieve. First, you need to select all elements:

const elNodes = document.querySelectorAll('.element');
const elements = [...elNodes];

Next, retrieve their values and determine the maximum value:

const elementsValues = elements.map((el) => parseFloat(el.children[1].textContent));
const maxValue = Math.max(...elementsValues);

Finally, adjust the width of elements based on their values:

elements.forEach((el) => {
    el.children[0].style.width = 100 / (maxValue / parseFloat(el.children[1].textContent)) + '%';
});

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

Refreshing a jsp page without the need to reload the content

On my jsp page, I am displaying the contents of a constantly changing table. This means that users have to refresh the page every time they want to see updated information. Is there a way for me to update the content dynamically without requiring users t ...

recording the results of a Node.js program in PHP using exec

I'm attempting to retrieve the output from my node.js script using PHP exec wrapped within an ajax call. I am able to make the call and receive some feedback, but I can't seem to capture the console.log output in the variable. This is how I exec ...

Are there any reliable PHP classes available to generate HTML tables efficiently?

Searching for an advanced PHP class that can effortlessly create intricate HTML tables, including the ability to handle colspan/rowspan and assign specific CSS classes to rows, columns, and cells. ...

Sort through various table columns

I am currently utilizing a data table component from Framework7, which is being generated dynamically with JSON data. My goal is to make the column filter input functional within the table. So far, I have succeeded in implementing the filter for the first ...

What is the best way to verify the existence of an email address?

I'm currently using the jQuery validation plugin and everything is working fine, but I've hit a snag when it comes to checking email addresses. The issue is that the plugin returns either true or false based on whether the email exists or not. Ho ...

I'm curious about what exactly happens when the NextJS Link component is triggered and how we can effectively capture and respond

As I was developing a simple navbar that uses a JSON data to dynamically generate its links, I encountered the need to visually persist the active link/route. To achieve this, I experimented with two different implementations: Initial approach: In the Me ...

Progress bar for uploading files

Similar Question: Upload Progress Bar in PHP Looking for suggestions on a simple and effective method to implement a file upload progress bar. Interested in a solution that involves both javascript and php. Any recommendations? ...

Implement SSL Encryption for IONIC Mobile Apps or Angular Web Applications

I am just beginning my journey in this field. Currently, I am using the IONIC framework to develop an application. The backends, which include authentication, storage, and a database, are hosted on Firebase. Additionally, I utilize some third-party APIs a ...

Top Choice: Firebase for image storage

As I work on creating my personal photography portfolio with firebase, I find myself unsure about the most efficient and cost-effective way to host the images. Currently, my website is hosted on firebase, and the images are being accessed from a storage b ...

Tips for preventing the nesting of promises when managing errors from various APIs

Currently, I am developing an application that requires making requests to two different APIs. The authentication process is handled by Cognito, while a lambda function communicates with a database. However, the issue I am facing does not seem to be specif ...

"How to ensure a background image fits perfectly on the screen in IE10

I am facing a problem while trying to set the background image in CSS to fit the screen. It works fine with the latest version of Chrome, but there is an issue with IE 10. html { border-top: 10px solid #8A85A5; background: url("http://www.lifeintempe.com/ ...

Alignment of close button in modal for IE7 using Bootstrap

While using Bootstrap 2 modal, I encountered an issue with the close button not being placed correctly in IE7. Given the popularity of this CSS library, I am curious if anyone has found a solution to align it properly in IE7. It seems to be related to floa ...

Finding all the dates within a specified date range in an Ionic 3 application

If I have a starting date of November 30, 2019 and an ending date of December 7, 2019, how can I generate a list of all the dates in between and save them in an array? I am looking to format the array like this: ["2019-11-30", "2019-11-31", "2019-12-1", ...

Creating HTML content using Racket

Is there a straightforward method for converting X-expressions to HTML in Racket without using response/xexpr? It appears that this function is mainly intended for serving http responses, but I only need to convert Racket lists (or X-expressions) into an ...

Automatically generate nested object properties in VueJS for streamlining code structure

Understanding the Issue I have created a custom system to monitor specific "store" properties from a JSON in a NoSQL database. The structure is fairly straightforward, with nested objects that are necessary for various reasons. The data format resembles ...

Guide to sending properties to reducer in React with Redux

I've been grappling with the complexities of react-redux for hours. I'm aiming to display an <Alert /> to the user when the value of isVisible is true. However, I'm still struggling to grasp the architecture of redux. Despite my effort ...

Create and adapt dynamic tiles to fit within the available width

I am looking to create a dynamic tile (div) that adjusts based on the number of users available, similar to how it works in Microsoft Teams meetings. For example, if there is only one user, the div should occupy the full screen. When there are two users ...

Enhance your website with a stylish CSS jQuery menu that lets you toggle, slide

If you're curious about the code, take a look here! Here are some of the issues I'm facing: The div doesn't toggle to hide when clicked on itself, only when another one is clicked. (UPDATE: it actually won't toggle at all) When t ...

When using the <object> tag, it may not always render at 100% height as intended

Application Inquiry I am seeking assistance with a web page that features a title, and a sticky menu bar at the top, allowing the rest of the space for displaying content. When a menu item is clicked, the objective is to load a page in the content at full ...

Securing ASP.NET Core applications with iframe authentication cookies

I seem to be facing an issue with my iframe. Whenever I attempt to login, it appears that my authentication cookie is not functioning correctly as I keep getting redirected back to the login screen. How can I resolve this? The cookie operates normally whe ...