首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >胜利-数据可视化

胜利-数据可视化
EN

Stack Overflow用户
提问于 2019-10-20 15:56:08
回答 1查看 115关注 0票数 1

我正在尝试为我的React项目使用胜利,但由于某些原因它无法工作。

我使用的代码是:

代码语言:javascript
复制
class App extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      data: this.getData()
    };
  }

  componentDidMount() {
    this.setStateInterval = window.setInterval(() => {
      this.setState({
        data: this.getData()
      });
    }, 3000);
  }

  componentWillUnmount() {
    window.clearInterval(this.setStateInterval);
  }

  getData() {
    const bars = random(6, 10);
    return range(bars).map((bar) => {
      return {x: bar + 1, y: random(2, 10)};
    });
  }

  render() {
    return (
      <VictoryChart
        domainPadding={{ x: 20 }}
        animate={{duration: 500}}
      >
        <VictoryBar
          data={this.state.data}
          style={{
            data: { fill: "tomato", width: 12 }
          }}
          animate={{
            onExit: {
              duration: 500,
              before: () => ({
                _y: 0,
                fill: "orange",
                label: "BYE"
              })
            }
          }}
        />
      </VictoryChart>
    );
  }
}

ReactDOM.render(<App/>, mountNode)

我在函数的不同部分中使用了大多数组件。

我得到的错误是:

代码语言:javascript
复制
  Line 28:18:  'random' is not defined  no-undef
  Line 29:12:  'range' is not defined   no-undef
  Line 30:30:  'random' is not defined  no-undef

Search for the keywords to learn more about each error.

我不知道要导入什么,因为我刚刚添加了胜利组件

EN

回答 1

Stack Overflow用户

发布于 2019-10-25 12:59:35

这里有一个替代你使用的函数,它不是有效的javascript。你从哪弄来的?

代码语言:javascript
复制
 const getData = () => {
   let arr = [];
  for (let i = 0; i < 15; i++) {
   arr.push({ x: x[i], y: y[Math.random(2, 10)] });
  }
  return arr;
 };
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58471053

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档