我尝试使用react与react-d3,但我总是会出错,在第一次,我已经使用了react v16,但它请求React v0.14.9。
所以现在我可以在出现错误之前看到图表。
我用过本教程来自于react d3。
将其设置为错误后:
findComponentRoot(..., .0.0.1.0.0.1.0.$/=13.0.$faux-dom-0): Unable to find element. This probably means the DOM was unexpectedly mutated (e.g., by the browser), usually due to forgetting a <tbody> when using tables, nesting tags like <form>, <p>, or <a>, or using non-SVG elements in an <svg> parent. Try inspecting the child nodes of the element with React ID ''.听起来我有一张桌子,但没有,App.js看起来是这样的:
import React, { Component } from 'react';
import './App.css';
import {Chart} from 'react-d3-core';
import {LineChart} from 'react-d3-basic';
class App extends Component {
render() {
var chartData = [
{data: 2000}
]
var width = 700,
height = 300,
margins = {left: 100, right: 100, top: 50, bottom: 50},
title = "User sample",
// chart series,
// field: is what field your data want to be selected
// name: the name of the field that display in legend
// color: what color is the line
chartSeries = [
{
field: 'BMI',
name: 'BMI',
color: '#ff7f0e'
}
],
// your x accessor
x = function(d) {
return d.index;
}
return (
<div className="App">
<Chart
title={title}
width={width}
height={height}
margins= {margins}
>
<LineChart
showXGrid= {false}
showYGrid= {false}
margins= {margins}
title={title}
data={chartData}
width={width}
height={height}
chartSeries={chartSeries}
x={x}
/>
</Chart>
</div>
);
}
}
export default App;
package.json
{
"name": "reactd3",
"version": "0.1.0",
"private": true,
"dependencies": {
"ajv": "^6.5.2",
"babel-loader": "^7.1.5",
"html-webpack-plugin": "^3.2.0",
"react": "^0.14.9",
"react-d3": "^0.4.0",
"react-d3-basic": "^1.6.11",
"react-dom": "^0.14.9",
"react-scripts": "1.1.4",
"style-loader": "^0.21.0",
"webpack": "^4.16.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"webpack-cli": "^3.1.0"
}
}没有理由出现此错误,因为图表没有表形式。
我试过在react16之前使用它,但是没有成功,很多错误.
编辑:现在我们使用d3.js而不是react-d3,它可以工作,但如果有人需要解决这个问题,那就更好了。
发布于 2018-08-03 08:47:18
IMHO此错误与整个应用程序根(html中的“root”)无关,而是一个子组件。
在早期版本的reactid中,呈现的DOM节点由额外的html属性'data-reactid‘标识,其值与虚拟节点路径相关。“.0.0.1.0.0.1.0……”就是一个例子。
此错误意味着react将此节点置于虚拟树中,希望在DOM中更新它,但由于某种原因,DOM节点(之前使用此id呈现)被取消。也许浏览器“修正”了糟糕的html结构?这可以与任何html错误相关,表显示为示例原因。
是否有理由不将未维护的“Reacti-d3”转换为“Reacti-d3-components”?
https://stackoverflow.com/questions/51494093
复制相似问题