0

一旦页面加载谷歌倾向于图表在趋势块类下加载。在调用 next_fun() 后,在下面的代码中,完成 html 代码获取图形渲染。我需要在趋势块内部渲染。

<html>
<body>

<script type="text/javascript" src="https://ssl.gstatic.com/trends_nrtr/1173_RC01/embed_loader.js"></script> 

<div class="trendsBlock">
    <script type="text/javascript"> 
        trends.embed.renderExploreWidget("TIMESERIES", {"comparisonItem":[{"keyword":"dbs bank","geo":"IN","time":"2016-10-02 2017-11-02"},{"keyword":"citi bank","geo":"IN","time":"2016-10-02 2017-11-02"}],"category":0,"property":""}, {"exploreQuery":"date=2016-10-02 2017-11-02,2016-10-02 2017-11-02&geo=IN&q=dbs%20bank,citi%20bank","guestPath":"https://trends.google.com:443/trends/embed/"}); 
    </script> 

</div>


<button onclick="next_fun()">Click to next trends</button>  

<script type="text/javascript">

    function next_fun(){

        //innerHTML in to class trendsBlock

        //?

    }

</script>
</body>
</html>
4

1 回答 1

4

renderExploreWidgetTo方法允许将图表嵌入到任何 HTML 元素中。

你可以看下面的示例代码来理解。

function next_fun(){

var divElem = document.getElementById('sampDiv');

trends.embed.renderExploreWidgetTo(divElem,"TIMESERIES", {"comparisonItem":[{"keyword":"dbs bank","geo":"","time":"today 12-m"}],"category":0,"property":""}, {"exploreQuery":"q=dbs%20bank&date=today 12-m","guestPath":"https://trends.google.com:443/trends/embed/"});
  
}
 
    <html>
    <body>

 <script type="text/javascript" src="https://ssl.gstatic.com/trends_nrtr/1328_RC04/embed_loader.js"> </script>

    <div id='sampDiv'>
    </div>


    <button onclick="next_fun()">Click to next trends</button>  
    </body>
    </html>

PS:当我在 StackOverflow 的内部编译器/浏览器中运行上述代码时,它会引发错误。 错误图!!

但否则工作正常。

于 2018-03-16T13:16:51.577 回答