gpt4 book ai didi

reactjs - React-d3 图表未显示

转载 作者:行者123 更新时间:2023-12-03 13:58:50 24 4
gpt4 key购买 nike

我已经执行了在 react-d3 中获取图表的分步说明:

http://www.reactd3.org/get_start/

我将其添加到我的代码中,但我什么也没看到。

但是,如果我检查,我确实会看到一个 SVG 标签,其中包含一些内容。

enter image description here

是否有某些元素被展平,或者您是否需要进行一些设置才能在浏览器中显示 SVG?

我的确切代码如下所示:

import React from 'react';

var Chart = require('react-d3-core').Chart;
var LineChart = require('react-d3-basic').LineChart;

class WelcomeView extends React.Component {

render() {

var chartData = [
{"name":"Darron Weissnat IV","BMI":20.72,"age":39,"birthday":"2005-01-03T00:00:00.000Z","city":"East Russel","married":false,"index":0},
{"name":"Guido Conroy","BMI":25.17,"age":39,"birthday":"1977-04-20T00:00:00.000Z","city":"Scarlettland","married":true,"index":20},
{"name":"Miss Demond Weissnat V","BMI":21.44,"age":19,"birthday":"2007-06-09T00:00:00.000Z","city":"Savionberg","married":false,"index":21},
{"name":"Easton Mante","BMI":20.61,"age":43,"birthday":"2007-01-29T00:00:00.000Z","city":"Kutchberg","married":false,"index":22},
{"name":"Dayton Ebert","BMI":29.88,"age":20,"birthday":"1978-04-27T00:00:00.000Z","city":"West Wiley","married":true,"index":23}
]

var width = 700,
height = 300,
margins = {left: 100, right: 100, top: 50, bottom: 50},
title = "User sample",
chartSeries = [
{
field: 'BMI',
name: 'BMI',
color: '#ff7f0e'
}
],
// your x accessor
x = function(d) {
return d.index;
}

return (
<div>
<div>
<Chart
title={title}
width={width}
height={height}
margins= {margins}
>
<LineChart
margins= {margins}
title={title}
data={chartData}
width={width}
height={height}
chartSeries={chartSeries}
x={x}
/>
</Chart>
</div>
</div>
);
}
}

export default WelcomeView;

我认为我正确地遵循了所有内容,所以我不确定我做错了什么。

更新:

如果我在图表元素上方动态添加另一个 SVG 元素,例如圆圈:

<svg height="100" width="100">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
</svg>

然后圆圈出现,并且神奇地添加 SVG 元素启动了图表的渲染过程。

非常困惑为什么会发生这种情况:(

最佳答案

我遵循了相同的步骤,但最初也无法显示它。

但是我注意到的是,在示例代码中,它们列出了 gitHub他们没有将 LineChart 嵌套在 Chart 中(正如他们在说明中所做的那样)。一旦我删除了包含的“图表”,我的图表就出现了。

return (
<LineChart
//showXGrid={false}
//showYGrid={false}
margins= {margins}
title={title}
data={chartData}
width={width}
height={height}
chartSeries={chartSeries}
x={x}
/>
);

关于reactjs - React-d3 图表未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44331565/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com