【问题标题】:Victory - data visualization胜利——数据可视化
【发布时间】:2019-10-20 07:56:07
【问题描述】:

我正在尝试将 Victory 用于我的 React 项目,但由于某种原因它无法正常工作。

我使用的代码是:

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)

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

我得到的错误是:

  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.

我刚刚添加了 Victory 组件,不知道要导入什么

【问题讨论】:

  • 那些缺失的函数似乎是用来创建随机数据的,如果你想创建一个包含特定数据的图表,你就不需要它们了。

标签: javascript reactjs react-redux react-router victory-charts


【解决方案1】:

这是您正在使用的替代功能,它不是有效的 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;
 };

【讨论】:

  • 有完全相同的错误,它在文档中.. 用您的代码替换它会产生另一个错误:第 66:31 行:'x' is not defined no-undef 第 66:40:'y ' 未定义 no-undef
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多