如何使用 React Js 从 ApexCharts 获取 URI

Ibr*_*bra 1 javascript charts reactjs react-router apexcharts

我正在尝试使用 Data URI 方法获取图表 URI。我见过很多使用 Apexchart Js从 ApexChart获取 pdf 的示例,当尝试在 React 上重现它时,我得到了 TypeError: Cannot read property 'type' of undefined

这是我的组件安装看起来像这样:

componentDidMount() {

console.log(this.state.loading);
if (this.state.loading === false) {
  const {options} = this.state;
  const node = ReactDOM.findDOMNode(this);
  if (node instanceof HTMLElement) {
    var chart = new ApexCharts(node.querySelector('.charty'), options);
    chart.render().then(() => {
      setTimeout(function() {
        chart.dataURI().then(uri => {
          console.log(uri);
        });
      }, 4000);
    });
  }
} else {
  return;
}
}
Run Code Online (Sandbox Code Playgroud)

类型也在我的状态和渲染中定义,如下所示:

    <div className='rfe'>
      <div className='rfea'>
        From {this.state.AxisMonth[0]} to{' '}
        {this.state.AxisMonth[this.state.AxisMonth.length - 1]}
      </div>
      <Chart
        className='charty'
        type='area'
        options={this.state.options}
        series={this.state.series}
        width='1000'
        height='380'
      />
    </div>
  </div>
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误

在此输入图像描述

确实需要帮助。

jun*_*ipa 5

您可以使用该exec函数从 React 组件调用 ApexCharts 的任何方法。

 getDataUri() {
    ApexCharts.exec("basic-bar", "dataURI").then(({ imgURI, blob }) => {
      console.log(imgURI);
    });
  }
Run Code Online (Sandbox Code Playgroud)

这是一个完整的codeandbox示例