4

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?

1
  • If the answer below worked for you, please click the check mark below the up/down-vote arrows in the answer so that other people can see that this solved your issue. If my answer was not clear enough, or if you are still having issues, please add a comment to the answer explaining what that issue is/what isn't clear.
    – jmac
    Commented Feb 18, 2013 at 4:53

2 Answers 2

13

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.

2

change as appropriate in the config file that the pie chart is located on. I had this chart under a donate.php as example:

FROM

$chartURL = 'http://chart.apis.google.com/chart?chf=bg,s,f9faf7&amp;cht=p&amp;chd=t:'.$percent.',-'.(100-$percent).'&amp;chs=200x200&amp;chco=639600&amp;chp=1.57';

TO

$chartURL = 'http://chart.apis.google.com/chart?chf=bg,s,FFFFFF00&amp;cht=p&amp;chd=t:'.$percent.',-'.(100-$percent).'&amp;chs=200x200&amp;chco=639600&amp;chp=1.57';

that code let me have transparency when it was a white background! thank you.

Not the answer you're looking for? Browse other questions tagged or ask your own question.