如何将背景图像破解到 Google 图表工具中?动态(JavaScript/SVG)图表?
我正在更新一个使用 Google Image Chart API 的旧数据可视化模块。现在,我们将切换到新的可视化 API< /a>,它使用 JavaScript 在浏览器中指定的 容器内生成动态图表。
我们需要为图表提供背景图像(用于品牌推广目的)。然而,鉴于API参考中的配置选项,是改变背景颜色。
如果我将背景图像嵌入到绘制图表的
中,则图表(显然)只会覆盖它。是否有我完全不知道的 JavaScript 或 HTML5 解决方案可以解决我的问题?
(我对 JavaScript 有点陌生,感谢您忍受这个实际上可能是微不足道的——或者显然不可能的——问题!)
I'm updating an older data visualization module which used the Google Image Chart API. Now, we're switching to the new(er) Visualization API, which uses JavaScript to generate dynamic charts in the browser, within a specified <div>
container.
We have a need to present the chart with a background image (for branding purposes). However, the only thing I've been able to accomplish, given the configuration options in API reference, is to change the background colour.
If I embed a background image into the <div>
the Chart is drawn into, the chart (obviously) just overlays it.
Is there a JavaScript or HTML5 solution to my problem that I'm totally unaware of?
(I'm somewhat new to JavaScript, to thank you for bearing with what may actually be a trivial -- or clearly impossible -- problem!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能希望用另一个图表的目标元素包裹图表的目标元素,并将父级的背景更改为您想要的图像,同时删除子级的背景。
例如,HTML
和 CSS
当然,在 JavaScript 中的图表选项中,
我在这里放了一个示例 http://jsfiddle.net/jaimem/jaxfz /
You might want to wrap your chart's target element with another one and change the parent's background to the image you want, while removing the background of the child.
for example, HTML
and CSS
And of course in your chart options in JavaScript
I put an example here http://jsfiddle.net/jaimem/jaxfz/
以防万一有人遇到和我一样的问题,您也可以仅修复图表的背景,而不是整个 div(这会将背景添加到标题、轴等),
您可以执行以下操作:
在 Html 中,正如 jaime 建议的那样:
在 css 中,正如 jaime 建议的那样:
在 javascript 中:
所有这些代码都是使用 jaime 的建议编写的,Google 图表文档 以及 此堆栈溢出问题
Just in case someone has the same problem as me, you can also fix the background to the chart only, and not the entire div (which will add background to the title, axis, etc.)
You can do this doing something like this:
In Html, as jaime suggested:
In css, as jaime suggested:
In javascript:
All this code was written using jaime's suggestion, google chart's documentation and the comments on this stack overflow question