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:

I am aiming for something similar to this design:

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

Avoiding special characters in URLs

Is there a way to properly escape the & (ampersand) in a URL using jQuery? I have attempted the following methods: .replace("/&/g", "&amp;") .replace("/&/g", "%26") .replace("/&/g", "\&") Unfortunately, none of these are y ...

auto-scrolling webpage as elements come into view

Here is some jQuery code I have: $(".col-md-12").hide(); $(".button-div").hide(); $(".featurette-divider").hide(); $(".footer").hide(); $(".first").fadeIn(1000); $(".second").delay(900).fadeIn(1000); $(".third").delay(1800).fadeIn(1000); $(".fourth").dela ...

Could there be a more efficient method to enable support for all video formats?

I have a case statement in my video validation function that checks for specific file extensions of video formats. However, I am wondering if there is a shorter way to write the code in order to allow all video formats instead of creating a long list of al ...

Adjusting the color of a specific part of a text within a string using

I am trying to update the color of specific keywords within a post. For example: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam tempor lacinia urna eget gravida. Quisque magna nulla, fermentum fermentum od #keyword1 #keyword2 #keyword3 ...

AngularJS: Changing color property using toggle when a CSS class is modified

After starting to learn AngularJS, I have been able to find many helpful answers on this forum. However, there is one particular issue that has been causing me frustration. My goal is to dynamically change the color property of an element only when it has ...

What causes the disparity in the functionality of getServerSideProps between index.js and [id].js in NextJS?

Exploring NextJS and React as part of my e-commerce site development journey has been exciting. However, I encountered a roadblock when trying to connect to an external database that requires real-time updates, making getStaticProps unsuitable for my needs ...

The caret operator in NPM does not automatically install the latest minor version of a package

Within my package.json file, one of the dependencies listed is labeled as... "@packageXXX": "^0.7.0", Upon running the "npm outdated" command, I observed that... @packageXXX current: 0.7.0 wanted: 0.7.0 latest: 0.8.0 Despite executing "npm ...

"Incorporate countless Bootstrap 4 carousels into one webpage for an enhanced user

I'm experiencing difficulties with the new Bootstrap 4. Can anyone provide guidance on how to incorporate multiple Bootstrap carousels into a single page? I've researched several websites, but most only offer solutions for Bootstrap 3. Your assi ...

Leverage Angular's directives to incorporate HTML elements into your project

I am trying to integrate the HTML code from a file called protocol-modal.html into my main HTML file as a directive: <div class="modal-content"> <form class="form-horizontal" role="form" name="questionForm"> <div class="modal-heade ...

What is the best way to navigate to a specific ID on the homepage using a navigation button on another page?

When a navigation button is clicked on any page other than the home page, I want the home page to load first and then scroll to the corresponding id mentioned in the navlink. Below is the code snippet: <Col sm={5}> <Nav className=& ...

jQuery event.preventDefault not functioning as expected

I am attempting to use jQuery's preventDefault() method, but when I submit the form, it still displays the default behavior and reloads the page. Here is the code from index.html: <body> <script src="/socket.io/socket.io.js"></script& ...

Is it possible to display a thumbnail image in a separate full-sized window by using CSS or JavaScript?

I am currently utilizing a program called WebWorks 2020.1 that automatically creates <img> tags from my FrameMaker source input when published to DHTML. Unfortunately, I do not have the ability to directly modify the HTML <img> or <a> tag ...

JavaScript Fullcalendar script - converting the names of months and days

I recently integrated the Fullcalendar script into my website (https://fullcalendar.io/). Most of the features are functioning correctly, however, I am seeking to translate the English names of months and days of the week. Within the downloaded package, ...

Jquery failing to properly loop text effect

I attempted to continuously display text using the fadein and fadeout effects. You can see exactly what I mean in this example. Below is the jQuery code where I am trying to cycle through messages: (function() { var message = jQuery("#message_after_ ...

How to send data to Material-UI drawer components

In the component called Setup, there are input fields that each hold their own data stored in an object named dropdowns. Alongside each input field, there is a drawer component containing the ID of that specific input field. I have a function called handle ...

What is the best way to incorporate new elements into the DOM in order to allow users to share their comments

Can anyone help me with the code below? I have a text box and a comment section, along with a button to add comments. However, I need assistance with adding the posted comment below the comment section. Below is the code snippet: <div id="comments"&g ...

Guide on Triggering a Custom Popup Message upon a Server Action in Next.js

Hey there, I'm currently facing some difficulties in finding the proper way to trigger a toast notification after successfully mutating data using server actions in Nextjs 13. The toast component I'm working with is specifically designed for clie ...

Storing and Retrieving Cookies for User Authentication in a Flutter Application

I am currently working on developing a platform where, upon logging in, a token is created and stored in the cookie. While I have successfully implemented a route that stores the cookie using Node.js (verified in Postman), I encounter issues when attemptin ...

The webpage is not displaying any results despite using .innerHTML with Ajax

I am currently developing a web application that displays query results using the Google Books API. While my code is functioning, I am encountering an issue where the .innerHTML method does not show any results on the HTML page. Below is the HTML code bein ...

Tips for creating an effective dark mode toggle switch on a website

I was experimenting with creating a dark-mode switch for a website, but I'm not convinced that my implementation is the most efficient. Essentially, I ended up duplicating each file and adding a "2" at the end to create modified versions for each sect ...