-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat/#74 랭킹 차트 적용하기
- Loading branch information
Showing
8 changed files
with
468 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import ApexCharts from "react-apexcharts"; | ||
|
||
type chartDataProp = { | ||
ranklabel: string[]; | ||
rankdata: number[]; | ||
chartnumber: number; | ||
}; | ||
export default function BarChart({ | ||
ranklabel, | ||
rankdata, | ||
chartnumber, | ||
}: chartDataProp) { | ||
const dataSet = []; | ||
for (let n in ranklabel) { | ||
dataSet.push({ x: ranklabel[n], y: rankdata[n] }); | ||
} | ||
const graphType = chartnumber === 1 ? "bar" : "pie"; | ||
return ( | ||
<ApexCharts | ||
type={"bar"} | ||
height={"250"} | ||
series={[ | ||
{ | ||
name: "검색수", | ||
data: dataSet, | ||
}, | ||
]} | ||
options={{ | ||
theme: { | ||
mode: "light", | ||
}, | ||
chart: { | ||
toolbar: { | ||
show: false, | ||
}, | ||
height: "100%", | ||
background: "transparent", | ||
zoom: { | ||
enabled: false, | ||
}, | ||
}, | ||
plotOptions: { | ||
bar: { | ||
horizontal: false, | ||
borderRadius: 4, | ||
columnWidth: " 50", | ||
barHeight: "100%", | ||
distributed: true, | ||
}, | ||
}, | ||
dataLabels: { | ||
style: { | ||
colors: ["#fff"], | ||
}, | ||
}, | ||
xaxis: { | ||
categories: ranklabel, | ||
type: "category", | ||
labels: { | ||
style: { | ||
colors: "#fff", | ||
}, | ||
}, | ||
title: { | ||
text: "Flower", | ||
offsetY: 140, | ||
offsetX: -20, | ||
style: { | ||
color: "#fff", | ||
}, | ||
}, | ||
}, | ||
yaxis: { | ||
labels: { | ||
formatter: function (val) { | ||
return val + "회"; | ||
}, | ||
style: { | ||
colors: "#fff", | ||
}, | ||
}, | ||
title: { | ||
text: "조회수", | ||
rotate: 0, | ||
offsetY: -100, | ||
offsetX: 25, | ||
style: { | ||
fontSize: "12", | ||
color: "#fff", | ||
}, | ||
}, | ||
}, | ||
title: { | ||
text: "검색랭킹", | ||
align: "center", | ||
style: { | ||
color: "#fff", | ||
}, | ||
}, | ||
|
||
colors: [ | ||
"#4ecdc4", | ||
"#c7f464", | ||
"#f9a3a4", | ||
"#f46036", | ||
"#00b1f2", | ||
"#13D8AA", | ||
], | ||
|
||
stroke: { | ||
curve: "smooth", | ||
width: 1, | ||
}, | ||
legend: { | ||
labels: { | ||
colors: ["#fff"], | ||
}, | ||
}, | ||
responsive: [ | ||
{ | ||
breakpoint: 1000, | ||
options: { | ||
yaxis: { | ||
labels: { | ||
formatter: function (val: string) { | ||
return val + "회"; | ||
}, | ||
style: { | ||
colors: "#fff", | ||
}, | ||
}, | ||
title: { | ||
text: "조회수", | ||
rotate: 0, | ||
offsetY: -80, | ||
offsetX: 25, | ||
style: { | ||
fontSize: "12", | ||
color: "#fff", | ||
}, | ||
}, | ||
}, | ||
Xaxis: { | ||
title: { | ||
text: "Flower", | ||
offsetY: 85, | ||
offsetX: -20, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import ApexCharts from "react-apexcharts"; | ||
|
||
type chartDataProp = { | ||
ranklabel: string[]; | ||
rankdata: number[]; | ||
chartnumber: number; | ||
}; | ||
export default function PieChart({ | ||
ranklabel, | ||
rankdata, | ||
chartnumber, | ||
}: chartDataProp) { | ||
const dataSet = []; | ||
for (let n in ranklabel) { | ||
dataSet.push({ x: ranklabel[n], y: rankdata[n] }); | ||
} | ||
const graphType = chartnumber === 1 ? "bar" : "pie"; | ||
return ( | ||
<ApexCharts | ||
type="pie" | ||
height={"250em"} | ||
series={rankdata} | ||
options={{ | ||
chart: { | ||
width: "100%", | ||
toolbar: { | ||
show: false, | ||
}, | ||
background: "transparent", | ||
zoom: { | ||
enabled: false, | ||
}, | ||
}, | ||
plotOptions: { | ||
pie: { | ||
expandOnClick: true, | ||
}, | ||
}, | ||
labels: ranklabel, | ||
dataLabels: { | ||
enabled: true, | ||
formatter: function (val, opt) { | ||
if (typeof val === "string") { | ||
val = parseInt(val); | ||
} | ||
val = Math.round(val as number); | ||
return val + "%"; | ||
}, | ||
}, | ||
legend: { | ||
labels: { | ||
colors: ["#fff"], | ||
}, | ||
}, | ||
title: { | ||
text: "검색랭킹", | ||
align: "center", | ||
style: { | ||
color: "#fff", | ||
}, | ||
}, | ||
}} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.