PieChart: tips for improving the tooltip visibility issue

While using Google Charts API v44, I encountered what appears to be a bug. When the name of an entry in the legend is too long, a tooltip with the name pops up. However, on Firefox under Fedora, the tooltip becomes unreadable due to both the font color and background color being the same: https://i.sstatic.net/266ZO.png

To address this issue, I decided to apply CSS styling like so: .goog-tooltip { color: white; }, which resolved the problem. Unfortunately, this approach caused display issues on my Mac as shown here: https://i.sstatic.net/6biEO.png

Trying

.goog-tooltip { color: white; background-color: black; }
changed the background color of the tooltip's borders rather than the tooltip itself.

How can I customize the font and background colors to ensure tooltips are readable across all platforms?

If you require access to the source code, it can be found here: HTML, JS, CSS

Answer №1

There are several choices available, take a look at the example charts provided below...

chart 0
To customize the tooltip text style, you can utilize the tooltip.textStyle configuration option. However, this option only allows for styling the text with specific attributes and does not support background customization.

color: <string>,
fontName: <string>,
fontSize: <number>,
bold: <boolean>,
italic: <boolean>

chart 1
Another method is to incorporate your own HTML/CSS by adding a tooltip column in the data.

data.addColumn({type: 'string', role: 'tooltip', p: {html: true}});

You also need to set tooltip.isHtml: true in the options section.

For further details, refer to Customizing HTML content.

Examples...

google.charts.load('current', {
  callback: function () {
    // Define data table
    var data = google.visualization.arrayToDataTable([
      ['Task', 'Hours per Day'],
      ['Work',     11],
      ['Eat',       2],
      ['Commute',   2],
      ['Watch TV',  2],
      ['Sleep',     7]
    ]);

    // Chart 0 settings
    new google.visualization.PieChart(document.getElementById('piechart0')).draw(data, {
      title: 'chart 0',
      tooltip: {
        textStyle: {
          color: 'deeppink',
          fontName: 'Verdana',
          fontSize: 16,
          bold: true,
          italic: true
        }
      }
    });

    // Constructing tooltip column
    data.addColumn({type: 'string', role: 'tooltip', p: {html: true}});
    for (var i = 0; i < data.getNumberOfRows(); i++) {
      data.setValue(i, 2,
        '<div class="goog-tooltip"><div class="goog-tooltip-task">' +
        data.getValue(i, 0) + '</div><div class="goog-tooltip-value">' +
        data.getValue(i, 1) + '</div></div>'
      );
    }

    // Chart 1 configuration
    new google.visualization.PieChart(document.getElementById('piechart1')).draw(data, {
      title: 'chart 1',
      tooltip: {
        isHtml: true
      }
    });
  },
  packages: ['corechart']
});
.goog-tooltip {
  background-color: black;
  padding: 6px 6px 6px 6px;
}

.goog-tooltip-task {
  color: cyan;
  font-size: 20px;
  font-weight: normal;
}

