Git Product home page Git Product logo

Comments (34)

xushuo avatar xushuo commented on May 22, 2024

我的react是0.13.3

from echarts-for-react.

hustcc avatar hustcc commented on May 22, 2024

可以看看你的代码吗?

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

我把 你的demo里面其中一个组件拿出来放到我的项目中运行,也是同样的错。之后我网上看了其他人类似的错误,貌似是因为异步加载的问题,导致dom还没有加载完毕?maybe...最后我直接调用的echarts,/(ㄒoㄒ)/~~可能避开了异步加载。

下面是调用echarts代码,写react还是很生疏,不知道逻辑对不对。也许你可以帮我看下。 :)

import React from 'react';
import echarts from 'echarts';

var EchartsInit = React.createClass({
    getInitialState:function(){
        return {option:this.props.option};
    },
    componentDidMount:function(){
        this.drawCharts(this.state.option);
    },
    drawCharts:function(option){
        var myChart = echarts.init(document.getElementById('charts'));
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    },
    componentWillUpdate:function(){
        this.drawCharts(this.state.option);
    },
    render: function() {
        return  <div id="charts" style={{height: this.props.tableHeight-80, width: this.props.tableWidth-80, margin: '10px auto'}}></div>
    }
});

from echarts-for-react.

hustcc avatar hustcc commented on May 22, 2024

这不是用的我这个组件啊(」゜ロ゜)」

from echarts-for-react.

pmdiano avatar pmdiano commented on May 22, 2024

我也遇到了这个问题(React 版本0.13.3),这是我的代码:

import React from 'react';
import ReactEcharts from 'echarts-for-react';
import StatsStore from '../stores/StatsStore';
import StatsActions from '../actions/StatsActions';

class Stats extends React.Component {
  constructor(props) {
    super(props);
    this.state = StatsStore.getState();
    this.onChange = this.onChange.bind(this);
  }

  componentDidMount() {
    StatsStore.listen(this.onChange);
    StatsActions.getStats(this.props.params.type);
  }

  componentWillUnmount() {
    StatsStore.unlisten(this.onChange);
  }

  componentDidUpdate(prevProps) {
    // Fetch new stats data when URL path changes
    if (prevProps.params.type !== this.props.params.type) {
      StatsActions.getStats(this.props.params.type);
    }
  }

  onChange(state) {
    this.setState(state);
  }

  getOption() {
    var option = {
          title : {
              text: '某站点用户访问来源',
              subtext: '纯属虚构',
              x:'center'
          },
          tooltip : {
              trigger: 'item',
              formatter: "{a} <br/>{b} : {c} ({d}%)"
          },
          legend: {
              orient: 'vertical',
              left: 'left',
              data: ['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']
          },
          series : [
              {
                  name: '访问来源',
                  type: 'pie',
                  radius : '55%',
                  center: ['50%', '60%'],
                  data:[
                      {value:335, name:'直接访问'},
                      {value:310, name:'邮件营销'},
                      {value:234, name:'联盟广告'},
                      {value:135, name:'视频广告'},
                      {value:1548, name:'搜索引擎'}
                  ],
                  itemStyle: {
                      emphasis: {
                          shadowBlur: 10,
                          shadowOffsetX: 0,
                          shadowColor: 'rgba(0, 0, 0, 0.5)'
                      }
                  }
              }
          ]
      };

      return option;
  }

  render() {
    return (
      <div className='container'>
        <ReactEcharts
          option={this.getOption()}
          style={{height: '350px', width: '100%'}}>
        </ReactEcharts>
      </div>
    );
  }
}

export default Stats;

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

@pmdiano 你解决了吗?上面我的代码有点问题,生成图表时,页面中貌似会构建多次,也许是option的变动引起的、

from echarts-for-react.

pmdiano avatar pmdiano commented on May 22, 2024

@xushuo 没有呐😆 刚开始学这些。。在出错的那个地方:

    /**
     * @param  {HTMLDomElement} dom
     * @return {echarts~ECharts}
     */
    echarts.getInstanceByDom = function (dom) {
        var key = dom.getAttribute(DOM_ATTRIBUTE_KEY); // <---- 出错
        return instances[key];
    };

dom是这样的:
screen shot 2016-11-06 at 9 15 31 pm

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

@pmdiano 我也是这个地方,据说是异步加载的问题。我在echarts的issues里面看到过类似的问题。在问题解决前,只好直接调用原生echarts了....

from echarts-for-react.

pmdiano avatar pmdiano commented on May 22, 2024

@xushuo 那为啥@hustcc的例子是可以work的?

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

@pmdiano 是可以work的.我想知道为什么用echarts-for-react会出现这个错误. :)

from echarts-for-react.

pmdiano avatar pmdiano commented on May 22, 2024

@xushuo 我把React升级成0.14.8貌似可以work了。。有个warning如下应该怎么改?

vendor.bundle.js:2120 Warning: React.render is deprecated. Please use ReactDOM.render from require('react-dom') instead.

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

@pmdiano 语法问题,0.15之后禁止使用React.render 了,要用 ReactDOM.render代替。0.14只是会警告,不影响运行吧。
var React = require('react');
var ReactDOM = require('react-dom');
var MyComponent = React.createClass({
render: function() {
return

Hello World
;
}
});
ReactDOM.render(, node);

我的react是0.13.因为项目关联其他的组件,升级比较麻烦,正好卡在0.12-0.14./(ㄒoㄒ)/~~

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

我记得之前看到echarts-for-react插件的要求是0.13+的吧。
"peerDependencies": {
"react": ">=0.13.2 || ^0.14 || ^15.0.0"
}

