Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Charts transparent background not working

I am trying to make the background transparent for some charts I have made with google charts. They work perfectly in everything except IE7 and 8, I get a white backgound.

I have tried every combination I can find for the color attribute to change it but nothing works.

The only thing left to try was a suggesting that someone made on here a few months ago for someone else with the same issue. Their suggestion was...

For a transparent background, use chf=bg,s,FFFFFF00

But I have no idea how to implement this?

like image 551
tatty27 Avatar asked Dec 07 '22 09:12

tatty27


1 Answers

chf=bg,s,FFFFFF00

is a code for the old Google Image Charts.

Those codes will only work with the non-SVG versions of charts. Google Image Charts have been deprecated (as you can see from their help pages), so unless you want to implement the old-style charts, you won't be able to implement the above code on your new, fancy, interactive SVG charts.

For the new fancy SVG charts, I have luck with

backgroundColor: "transparent"

Copy-paste this in to Google Playground to test:

<!--
You are free to copy and use this sample in accordance with the terms of the
Apache license (http://www.apache.org/licenses/LICENSE-2.0.html)
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>
      Google Visualization API Sample
    </title>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load('visualization', '1', {packages: ['corechart']});
    </script>
    <script type="text/javascript">
      function drawVisualization() {
        // Create and populate the data table.
        var data = google.visualization.arrayToDataTable([
          ['Year', 'Austria', 'Bulgaria', 'Denmark', 'Greece'],
          ['2003',  1336060,    400361,    1001582,   997974],
          ['2004',  1538156,    366849,    1119450,   941795],
          ['2005',  1576579,    440514,    993360,    930593],
          ['2006',  1600652,    434552,    1004163,   897127],
          ['2007',  1968113,    393032,    979198,    1080887],
          ['2008',  1901067,    517206,    916965,    1056036]
        ]);

        // 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"},
                  backgroundColor: "transparent"}
            );
      }


      google.setOnLoadCallback(drawVisualization);
    </script>
  </head>
  <body style="font-family: Arial;border: 0 none;" bgcolor="#E6E6FA">
    <div id="visualization" style="width: 600px; height: 400px;"></div>
  </body>
</html>

This is just the standard bar chart example with two things added:

  1. bgcolor="#E6E6FA" to the body element (make it blue so we can tell if transparent)
  2. backgroundColor="transparent" to the options (make it transparent)

This works in FireFox. I don't know if it works in IE7 (no testing environment). Let us know if it works.

like image 197
jmac Avatar answered Jan 19 '23 08:01

jmac