Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8634027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:36:55+00:00 2026-06-12T09:36:55+00:00

I have been playing around with Google charts quite a bit over in the

  • 0

I have been playing around with Google charts quite a bit over in the google charts play ground here:

Link

The code I have been playing with is this:

function drawVisualization() {
  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable([
    ['Year', 'Austria'],
    ['2003',  1336060],
    ['2004',  1538156],
    ['2005',  1576579],
    ['2006',  1600652],
    ['2007',  1968113],
    ['2008',  1901067]
  ]);

  // Create and draw the visualization.
  new google.visualization.BarChart(document.getElementById('visualization')).
      draw(data,
           {title:"Yearly Coffee Consumption by Country",
            width:600, height:400,
            vAxis: {title: "Year"},
            hAxis: {title: "Cups"}}
      );
}

and that gives me a nice chart that looks like this:

enter image description here

I am trying to have this chart fit the needs of my website, and to do this, I need to make the bar names on the left links to another page. So for example 2003 would be a link that the user can click ans so would 2004 etc.

I tried to do something like this:

function drawVisualization() {
  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable([
    ['Year', 'Austria'],
    ['<a href="url">Link text</a>',  1336060],
    ['2004',  1538156],
    ['2005',  1576579],
    ['2006',  1600652],
    ['2007',  1968113],
    ['2008',  1901067]
  ]);

  // Create and draw the visualization.
  new google.visualization.BarChart(document.getElementById('visualization')).
      draw(data,
           {title:"Yearly Coffee Consumption by Country",
            width:600, height:400,
            vAxis: {title: "Year"},
            hAxis: {title: "Cups"}}
      );
}

But I could only hope for it to be that easy and it wasn’t. Does anyone know if this is at all possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:36:56+00:00Added an answer on June 12, 2026 at 9:36 am

    This is non-trivial because the output you are seeing is SVG, not HTML. Those labels in your example (“2004”, “2005”, etc) are embedded inside SVG text nodes, so inserting raw HTML markup inside them will not be rendered as HTML.

    The workaround is to scan for the text nodes containing the target values (again, “2004”, “2005” etc) and replace them with ForeignObject elements. ForeignObject elements can contain regular HTML. These then need to be positioned more-or-less where the original SVG text nodes had been.

    Here is a sample snippet illustrating all this. It is tuned to your specific example, so when you switch to rendering whatever your real data is, you will want to modify and generalize this snippet accordingly.

    // Note: You will probably need to tweak these deltas
    // for your labels to position nicely.
    var xDelta = 35;
    var yDelta = 13;
    var years = ['2003','2004','2005','2006','2007','2008'];
    $('text').each(function(i, el) {
      if (years.indexOf(el.textContent) != -1) {
        var g = el.parentNode;
        var x = el.getAttribute('x');
        var y = el.getAttribute('y');
        var width = el.getAttribute('width') || 50;
        var height = el.getAttribute('height') || 15;
    
        // A "ForeignObject" tag is how you can inject HTML into an SVG document.
        var fo = document.createElementNS("http://www.w3.org/2000/svg", "foreignObject")
        fo.setAttribute('x', x - xDelta);
        fo.setAttribute('y', y - yDelta);
        fo.setAttribute('height', height);
        fo.setAttribute('width', width);
        var body = document.createElementNS("http://www.w3.org/1999/xhtml", "BODY");
        var a = document.createElement("A");
        a.href = "http://yahoo.com";
        a.setAttribute("style", "color:blue;");
        a.innerHTML = el.textContent;
        body.appendChild(a);
        fo.appendChild(body);
    
        // Remove the original SVG text and replace it with the HTML.
        g.removeChild(el);
        g.appendChild(fo);
      }
    });
    

    Minor note, there is a bit of jQuery in there for convenience but you can replace $('text') with document.getElementsByTagName("svg")[0].getElementsByTagName("text").

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been playing around quite a lot with EF4 Code First and I
I have been playing around with this preference activity code for most of the
I have been playing around with the code found here . I'm getting things
I have been playing around with Google Apps Script today and I am trying
I have been playing around a bit with a fairly simple, home-made search engine,
I have been playing around with the min3D libraries a bit lately learning how
I'm brand new to Google App Engine and have just been playing around with
I have been playing around with zxing over the weekend, and have ran into
I have been playing around with jQuery for a bit now, and am really
I am new to Android location/google maps. And I have been playing around with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.