Creating an Angular2 application that dynamically styles a div with two colors based on the ratio percentage of HTML table column values

Hello Kind Helpers. I am relatively new to angular2 and I have a specific requirement where I need to show a two-colored div that represents the ratio-percentage difference between incoming and outgoing call data for different cities. This will be based on the disparity between the values in two columns of an HTML table. The table structure is as follows:

City | Incoming Calls | Outgoing Calls | Ratio In\Out calls

New York | 4500 | 5600 | divs two colored bar- red\blue -- showcasing the percentage difference in inbound and outbound calls for New York with values 4500 and 5600 respectively.

Boston | 8800 | 1200 | divs two colored bar> red\blue depicting the percentage discrepancy in inbound and outbound call figures, being 8800 and 1200 for Boston.

LA | 3400 | 8800 | divs two colored bar> red\blue indicating the percentage difference in incoming and outgoing call numbers (3400 and 8800) for LA.

Seattle | 1200 | 790 | divs two colored bar> red\blue showing the percentage variation in inbound and outbound calls, representing 1200 and 790 for Seattle.

I hope this explanation makes sense...

.two-colour-bar { 
width: 60px; height: 10px; color: #fff; 
background: -webkit-linear-gradient(left, orange, orange 30%, black 70%, black);

The percentages in the gradient above will adjust according to the input values from the table columns such as Incoming and Outgoing calls. For instance, the proportions 30% and 70% would change based on respective values like 4500 and 5600 from incoming and outgoing calls.

City | Incoming Calls | Outgoing Calls | Ratio In\Out calls

New York | 4500 | 5600 |

The aforementioned table is implemented using *ngFor within a table structure in HTML.. –

[sample look][1]

Answer №1

<td>
  <div class="progress-bar">
    <div class="filler" [style.width]="incoming / outgoing + '%'">

    </div>
  </div>
</td>

.progress-bar {
  width: 200px;
  height: 20px;
  background-color: red;
  position: relative;
}

.progress-bar .filler{
  position: absolute;
  width: 50%;
  height: 100%;
  background-color: blue;
}

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

How can a child component trigger an event in its parent component?

Currently, I have tabs implemented with a form and a button in tab1. In the parent component, there is an event that deactivates the current tab and activates the next one. Can anyone advise on how to call this event from the child component? gotosecond ...

Store the position of a draggable object using JQuery into an SQL database

Because of the current crisis, my friends and I are unable to meet up in person. To stay connected, I've come up with a little game for us to play online. Each of us can move an object on my website, and when the page is refreshed, we'll see the ...

React js experiences a crash when it attempts to re-render with a different number of child elements

When working with react.js, I came across the need for a component that renders a 'tr' with either one or two 'td' elements, depending on its property. Here is an example: var Item = React.createClass({ content: function() { ...

JavaScript utilized to create a fully immersive full-screen webpage

I have been trying to implement a code for creating a full-screen website that works on all browsers. Unfortunately, my current code only seems to be functioning properly on Mozilla browser. When I try to view the site in Chrome and make it full screen, it ...

Bootstrap Scrollable Card

Currently, I am working with bootstrap 4 and have set up a layout with 3 columns in a single row. One of the columns contains a list while the other two do not. I am trying to make only the column with the list scrollable without affecting the entire conta ...

Assign a default value to the dropdown select option when the page is loaded

Here is the code I am currently using. My goal is to have "Select the type of document" display when the form first loads. The first option in the select element is set to that text, while the second option is fetching data from my backend. If you want mor ...

Understanding the contrast between viewport and responsive web design is essential in developing a

Can you explain the distinction between using <meta name='viewport'> and implementing Responsive web design with CSS Media Screen? It appears that these two methods serve similar purposes. Even without including <meta name='viewpo ...

Using Ajax to send data from a parent JSP to a child JSP and then refresh the page

Can anyone assist me in resolving my issue? I'm attempting to incorporate an existing JSP partial (child) into another JSP page (parent). These pages are controlled by Java Controller classes in a Weblogic 12c environment using Spring. The child JSP i ...

What's the best location to insert the web.config file within my project structure?

It appears that Azure is not reading the local .json files in my App due to a missing file named web.config. This file should set the MIME type for .json by default so that Azure can locate the files without throwing a 404 error. However, even after adding ...

Converting an array into an object using Typescript and Angular

I have a service that connects to a backend API and receives data in the form of comma-separated lines of text. These lines represent attributes in a TypeScript class I've defined called TopTalker: export class TopTalker { constructor( pu ...

Changing the read-only property of a form input using a button click

I have designed a form with some input fields marked as Readonly along with an icon placed beside each of them. Is there a way to toggle the Readonly property of a specific field when I click on the adjacent icon? Sample Form <div class="input-group"& ...

Tips for personalizing the color scheme of Material UI Stepper Step?

I need help customizing the disabled Step color for Material UI Steppers. The default colors are Blue for enabled steps and Grey for disabled steps, but I want to change it to a different color as shown in this example: https://i.stack.imgur.com/HGGxp.png ...

Vue 3 project experiencing issue with Bootstrap 5 tabs failing to update upon tab click

Currently, I'm in the process of developing a vue3 application with bootstrap 5. As part of this project, I am implementing tabs. Although I can successfully click on the tabs, I have encountered an issue where the tab-content remains fixed on the ini ...

Steps for changing the direction of a dropdown menu to the left instead of the right

I'm having a bit of an issue with my inbox setup. I have a dropdown for it, but the dropdown is appearing off to the right and since it's at the end of my top navbar, it's not very visible. Here is the CSS code for the inbox: .notification ...

Creating a JQuery slider with customizable step sizes

Can the JQuery Slider (range slider / dual slider) be customized to handle non-linear values with inconsistent "step" sizes? I envision a horizontal Slider that looks like this: |----|----|----|----|----|--------|--------|-------------------------|------ ...

What steps can be taken to customize the default keyboard shortcuts functionality in Swiper.js?

I am trying to customize the functionality for left/right keys in Swiper.js but I am unable to find a way to do this through the API () It seems that the API only allows you to disable/enable default actions: mySwiper.keyboard.enabled // Whether th ...

Unusual JavaScript AJAX antics

I have a situation that looks like this: elFinder.prototype.commands.info = function() { this.exec = function(hashes) { var temp_array = new Array(), temp_html = new String(); var request = new XMLHttpRequest(); ...

Adaptive Table Layout that Creates a Page-breaking Design

I have a page layout with three columns: a fixed-width left-hand navigation, a responsive content column, and a fixed-width right-hand navigation. The issue arises when the content in the middle column includes HTML tables that sometimes exceed the availab ...

What is the best way to increment a variable by one when a button image is clicked?

Is there a way to increase a variable by +1 when clicking on an image button? ~John ...

Problem starting Angular 2 project with npm

Upon attempting to execute the command npm start, I encountered an error like this: https://i.sstatic.net/l5qgF.png This is the content of my package.json file:- { "name": "angular-quickstart", "version": "1.0.0", "description": "QuickStart package.jso ...