``Using backticks to denote HTML syntax - Leveraging Google Charts to create

Has anyone found a way to incorporate HTML in ticks within a Google chart? I am attempting to insert a weather icon from

This is my current attempt:

const dailyData = new google.visualization.DataTable();
        dailyData.addColumn('timeofday', 'Hour');
        dailyData.addColumn('number', 'Visits');

        let mTicks = [];

        for(let i: number = 8; i <22; i++) {

            let timeofday: any = [parseFloat(parsedData[0].data[i].name[1]),0,0];

            let weatherIcon = '-';

            if(parsedData[0].data[i].weather_code > 0) {

                let weather = new WeatherFunctions(parsedData[0].data[i].weather_code).getResult();

                weatherIcon = weather.icon;
            }

            let fullString: string = `${i}:00 <br/> ${weatherIcon}`;

            dailyData.addRow([timeofday, parsedData[0].data[i].visits]);
            mTicks.push({v: timeofday, f: fullString});
        }


        const options: any = {
            allowHTML: true,
            legend: {
                position: 'none'
            },

            hAxis: {
                ticks:mTicks
                ,
                title: 'Time - Weather - Temperature'
            }
        };

where full string =

"8:00 <i class="wi wi-day-sunny-overcast"></i>"
.

Unfortunately, including HTML in the string causes the ticks not to display.

Answer №1

Due to the SVG nature of the chart,
HTML elements are not supported within chart elements
(except for tooltips)

Nevertheless, the chart offers methods that facilitate positioning HTML overlays

On the 'ready' event of the chart, you can utilize the chart method --> getChartLayoutInterface()

The interface includes a method --> getBoundingBox()
by providing the id of a chart element, it will provide the coordinates

To obtain the position of the first x-axis label...

var chartLayout = chart.getChartLayoutInterface();
var labelBounds = chartLayout.getBoundingBox('hAxis#0#label#0');

Use these coordinates to accurately position your HTML overlay

Refer to the working snippet below,
an image is inserted right after each x-axis label...

google.charts.load('current', {
  packages: ['corechart']
}).then(function () {
// JavaScript code snippet showing how to add an image next to each x-axis label in the Google Charts Line Chart.
};
html, body {
  height: 100%;
  margin: 0px;
  overflow: hidden;
}

.chart {
  height: 100%;
}

.tickIcon {
  position: absolute;
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div class="chart" id="chart_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

Some components react to history.push() with react-router-dom while others simply don't seem to respond

As the title states, I am using React-router-dom in my App.js file with a Router containing multiple Routes and a Switch. I have been successful in manipulating history and navigating my app using useHistory and history.push() in smaller components. Howev ...

Ways to determine the presence of a value in an array using AngularJs

I'm currently working on looping through an array to verify the existence of email, phone, and alternate phone in a database. My challenge lies in finding a suitable function or workaround in AngularJS that allows me to iterate through the array with ...

Steps to hide a div after it has been displayed once during a user's session

After a successful login, I have a div that displays a success message and then hides after 4 seconds using the following JavaScript code: document.getElementById('success').style.display = 'none'; }, 4000); While this functionality wo ...

Adjust the text appearance of the graph in ApexCharts

Is there a way to adjust the font size of the donut chart generated by using apexchart? You can view the image here. <template> <section> <v-card raised> <v-card-title class="blue--text">Requests Overview</v-card-ti ...

Vue.js mobile app may show a loaded DOM that remains invisible until the screen is tapped

I am facing a peculiar issue that has me stumped. On my mobile device, my page initially loads like this homepage However, once I tap the screen, all the components suddenly appear. Is there a way to simulate a click on my mobile? I'm struggling to u ...

Error in Vue.js: "Trying to access properties of an object that is undefined (specifically '$refs')"

When we trigger methods from a parent component in a child component, we use the following code: await this.$refs.patientinputmask.$refs.patientpersonaldata.ChangePersonalData(); await this.$refs.patientinputmask.$refs.patientaddressdata.SavePersonalAddres ...

