Spacing of data points in Google charts

I'm currently facing an issue with the spacing between the "Applications" and the data in my chart. In Chart 1, there is no space between the colon and the integer value. I would like it to resemble Chart 2 which shows the desired spacing.

(As a new user, I am unable to upload images of the charts)
Chart 1:
2011
Applicaitons:10 <-- no spacing

Chart 2: (sourced from Google)
25
Cats: 42 <-- spacing

I am populating the data dynamically, unlike the example provided by Google charts. Below is the code snippet:

    public string GetAppFiledPatIssuedByYear(DateTime? startDate, DateTime? endDate)
    {
        // Code logic
    }

***** Javascript function where the code is executed *****

function getAppFiledPatentsIssuedByYear() {
// Retrieve data and call drawing function
}

function drawAppFiledPatIssuedByYearChart(json) {
// Draw chart using google.visualization arrayToDataTable method
}

The backend returns the data as a string, which is then converted to a JSON object and passed back to the frontend in the JS file.

Link to Google Datapoint
How can I achieve the desired spacing between "Applications:10" and "Applications: 10"?

Answer №1

unable to replicate the problem at this time, everything appears to be functioning correctly.
take a look at the working snippet provided below:

is the issue related to the fontName? (what value is assigned to it?)

are there any missing components in the code snippet below?
filedAndIssuedColors & setVAxisTicks -- although unlikely to be causing the problem.

google.charts.load('current', {
  packages:['corechart']
}).then(function () {
  var data = google.visualization.arrayToDataTable([["Year","Applications", "Patents"], ["1990", 1, 0], ["1991", 11, 0], ["1992", 2, 0], ["1993", 1, 0], ["1994", 19, 0], ["1997", 1, 0], ["2000", 1, 0], ["2001", 9, 0], ["2002", 11, 0], ["2003", 2, 1], ["2004", 2, 0], ["2005", 15, 0], ["2006", 2, 1], ["2007", 34, 1], ["2008", 2, 5], ["2009", 2, 5], ["2010", 27, 1], ["2011", 14, 6], ["2012", 23, 7], ["2013", 22, 14], ["2014", 15, 6], ["2015", 94, 12], ["2016", 26, 22], ["2017", 96, 33], ["2018", 22, 51]]);

  var options = {
      isStacked: false,
      height: 250,
      width: "100%",
      fontSize: 12,
      //fontName: fontName,
      pointSize: 10,
      legend: { position: 'top' },
      chartArea: {
          top: 50,
          left: 60,
          width: "100%"
      },
      hAxis: {
          slantedText: true,
          slantedTextAngle: 45,
          textStyle: {
              fontsize: 11
          }
      },
      vAxis: {
          format: "0",
          textStyle: {
              bold: true
          },
          viewWindow: {
              min: 0
          }
      },

      //colors: filedAndIssuedColors
  };

  //setVAxisTicks(data, options);

  var chart = new google.visualization.LineChart(document.getElementById("chart_div"));
  chart.draw(data, options);

});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

UPDATE

there's an option to expand the tooltip using custom formatting,
refer to the functional snippet provided below...

google.charts.load('current', {
  packages:['corechart']
}).then(function () {
  var data = google.visualization.arrayToDataTable([["Year","Applications", "Patents"], ["1990", 1, 0], ["1991", 11, 0], ["1992", 2, 0], ["1993", 1, 0], ["1994", 19, 0], ["1997", 1, 0], ["2000", 1, 0], ["2001", 9, 0], ["2002", 11, 0], ["2003", 2, 1], ["2004", 2, 0], ["2005", 15, 0], ["2006", 2, 1], ["2007", 34, 1], ["2008", 2, 5], ["2009", 2, 5], ["2010", 27, 1], ["2011", 14, 6], ["2012", 23, 7], ["2013", 22, 14], ["2014", 15, 6], ["2015", 94, 12], ["2016", 26, 22], ["2017", 96, 33], ["2018", 22, 51]]);

  var options = {
      isStacked: false,
      height: 250,
      width: "100%",
      fontSize: 12,
      fontName: 'Open Sans',
      pointSize: 10,
      legend: { position: 'top' },
      chartArea: {
          top: 50,
          left: 60,
          width: "100%"
      },
      hAxis: {
          slantedText: true,
          slantedTextAngle: 45,
          textStyle: {
              fontsize: 11
          }
      },
      vAxis: {
          format: "0",
          textStyle: {
              bold: true
          },
          viewWindow: {
              min: 0
          }
      },
      tooltip: {
          isHtml: true
      }
  };
  var view = new google.visualization.DataView(data);
  view.setColumns([0, 1, {
    type: 'string',
    role: 'tooltip',
    calc: function (dt, row) {
      return '<div class="tooltip"><div><span>' + dt.getValue(row, 0) + '</span></div><div>' + dt.getColumnLabel(1) + ':&nbsp;&nbsp;<span>' + dt.getValue(row, 1) + '</span></div>';
    },
    p: {html: true}
  }, 2, {
    type: 'string',
    role: 'tooltip',
    calc: function (dt, row) {
      return '<div class="tooltip"><div><span>' + dt.getValue(row, 0) + '</span></div><div>' + dt.getColumnLabel(2) + ':&nbsp;&nbsp;<span>' + dt.getValue(row, 2) + '</span></div>';
    },
    p: {html: true}
  }]);
console.log('test');

  var chart = new google.visualization.LineChart(document.getElementById("chart_div"));
  chart.draw(view.toDataTable(), options);
});
.tooltip {
  font-family: 'Open Sans';
  font-size: 11pt;
  padding: 4px;
}

