如何在谷歌图表中放置图像背景 [英] How to place an image background in a google chart

查看:118
本文介绍了如何在谷歌图表中放置图像背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Google图表中放置背景图片。我见过的解决方案建议在父div中包含图表,并为父div设置背景图像。但是,如果我这样做,那么背景图像也将覆盖图表外部显示轴标签和图例等的区域。另外,是否有任何方法可以检索图表选项,以便我可以使用chartArea.top,chartArea.left和chartArea.top, chartArea.width和chartArea.height覆盖图表上正确位置的图片?



非常感谢,Chris

解决方案

您可以通过以下方式获取有关图表绘制位置的信息:

  var graph = new google.visualization.LineChart(...); 
graph.draw(data,...);
var boundingBox = graph.getChartLayoutInterface()。getChartAreaBoundingBox();
var pixelsFromLeft = boundingBox.left;

然后,您可以使用此信息在正确的位置上绘制一个div。

I need to place a background image in a Google Chart. I've seen solutions which suggest including the chart in a parent div and setting a background image for the parent div. However, if I do that then the background image will also cover the area outside the chart where the axis labels and legend, etc are displayed. I want my image in the chart area itself only.

Alternatively, is there any way to retrieve the chart options so that I could use chartArea.top, chartArea.left, chartArea.width and chartArea.height to overlay an image on the chart in the correct place?

Many thanks, Chris

解决方案

You can get information about where your chart is drawn in the following manner:

var graph = new google.visualization.LineChart(...);
graph.draw(data, ...);
var boundingBox = graph.getChartLayoutInterface().getChartAreaBoundingBox();
var pixelsFromLeft = boundingBox.left;

You can then use this information to draw a div on the correct position.

这篇关于如何在谷歌图表中放置图像背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