"Having an issue with the jQuery AJAX call where the success function is not operating as expected

I attempted to retrieve information from a database using PHP by making an AJAX call with jQuery. However, I encountered an issue where the $.ajax function was not functioning as expected. There were no error messages displayed, and the console.log('s ...

Deciphering JavaScript's Minus Equals Operator: What's the Significance?

Can you explain the significance of the minus equals symbol -= in the following code snippet? $('#wrapper').animate({ backgroundPosition: '-=2px' })(); Appreciate your help! ...

Having difficulty configuring unique paths for multiple APIs using Socket.IO, ExpressJS, and Nginx

I am currently working on setting up multiple APIs on a single VPS and serving them through Nginx. My goal is to have all of them organized in separate sub-locations, as shown in the example below: For Express remote paths: [myhost].com/apps/app1/api [myh ...

Managing asynchronous data retrieval using rxjs

Within my service, I use an Observable to load data in the constructor. Later on, this data can be accessed using a getter, which should either return the data immediately if it's available or wait until the loading process is complete. Here is an exa ...

Retrieve the data from a JSON file using Angular 4

I have a JSON data structure that looks like this: [{"id": "ARMpalmerillas07", "type": "GreenHouse","act_OpenVentanaCen": {"type": "float", "value": 0, "metadata": {"accuracy": {"type": "Float", "value": "07/02/2018 13:08 : 43 "}}}, "act_OpenVentanaLatNS" ...

Tips on transferring key values when inputText changes in ReactJs using TypeScript

I have implemented a switch case for comparing object keys with strings in the following code snippet: import { TextField, Button } from "@material-ui/core"; import React, { Component, ReactNode } from "react"; import classes from "./Contact.module.scss" ...

Leveraging AnimatePresence from the Framer Motion library to design an exit animation for a motion.div

My goal is to implement a side menu that smoothly slides in and out when the menu/close button is clicked using framer motion. Initially, clicking on the menu button will cause the menu to slide out from the left side of the screen while changing the butto ...

Ways to automatically check a checkbox using jQuery

Is there a way to use jQuery to programmatically click a checkbox? I am trying to create a hidden checkbox that will be checked when a user clicks on a specific element, but my current code is not functioning as expected and I am unsure why. You can view ...

My jquery is malfunctioning when trying to retrieve values

I am facing an issue with accessing server-side values in my jQuery function. When I use my localhost path (NewsRecord.php) as the AJAX URL, it works fine. However, when I use the server path, it does not work. The strange thing is that the server URL pr ...

Why would someone opt to utilize process.env.PORT in their code?

Setting the environment variable PORT to a specific value, such as set PORT=5000, provides explicit instructions on which port the program should use. How does this method differ from simply instructing it to use port 3000? ...

Is it possible to share data from one controller in a JS file to another JS file? (using AngularJS)

I need to create a table in JavaScript. In one of my JS files, I have a controller with JSON data containing properties like width, height, color, etc. In another JS file, I am building the actual table structure. Here is an example of my AngularJS file: ...

Using JQUERY to toggle classes conditionally

$('.showall').css("cursor","pointer").click(function() { $('.value-container').toggle(); $('.dim-header').toggleClass($('.dim-header').toggleClass() == 'dim-header' ? 'dim-header active' : & ...

Incorporate Ng-Survey multiple times within one component

Incorporating the ng-surveys template into my Angular application via has been successful. However, I encountered an issue where when using the template selector *ngFor to display multiple surveys on the same page, the browser treats all the surveys as id ...

What causes npm start to fail in Angular 6 after incorporating social login functionality?

I am currently working on integrating Social Login functionality into my app. I have attempted to incorporate the following: npm install --save angular-6-social-login-fixed npm install --save angular-6-social-login npm install --save angular-6-social-log ...