【发布时间】:2021-07-25 04:56:20
【问题描述】:
我正在使用 Recharts 在 react 中绘制数据。
我希望能够在绘图过程中看到所有四个笛卡尔象限。我目前正在使用此代码,
import React, { PureComponent } from 'react';
import { ScatterChart, Scatter, XAxis, YAxis, CartesianGrid, Tooltip, Cell, ResponsiveContainer } from 'recharts';
import { scaleOrdinal } from 'd3-scale';
import { schemeCategory10 } from 'd3-scale-chromatic';
const colors = scaleOrdinal(schemeCategory10).range();
const data = [
{ x: -100, y: 200, z: 200 },
{ x: -120, y: 100, z: 260 },
{ x: -170, y: 300, z: 400 },
{ x: 140, y: 250, z: 280 },
{ x: 150, y: 400, z: 500 },
{ x: 110, y: 280, z: 200 },
];
export default class Baseline extends PureComponent {
static demoUrl = 'https://codesandbox.io/s/scatter-chart-with-cells-2sk2o';
render() {
return (
<ResponsiveContainer width="100%" height="100%">
<ScatterChart
width={400}
height={400}
margin={{
top: 20,
right: 20,
bottom: 20,
left: 20,
}}
>
<CartesianGrid />
<XAxis type="number" dataKey="x" name="stature" unit="cm" />
<YAxis type="number" dataKey="y" name="weight" unit="kg" />
<Tooltip cursor={{ strokeDasharray: '3 3' }} />
<Scatter name="A school" data={data} fill="#8884d8">
{data.map((entry, index) => (
<Cell key={`cell-${index}`} fill={colors[index % colors.length]} />
))}
</Scatter>
</ScatterChart>
</ResponsiveContainer>
);
}
}
我的目标是近似于这个,
recharts 是最好的主意还是有可能?喜欢任何例子:)
【问题讨论】:
-
只是为了澄清。截至目前,您正在获得 +ve x 和 y 轴,但您还需要 -ve x 和 y 轴。
-
是的,没错
-
我之前用echarts.apache.org/examples/en/editor.html?c=scatter-clustering 完成了它——你可以用它作为参考。
标签: javascript reactjs d3.js recharts