.tooltip div {
  padding: 4px;
}

.tooltip span {
  font-weight: bold;
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div 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

After running the map.fitBounds function, you can retrieve the current boundary coordinates using map.getBounds() in

After calling fitBounds() to recenter and zoom the map to fit the bounds, I expected getBounds() to return a valid bound. However, it is returning nil. Below is the code snippet that reproduces this issue: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...

Typescript is throwing a Mongoose error stating that the Schema has not been registered for the model

I've dedicated a lot of time to researching online, but I can't seem to figure out what's missing in this case. Any help would be greatly appreciated! Permission.ts (This is the Permission model file. It has references with the Module model ...

Node replication including a drop-down menu

Is there a way to clone a dropdown menu and text box with their values, then append them to the next line when clicking a button? Check out my HTML code snippet: <div class="container"> <div class="mynode"> <span class=& ...

Avoid showing a pop-up window when switching to a different page

I have a pop-up window that displays a confirmation message only when I am trying to close the browser/tab. It is working on my page, but it also appears when I navigate to another page. I want the pop-up window to only show up when I try to close the ta ...

Trouble aligning text in circles and fadeToggle not functioning correctly

Hello StackOverflow community! This is my first time posting here, so please excuse any mistakes I may have made while asking my question. :) [Issue 1] I've been trying to center text inside circles by referring to the following posts: Center text ...

Steps to manage the time delay between mousewheel events triggering

Currently, I am working on a website for a movie production company that showcases their various films in full-screen mode. Each video is listed and there is a function that automatically takes the user to the next video when a mousewheel event occurs. How ...

Encountering an error during the installation of node js when attempting to run npm install

npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1e687b7f7d6a327f6b6a717d717e737f76776c796937252327">[email protected]</a&g ...

What is the best way to attach a click event listener to dynamically generated child elements?

My parent container houses a variable number of elements generated by an API as the user inputs text. These elements, in turn, serve as parents to other child elements. The goal is for an overlay with more details about a specific element to appear when t ...

Exploring the Options for csc's linkresource Function

I am facing an issue with my .net assembly that relies on a native dll. When IIS copies files to the 'Temporary ASP.NET Files' folder, I would like the native dll to be copied along with the regular dll. I have attempted to use manifest dependenc ...

Encountering a Problem with the onEnter Method in React

Seeking to implement route authentication in my ReactJS app using React Router, I encountered an error when adding the authentication function to the onEnter property of a specific route. Error: Uncaught RangeError - Maximum call stack size exceeded Rout ...

Is it possible to identify the origin URL of a user using Javascript or AngularJS?

Is it possible to use Angular to detect the origin URL of a user visiting my website in order to perform specific operations later on? ...

What is the best way to showcase page content once the page has finished loading?

I'm facing an issue with my website. It has a large amount of content that I need to display in a jQuery table. The problem is that while the page is loading, all rows of the table are showing up and making the page extremely long instead of being sho ...

- "Utilizing the _underscore loop within a design framework"

I am encountering a persistent error while working on this. Specifically, I keep receiving an error related to syntax: syntax error var _p=[],print=function(){_p.push.a... ');}return __p.join(''); <script id="product" type="text/t ...

Stop displaying AJAX requests in the console tab of Firebug, similar to how Twitter does it

I'm looking for a way to prevent my AJAX calls from being logged in Firebug's Console tab, similar to how Twitter does it. When using Twitter search, you'll see a live update feed showing "5 tweets since you searched." Twitter sends periodic ...

JQuery causing array to not update properly

I am attempting to splice an array to remove an object from it. My approach involves using angular-formly for form display, and AngularJs with JQuery to manage the data. Utilizing JQuery $(document).on("click", ".delete-me", function () { var id = $( ...

Concealing the table border with the help of jQuery

I am working with a dynamically created tables in a ASP.NET repeater, where the number of tables can vary depending on the data retrieved from the database. Below is a sample markup along with the CSS and jQuery code. Please note that the tables are dynami ...

Controlling API requests using JavaScript, Python, and Bash

If I had to choose a language: Python (using Selenium or any other tool) Javascript (with node and any module) Bash (using curl for example) I would need to: Make a request to an API (Scrapy cloud) to retrieve a specific value, in this case, I only ne ...

Building a Laravel Form for Uploading Images in Laravel 5.3

I need help with uploading an image first and getting the image file path before storing all the data, including the image, into a database in LARAVEL. Can someone please advise me on what steps I should take to accomplish this? ...

What causes execution to halt without error in JavaScript?

While working with React hooks, I encountered an issue where code execution would inexplicably stop when reaching the await keyword within an async function. The await call is surrounded by a try...catch...finally block. Here's a simplified version of ...

Tips for effortlessly moving content by dragging and dropping it into a text box

Before attempting to create something, I want to verify its feasibility. Begin with a text area that can be pre-filled with text and allow users to add or delete text. Alongside the text area, there are small elements that can be images or HTML components ...