Exploring the world of color in Google visualization charts

I am currently working on a project that requires me to add different colors to specific zones on a graph. I am looking to use colors such as blue, red, yellow, and green.

Here is the outcome I have achieved: https://i.sstatic.net/0AdC7.jpg

I am aiming for something similar to this design:

https://i.sstatic.net/FN8II.jpg This is the code I have used

google.charts.load('current', { 'packages': ['bar'] });
google.charts.setOnLoadCallback(drawStuff);

function drawStuff() {
    var data = google.visualization.arrayToDataTable([
        ['Week', 'Zone 0 - 60%', 'Zone 60 - 70%', 'Zone 70 - 80%', 'Zone 80 - 90%', 'Zone 90% +'],
        ['W45', 10, 24, 20, 32, 18],
        ['W46', 16, 22, 23, 30, 16],
        ['W47', 28, 19, 29, 30, 12],
        ['W48', 26, 25, 23, 10, 16],
        ['W49', 28, 19, 29, 40, 12],
        ['W50', 16, 22, 23, 30, 16],
        ['W60', 28, 19, 29, 30, 12],
        ['W61', 26, 25, 23, 10, 16],
        ['W62', 28, 19, 29, 40, 12],
        ['W63', 16, 22, 23, 30, 16],
        ['W64', 28, 19, 29, 30, 12],
        ['W65', 26, 25, 23, 10, 16],
        ['W66', 28, 19, 29, 40, 12],
        ['W67', 28, 19, 29, 30, 12],
        ['W68', 26, 25, 23, 10, 16],
        ['W69', 28, 19, 29, 40, 12],
        ['W70', 16, 22, 23, 30, 16],
        ['W71', 28, 19, 29, 30, 12],
        ['W72', 26, 25, 23, 10, 16],
        ['W73', 28, 19, 29, 40, 12]
    ]);

    var options = {
        width: '100%',
        height: '100%',
        chartArea: {
            width: '90%',
            height: '80%',
        },
        bar: { groupWidth: '75%' },
        isStacked: true
    };

    var chart = new google.charts.Bar(document.getElementById('top_x_div'));
    // Convert the Classic options to Material options.
    chart.draw(data, google.charts.Bar.convertOptions(options));

Answer №1

opt for a traditional chart rather than the modern one

traditional --> packages: ['corechart'] + google.visualization.ColumnChart

modern --> packages: ['bar'] + google.charts.Bar

modern charts have limited styling options
check out options not available in modern --> Tracking Issue for Modern Chart Feature Parity

there's an option to style a traditional chart similar to modern

theme: 'modern'

look at the working example below...

google.charts.load('current', {
  callback: drawStuff,
  packages: ['corechart']
});

function drawStuff() {
  var data = google.visualization.arrayToDataTable([
      ['Week', 'Zone 0 - 60%', 'Zone 60 - 70%', 'Zone 70 - 80%', 'Zone 80 - 90%', 'Zone 90% +'],
      ['W45', 10, 24, 20, 32, 18],
      ['W46', 16, 22, 23, 30, 16],
      ['W47', 28, 19, 29, 30, 12],
      ['W48', 26, 25, 23, 10, 16],
      ['W49', 28, 19, 29, 40, 12],
      ['W50', 16, 22, 23, 30, 16],
      // more data...
  ]);

  var options = {
      width: '100%',
      height: '100%',
      chartArea: {
          width: '90%',
          height: '80%',
          top: 48
    },
      bar: { groupWidth: '75%' },
      isStacked: true,
      theme: 'modern',
      legend: {
          maxLines: 2,
          position: 'top'
    }
  };

  var chart = new google.visualization.ColumnChart(document.getElementById('top_x_div'));
  chart.draw(data, options);
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="top_x_div"></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

Enhance your dynamic content with jQuery/AJAX through customized CSS styling

Below is the jquery (3.1.1)/ajax request that I am using: $.ajax({ type: "POST", url: "pref.php", dataType: "text", data: { groupe_id: groupe_id, action: "getProducts" }, cache: false, error: function(html){ ...

Removing Access Package Assignment in Microsoft Graph

Using the Microsoft Graph API Beta version, I am attempting to delete an access package. However, in order to do so, I must first remove all assignments associated with it. As per the official documentation, I came across the accessPackageAssignment object ...

Updating Variable Values in PHP

Currently, I am working on a project about online shopping using PHP. However, I have encountered an issue regarding changing the currency value. I need to convert the currency to another based on the exchange rate provided. <select onchange=""> ...

Tips for successfully sending data to an ng-include controller

So, I've got this ng-include html element, and I'm trying to figure out how to pass data from an external source to the controller. The primary controller is responsible for fetching json data from a http webservice, and then parsing that data i ...

Cease the firing of ion-change until the values have been successfully loaded from storage

My settings page contains multiple ion-toggle's. There's an onChange method to update local storage when toggled. Standard procedure involves checking existing values in storage on page load and mapping them to the toggles using ngModel. <tab ...

Toggle the visibility of text boxes based on the checkbox selection

After doing some research, I decided to revise the question after receiving feedback that it was causing some concern. When a checkbox is clicked, the content of the corresponding div should be visible and vice versa. How can I achieve this? Thank you. JQ ...

Loop through each div using jQuery and dynamically add or remove a class to

I am looking to create an infinite loop that adds a class to each div with a timeout in between. Currently, I have implemented it like this: $(document).ready(function() { $('.small-bordered-box').each(function(i) { var $t = $(this); ...

Unable to remove data once it exceeds 10 entries while using AJAX, jQuery, and JavaScript/PHP

I am having an issue where I can insert data into the first 10 rows and delete any of them successfully. However, when I try to insert data starting from the 11th row, I am unable to delete any rows past the 10th. UPDATE: The deletion function does not wo ...

Can you please provide the Jquery alternative to this?

Can you provide a sleek jQuery solution for this problem? $('A').append(str); ...

Utilizing a single controller for both modal and non-modal forms in Angular UI Bootstrap: A guide

I am dealing with a registration form that is currently displayed within a modal. I would like the same form to be shown at the bottom of the landing page instead of in a modal. When attempting to move the controller responsible for the registration modal ...

Issue with displaying cocoa pod chart in Swift4

I am facing an issue with my bar graph as it is not displaying any bars. Even though I have imported the charts cocoa pod successfully and there are no run time errors, only the description label is being shown in the graph. import UIKit import Charts ...

"In Vim, learning how to create block comments is an essential skill to

I am seeking a way to streamline the process of generating block comments for documentation in vim. For example: /** * comment */ Are there any available plugins that can assist with this task? ...

Locate all buttons on the page that have an onclick function attached to them, and

I seem to have run into an issue. I am currently working with Java and WebDriver. My goal is to navigate to , locate the item "ipod", receive 4 results, and then compare them by clicking on the "compare" button beneath each item. However, I am encounteri ...

Adjusting the inner div dimensions to be 100% of the body's size without relying on the parent div using JavaScript

I have a main layer with multiple layers stacked on top of it. I need the second layer to extend its width to match the body's width. Main Project: http://example.com What I've tried: I looked into: Solution for matching div width with body ...

Guide for using two Async Pipe functions in Angular 7

Two different functions are in place to check a specific condition, and the requirement is for both of them to be true simultaneously. How can *ngIf be utilized to achieve this? Currently, setting just one of them works, but the aim is to have both. HTML ...

Accessing both a controller and state parameter values in an Angular template using UI-Router: How is it done?

After trying out the suggestions and examples provided in these references (Angular UI-Router testing scope inheritance, Angular ui-router - how to access parameters in nested, named view, passed from the parent template?), I implemented the following code ...

Search through an array of objects that contains nested arrays of objects with various property names and values

I have an Array of objects structured like this: [{ property1: 'test', property2: 'test', filter: [{ fil1: 1, fil2: 2, fil3: 3 }, { fil1: 56, fil2: 3, fil3: 34 ...

What is the process for obtaining the source code for children in React?

Can React extract the source code from children props? Imagine having a component with the following structure... <SomeComp> <Heading>I want to access this code inside the Heading tag</Heading> </SomeComp> How can I retrieve t ...

Discover the most concise string within the array

Is there a way to determine the shortest string in a JavaScript array regardless of the number of elements it contains? I attempted using var min = Math.min(arr[0].length,arr[1].length,arr[2].length); to find the shortest string among 3 elements in an ar ...

Using JavaScript to calculate dimensions based on the viewport's width and height

I have been trying to establish a responsive point in my mobile Webview by implementing the following JavaScript code: var w = window.innerWidth-40; var h = window.innerHeight-100; So far, this solution has been working effectively. However, I noticed th ...