Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在react中添加google趋势_Reactjs_Google Trends - Fatal编程技术网

Reactjs 在react中添加google趋势

Reactjs 在react中添加google趋势,reactjs,google-trends,Reactjs,Google Trends,如何在reactjs中添加google趋势中的图表等组件 componentDidUpdate() { const that = this const keyword = "your keyword" conts script = document.createElement("script") script.src = "https://ssl.gstatic.com/trends_nrtr/760_RC08/embed_loader.js" scri

如何在reactjs中添加google趋势中的图表等组件

componentDidUpdate() {
    const that = this
    const keyword = "your keyword"

    conts script = document.createElement("script")
    script.src = "https://ssl.gstatic.com/trends_nrtr/760_RC08/embed_loader.js"
    script.async = true

    ReactDOM.findDOMNode(this.refs.trendsWrapper1).appendChild(script)

    script.onload = function () {
       trends.embed.renderExploreWidgetTo(ReactDOM.findDOMNode(that.refs.trendsWrapper1), "TIMESERIES", {"comparisonItem":[{"keyword":keyword,"geo":"","time":"today 5-y"}],"category":0,"property":""}, {"exploreQuery":"q=%2Fm%2F0rfgxy2","guestPath":"https://www.google.co.uk:443/trends/embed/"})
    }

}

我试过了,但没有成功。请尝试推荐一种比这简单得多的方法。

您需要在react之外加载embed_loader脚本(与任何其他第三库代码一样)

在组件上,运行trends.embed命令

var Trends = React.createClass({
  render: function() {
   trends.embed.renderWidget("US_cu_mqCQGFwBAABWOM_en", 
   "fe_line_chart_309e703b-7d68-4baa-8dc9-c12e2f9defc3", 
   {"guestPath":"https://trends.google.com:443/trends/embed/"});  
  return (
    <div>must return something :/</div>
  )}
});
var Trends=React.createClass({
render:function(){
trends.embed.renderWidget(“US_cu_mqCQGFwBAABWOM_en”,
“fe_线图_309e703b-7d68-4baa-8dc9-c12e2f9defc3”,
{“访客路径”:https://trends.google.com:443/trends/embed/"});  
返回(
必须归还一些东西:/
)}
});

您需要将嵌入加载器脚本加载到react之外(与任何其他第三个库代码一样)

在组件上,运行trends.embed命令

var Trends = React.createClass({
  render: function() {
   trends.embed.renderWidget("US_cu_mqCQGFwBAABWOM_en", 
   "fe_line_chart_309e703b-7d68-4baa-8dc9-c12e2f9defc3", 
   {"guestPath":"https://trends.google.com:443/trends/embed/"});  
  return (
    <div>must return something :/</div>
  )}
});
var Trends=React.createClass({
render:function(){
trends.embed.renderWidget(“US_cu_mqCQGFwBAABWOM_en”,
“fe_线图_309e703b-7d68-4baa-8dc9-c12e2f9defc3”,
{“访客路径”:https://trends.google.com:443/trends/embed/"});  
返回(
必须归还一些东西:/
)}
});