【问题标题】:WebDataRock TypeError: Cannot read property element of nullWebDataRock TypeError:无法读取 null 的属性元素
【发布时间】:2021-06-02 18:35:58
【问题描述】:

WebDataRock TypeError:无法读取 nul 的属性“元素” 和 WebDataRocks:无法绘制枢轴。

问候。

我尝试在我的 react-app 项目中实现 WebDataRocks,我可以实现 WebDataRock.Pivot 组件,但由于开始渲染组件,控制台打印此消息

webdatarocks.js:180 Uncaught TypeError: Cannot read property 'element' of null 在新 e (webdatarocks.js:180) 在 b.setControls (webdatarocks.js:1006) 在 webdatarocks.js:992

几秒钟后控制台打印出这个:

index.js:1 WebDataRocks: 无法绘制枢轴。

    import React from "react";
         import ReactDOM from "react-dom";
         import WebDataRocks from "webdatarocks";
     
         export class Pivot extends React.Component<WebDataRocks.Params, any> {
         webdatarocks: WebDataRocks.Pivot;
         
         componentDidMount() {
            const tempProps : any = this.props;
            const pivotData = tempProps.pivotData;
            const columnsData : any[] = tempProps.columnsData;
     
            const tempColums = [];
            const tempKeys = [];
     
            columnsData.forEach(cd => {
                const tempLabelColumn = cd.title;
                tempColums.push(tempLabelColumn);
                tempKeys.push(cd.key);
            });
     
            this.webdatarocks = new WebDataRocks({
                toolbar: true,
                report: {
                    dataSource: {
                        data: pivotData
                    },
                    slice: {
                        rows: tempKeys,
                        expands: {
                            expandAll: true
                        },
                        measures: [{
                            "uniqueName": "Price",
                            "aggregation": "sum",
                            "format": "currency"
                        }, {
                            "uniqueName": "Discount",
                            "aggregation": "sum",
                            "format": "currency"
                        }],
                        columns: tempColums,
                    },
                    options: {
                        "grid": {
                            "type": "flat"
                        },
                    },
                    formats: [{
                        "name": "",
                        "thousandsSeparator": " ",
                        "decimalSeparator": ".",
                        "decimalPlaces": 2,
                        "maxSymbols": 20,
                        "currencySymbol": "",
                        "currencySymbolAlign": "left",
                        "nullValue": " ",
                        "infinityValue": "Infinity",
                        "divideByZeroValue": "Infinity"
                    }]
                },
                container: ReactDOM.findDOMNode(this)
            });
         }
     
         componentWillUnmount() {
            // console.log('componentWillUnmount this.webdatarocks', this.webdatarocks.dispose);
            if (this.webdatarocks.dispose) {
                 // this code break the system
                // this.webdatarocks.dispose();
            }
         }
         
         shouldComponentUpdate() {
            return false;
         }
     
           render() {`enter code here`
            return <div>Pivot</div>;
           }
         }
     
         export default Pivot;

这是我的回应。

有人可以帮我解决这个问题吗?

谢谢,感谢任何帮助。

【问题讨论】:

    标签: javascript reactjs data-analysis webdatarocks


    【解决方案1】:

    此错误表示 WebDataRocks 找不到应初始化的 DOM 元素。我尝试了以下 GitHub 示例:https://github.com/WebDataRocks/pivot-react/tree/master/typescript,它对我来说效果很好。看来你的代码示例也是基于它的。

    我对您的建议如下:首先将您的业务逻辑与 WebDataRocks 组件代码分开。这是 vanilla WebDataRocks 和您的 React 应用程序之间的代理代码:https://github.com/WebDataRocks/pivot-react/blob/master/typescript/src/webdatarocks/webdatarocks.react.tsx。您可以将其用作创建自定义 WebDataRocks 可视化的基本组件。因此,应该修改的情况并不多。

    这里是客户端代码示例,您可以在其中初始化 WebDataRocks 报告和其他配置:https://github.com/WebDataRocks/pivot-react/blob/master/typescript/src/App.tsx。

    【讨论】:

      猜你喜欢
      • 2020-01-29
      • 2022-01-12
      • 2021-12-04
      • 2021-12-17
      • 2022-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-10
      相关资源
      最近更新 更多