from echarts-for-react.

hustcc avatar hustcc commented on May 22, 2024

那么这个问题解决了没有^_^~

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

呃。。。木有。。。

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

这因为0.13.3 react没法引用你这个插件么?

from echarts-for-react.

hustcc avatar hustcc commented on May 22, 2024

@xushuo 你的代码是什么?不要贴你用 echarts 的代码,贴你用echarts-for-react的代码,也就是使用这个项目的代码。

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

pmdiano 贴的代码和我的差不多,也是null错误,我的代码已经被改成echarts的代码了。要重现需要重新写一个

from echarts-for-react.

hustcc avatar hustcc commented on May 22, 2024

测试了一下,我这边出错是:

Uncaught TypeError: _reactDom2.default.render is not a function

你那边的错误是:dom.getAttribute is not a function ???

from echarts-for-react.

hustcc avatar hustcc commented on May 22, 2024

这个问题是react版本问题导致的,建议还是升级react吧~~~现在都到15了,为啥还要用13呢~

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024
 import React from 'react';
 import _ from 'lodash';
 import FQN from '../utils/fqn';
 import ResultsPreviewStore from '../stores/ResultsPreviewStore';
 import ResultsPreviewActions from '../actions/ResultsPreviewActions';
 import UpdateWidthMixin from '../mixins/UpdateWidthMixin';
 import QueryActions from '../actions/QueryActions';
 import ReactEcharts from '../utils/echarts-for-react';

 // State actions
 function getStateFromStore() {
   return {
     query: ResultsPreviewStore.getPreviewQuery(),
     table: ResultsPreviewStore.getResultsPreview()
   };
 }

 function selectQuery(query, e) {
   e.preventDefault();
   QueryActions.selectQuery(query);
 }

 const EchartsTable = React.createClass({
   displayName: 'EchartsTable',
   mixins: [UpdateWidthMixin],

   getInitialState() {
     return getStateFromStore();
   },

   componentDidMount() {
     ResultsPreviewStore.listen(this._onChange);
   },

   componentWillUnmount() {
     ResultsPreviewStore.unlisten(this._onChange);
   },

   render() {
     if( this.state.table && this.state.table.data ) {
       return this._renderColumns();
     } else {
       return this._renderEmptyMessage();
     }
   },

   /* Internal Helpers ------------------------------------------------------- */
   _renderEmptyMessage() {
     return (
       <div className="panel-body text-light text-center">
         <p>请先查询语句.</p>
       </div>
     )
   },

   _renderColumns() {
     return (
       <div className='flex flex-column airpal-table'>
         <div className='editor-menu'>
           <div 
             style={{width: this.props.tableWidth - 20}} 
             className="text-overflow-ellipsis">
             <a href="#" onClick={selectQuery.bind(null, this.state.query)}>
               {this.state.query}
             </a>
           </div>
         </div>
         <ReactEcharts ref='echarts_react'
         option={this.state.option}
         style={{height: '400px', width:  '400px'}} />
       </div>
     );
   },
   /* Store events */
   _onChange() {
     this.setState(getStateFromStore());
   }
 });


 export default EchartsTable;

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

这个是我的 ,之前的代码。 改版改动太大,赶进度。唉

from echarts-for-react.

hustcc avatar hustcc commented on May 22, 2024

好吧,我尝试解决一下吧,你这个代码应该和我的报错是一样的吧?

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

你用的react多少版本的?0.15之后不支持一些语法

from echarts-for-react.

hustcc avatar hustcc commented on May 22, 2024

0.14.0 这个版本,在这里也可以看到:https://github.com/hustcc/echarts-for-react/blob/master/package.json#L48-L49

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

如果你那里测试环境换成0.13.3的,也许会有我这个错误。
https://github.com/hustcc/echarts-for-react/blob/master/package.json#L68-L70

from echarts-for-react.

hustcc avatar hustcc commented on May 22, 2024

你错误具体是什么,截图一下呗~~

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

错误就是 issues的标题 TypeError: dom.getAttribute is not a function

from echarts-for-react.

hustcc avatar hustcc commented on May 22, 2024

好吧,我倒是没有出现这个错误。

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

出错位置就是
/**
* @param {HTMLDomElement} dom
* @return {echarts~ECharts}
*/
echarts.getInstanceByDom = function (dom) {
var key = dom.getAttribute(DOM_ATTRIBUTE_KEY); // <---- 出错
return instances[key];
};

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

如果你换成0.13.3还是没有出现我的错误的话。那也许是其他地方的问题吧。 ~)

from echarts-for-react.

hustcc avatar hustcc commented on May 22, 2024
echarts.getInstanceByDom = function (dom) {
var key = dom.getAttribute(DOM_ATTRIBUTE_KEY); // <---- 出错
return instances[key];
};

这个代码是你自己写的吧,不知道为什么需要使用 instances` 去缓存 echarts 对象。

TypeError: dom.getAttribute is not a function 说明传入的 dom 根本就不是一个dom 啊~~你可以打印出来看一下。

from echarts-for-react.

xushuo avatar xushuo commented on May 22, 2024

/**
* @param {HTMLDomElement} dom
* @return {echarts~ECharts}
*/
echarts.getInstanceByDom = function (dom) {
var key = dom.getAttribute(DOM_ATTRIBUTE_KEY); // <---- 出错
return instances[key];
};

这个是 echarts 里得代码

from echarts-for-react.

hustcc avatar hustcc commented on May 22, 2024

那感觉不是这个项目的问题啊~~~

我这边使用[email protected]版本没有这个问题~

from echarts-for-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.