繁体   English   中英

将 chartjs-chart-treemap 与 react-chartjs-2 集成

[英]Integrate chartjs-chart-treemap with react-chartjs-2

我想将chartjs-chart-treemap 中的树状图添加到我现有的使用react-chartjs-2 的项目中

我到目前为止尝试过:

import ChartComponent from 'react-chartjs-2';


export default class TreeMap extends React.Component {
    render() {
        return (
            <ChartComponent
                {...this.props}
                ref={ref => this.chartInstance = ref && ref.chartInstance}
                type='treemap'
            />
        );
    }
}

,但是在尝试渲染此组件时我会看到以下错误:

错误:“树状图”不是图表类型。

如何在 React 中使用 chartjs-chart-treemap?

必须将 chartjs-chart-treemap 库导入到组件文件中

import ChartComponent from 'react-chartjs-2';
import 'chartjs-chart-treemap';


export default class TreeMap extends React.Component {
    render() {
        return (
            <ChartComponent
                {...this.props}
                ref={ref => this.chartInstance = ref && ref.chartInstance}
                type='treemap'
            />
        );
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM