Skip to content

Commit

Permalink
fix : rechart 가운데 정렬
Browse files Browse the repository at this point in the history
  • Loading branch information
moana16 committed Apr 13, 2023
1 parent ace1902 commit 44f4e98
Showing 1 changed file with 65 additions and 55 deletions.
120 changes: 65 additions & 55 deletions src/popup/PieChartComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,69 @@
import React, { useState } from "react";
import React, { useState } from 'react';
import { PieChart, Pie, Legend, Sector, Cell, ResponsiveContainer } from 'recharts';


const PieChartComponent = () => {

const data = [
{ name: '진보', value: 700 },
{ name: '보수', value: 500 },
];

const COLORS = ['#0088FE', '#00C49F'];

const RADIAN = Math.PI / 180;
const renderCustomizedLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, percent, index }: any) => {
const radius = innerRadius + (outerRadius - innerRadius) * 0.5;
const x = cx + radius * Math.cos(-midAngle * RADIAN);
const y = cy + radius * Math.sin(-midAngle * RADIAN);

return (
<text x={x} y={y} fill="white" textAnchor={x > cx ? 'start' : 'end'} dominantBaseline="central">
{`${(percent * 100).toFixed(0)}%`}
</text>
);
};
const data = [
{ name: '진보', value: 700 },
{ name: '보수', value: 500 },
];

const COLORS = ['#0088FE', '#00C49F'];

const RADIAN = Math.PI / 180;
const renderCustomizedLabel = ({
cx,
cy,
midAngle,
innerRadius,
outerRadius,
percent,
index,
}: any) => {
const radius = innerRadius + (outerRadius - innerRadius) * 0.5;
const x = cx + radius * Math.cos(-midAngle * RADIAN);
const y = cy + radius * Math.sin(-midAngle * RADIAN);

return (
<>
<div>
<div className="row d-flex justify-content-center text-center">
<h1>Favorite Beverages - technostuf.com</h1>
<hr />
<div className="col-md-8">
<ResponsiveContainer width={400} height={400} className="text-center">
<PieChart width={400} height={400}>
<Legend layout="vertical" verticalAlign="top" />
<Pie
data={data}
cx="50%"
cy="50%"
labelLine={false}
label={renderCustomizedLabel}
outerRadius={80}
fill="#8884d8"
dataKey="value"
>
{data.map((entry, index) => (
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
))}
</Pie>
</PieChart>
</ResponsiveContainer>
</div>
</div>
</div>
</>
)
}
export default PieChartComponent;
<text
x={x}
y={y}
fill="white"
textAnchor={x > cx ? 'start' : 'end'}
dominantBaseline="central"
>
{`${(percent * 100).toFixed(0)}%`}
</text>
);
};

return (
<>
<div>
<div className="row d-flex justify-content-center text-center">
<div className="col-md-8">
<ResponsiveContainer width={500} height={400} className="text-center">
<PieChart width={500} height={400}>
<Legend layout="vertical" verticalAlign="top" />
<Pie
data={data}
cx="50%"
cy="50%"
labelLine={false}
label={renderCustomizedLabel}
outerRadius={80}
fill="#8884d8"
dataKey="value"
>
{data.map((entry, index) => (
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
))}
</Pie>
</PieChart>
</ResponsiveContainer>
</div>
</div>
</div>
</>
);
};
export default PieChartComponent;

0 comments on commit 44f4e98

Please sign in to comment.