.goog-tooltip-value {
  color: gold;
  font-size: 16px;
  font-weight: bold;
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="piechart0"></div>
<div id="piechart1"></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

Every time I try to access my project by logging in, an error occurs and I am redirected back to the base URL

There is an error that occurs when I try to log in to my project and then go to the base URL. The error message is displayed below: https://i.sstatic.net/lJq7S.png Here is the URL for My Login page https://i.sstatic.net/MtY7Z.png After logging in, if I ...

What's the best way to align the hamburger menu to the left in Foundation CSS framework

My experience with SASS is still in its infancy, and I have encountered some issues. According to the documentation, I should make changes to _top-bar.scss by adding the line: $topbar-menu-icon-position: $default-float; (rather than $opposite-direction;). ...

Is there a way to make my siblings' elements turn black when hovering over an element?

Currently, I am working on CSS within Reactjs. In my project, I have two sibling elements: a logo and a text placed beside it. My goal is to have the text turn black when I hover over the logo, but so far, I have been unsuccessful in achieving this effect. ...

Ways to inspect a number within a span and adjust its color depending on the value?

Can someone help me figure out why this code is not reading the value correctly? Check it out here This is the HTML: <a class="InterestLink">Click me</a> <div id="InterestExpander"> <div id="InterestExpanderX"> ...

To add a span within a contenteditable field, restricting the user from inputting beyond the inserted span

When the user presses the space key, I want an auto input span to appear. However, when I trace them in the devtools, range.setEnd(lasttextnode, 0); and range.collapse() seem to work correctly. The issue arises when the keyboard input is not right. I try t ...

"Clicking on the radio button does not activate when placed within an <a> tag

Why is it that when the text is clicked, the radio button is checked, and when the little green patch is clicked, the frame is working, but they both don't work at the same time? Any assistance in resolving this issue would be greatly appreciated. ...

Creating a set of HTML input elements using a database variable

I am currently working on creating an HTML form where users can register quality features of a product. The number of features may vary depending on the model, and this information is stored in a SQL table. While I have managed to generate the input fiel ...

Modify the height of one or more <span> elements within a table cell

Is it possible in this scenario to automatically adjust the row height for <span class="orange">ORANGE</span>? And if there are two or more <span> elements, can the cell be split to accommodate varying heights? (You can use: display: tab ...

Update the DOM by setting the innerHTML with a template tag

I'm currently working on a Vue project and I'm facing an issue with setting the innerHTML of an HTML element using a template tag. Here's an example of what I've tried: let divElem = document.getElementById('divElem') let inne ...

How can you create two HTML DIVs side by side with equal heights?

I am working on creating two side by side DIVs, where one contains static content and the other has dynamic content. My goal is to make sure that the height of the static DIV increases whenever the height of the dynamic DIV increases. Here's the code ...

Is it possible that smarty assigns but doesn't execute the code?

In the process of developing a PHP-Script, I am tasked with assigning HTML code to various templates. PHP-File: $smarty->assign("PLACEHOLDER", getCode()); $smarty->display('index.html'); function getCode(){ return "{literal}some co ...

Using variables with Tailwind arbitrary values is not supported

Why is it that in tailwind, bg-[#5ad0a1] works but assigning the hex value to a variable such as const color = '#5ad0a1';, and then using bg-[${color}] does not work? <span className={`inline-flex items-center rounded-md bg-[${color}] px-2 py- ...

Modifying placeholder text styling using jQuery for font and color changes

I have a form with an input field like this: <input type="text" name="firstname" id="firstname" placeholder="First name"> Initially, I am checking if the input field is empty using jQuery: $("#submitreg").click(function(e){ if ($.trim($("#fi ...

Is it possible to incorporate percentage-based widths within a fixed layout design on a webpage?

I've been delving into the concepts of fixed, fluid, and responsive web page design. One of the resources I stumbled upon is this article about fixed vs. fluid layouts. In the article, it mentions that "A fixed website layout has a wrapper that is a f ...

Interactive Navigation Bar in JavaScript

Is there a way to create a horizontal menu with an arrow that follows the mouse cursor? I saw this effect on a website (http://cartubank.ge) and I'm curious if anyone has the source code for it? Your help would be greatly appreciated. ...

The performance of the animation on http://responsive-nav.com/ becomes erratic when viewed on Android devices

Recently, I came across a fantastic plugin that works perfectly on regular computer browsers. However, when I tested it on my android phone, the css3 animation for the dropdown appeared choppy and seemed to be dropping frames. Does anyone have suggestions ...

The React task list updates the todo items on change, rather than on submission

As a newcomer to React, I have embarked on the classic journey of building a todo app to learn the ropes. Everything seems to be functioning smoothly except for one minor hiccup: When I input a new todo and hit "submit", it does get added to my array but d ...

Display a single image on the tablet and a distinct image on the computer

Currently, I am encountering an issue with my webpage located at . The problem lies in the right upper corner where a ribbon is located. However, when viewing the page on a tablet, the ribbon overlaps with my menu. To resolve this, I thought about displa ...

Troubleshooting Issue with Post/Get Request in AJAX and Flask Framework

My current project involves building a YouTube scraper webpage purely for educational purposes. I have created a web page with a text box to enter search queries and a search button. When the button is clicked, an Ajax post request is sent with the text bo ...

The size of the downloaded file does not match the expected content length

I have a base64 encoded string that I decoded and want to give the user the ability to save it as a file. After decoding, the length of the content is 11271 bytes. var content = messageObj['data']; var decodedContent = atob(content); console.log ...