Google Charts透明背景无效

tat*_*y27 4 google-visualization

我试图使用谷歌图表制作的一些图表使背景透明.除了IE7和8之外,它们完美地运行在一切,我得到一个白色的背景.

我已经尝试了我可以找到的每个组合的颜色属性来改变它,但没有任何作用.

剩下要尝试的唯一一件事就是建议有人在几个月前在这里为其他人提出同样的问题.他们的建议是......

对于透明背景,请使用chf = bg,s,FFFFFF00

但我不知道如何实现这个?

jma*_*mac 13

CHF = BG,S,FFFFFF00

是旧版Google Image Charts的代码.

这些代码仅适用于非SVG版本的图表.Google Image Charts已被弃用(正如您可以从他们的帮助页面中看到的那样),因此除非您想要实现旧式图表,否则您将无法在新的,精美的交互式SVG图表上实现上述代码.

对于新的花式SVG图表,我很幸运

backgroundColor: "transparent"
Run Code Online (Sandbox Code Playgroud)

将其复制粘贴到Google Playground以测试:

<!--
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)
-->
Run Code Online (Sandbox Code Playgroud)
<!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>
Run Code Online (Sandbox Code Playgroud)

这只是添加了两件事的标准条形图示例:

  1. bgcolor ="#E6E6FA"到body元素(将其设为蓝色,以便我们可以判断是否透明)
  2. backgroundColor =选项的"透明"(使其透明)

这适用于FireFox.我不知道它是否适用于IE7(没有测试环境).如果有效,请告诉我们.