我想嵌入一个现成的谷歌图表,但不使用<script>
标签。
当我访问Google Charts并按“发布图表”时,会弹出一个窗口,说我应该将此代码放在HTML中的任何位置:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/static/modules/gviz/1.0/chart.js">
{"dataSourceUrl":"//docs.google.com/spreadsheet/tq?key=....","options":{"titleTextStyle":{"bold":true,"color":"#000","fontSize":16},"legendTextStyle":{"bold":true,"color":"#000000","fontSize":12},"animation":{"duration":0},"width":600,"hAxis":{"useFormatFromData":true,"minValue":null,"viewWindowMode":null,"viewWindow":null,"maxValue":null},"vAxes":[{"useFormatFromData":true,"title":null,"minValue":null,"viewWindow":{"max":null,"min":null},"maxValue":null},{"useFormatFromData":true,"minValue":null,"viewWindow":{"max":null,"min":null},"maxValue":null}],"booleanRole":"certainty","title":"A title","height":371,"legend":"right","focusTarget":"series","tooltip":{"trigger":"none"},"isStacked":false},"state":{},"view":{},"isDefaultVisualization":false,"chartType":"ColumnChart","chartName":"Chart 1"}
</script>
这将非常简单,只需复制和粘贴......问题是我无法在HTML中的任何位置添加<script>
标记,因为编辑器会拒绝它。我只能在HTML中生成<div id="mychart"></div>
并在javascript文件中添加一些内容,该文件将在<head>
的末尾加载。
因此,我的javascript代码会执行以下操作:
jQuery(document).ready(function() {
jQuery("#mychart").text("google chart here...");
});
但是我无法弄清楚如何将上面提到的图表嵌入到这段代码中(它只是一个带有json图表定义的脚本标记)。