Skip to content

Commit e8e8457

Browse files
committed
refactor : BarChart2 Constant 처리 개선
1 parent 2f4ecec commit e8e8457

File tree

2 files changed

+63
-61
lines changed

2 files changed

+63
-61
lines changed

src/chart/BarChartNegative.tsx

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,5 @@
1-
import { ChartOptions } from "chart.js";
21
import { Bar } from "react-chartjs-2";
3-
4-
const data = {
5-
labels: ["KRW"],
6-
datasets: [
7-
{
8-
data: [-1750000000000.0],
9-
backgroundColor: function (context: any) {
10-
const chart = context.chart;
11-
const { ctx, chartArea } = chart;
12-
13-
if (!chartArea) {
14-
return null;
15-
}
16-
17-
const gradient = ctx.createLinearGradient(
18-
0,
19-
chartArea.top,
20-
0,
21-
chartArea.bottom
22-
);
23-
gradient.addColorStop(0, "#015F8C"); // 그라데이션 시작 색상
24-
gradient.addColorStop(1, "#151C26"); // 그라데이션 끝 색상
25-
26-
return gradient;
27-
},
28-
borderColor: "#FFB3BA",
29-
borderWidth: 2,
30-
barThickness: 60, // 막대의 두께 조정
31-
// maxBarThickness: 30, // 막대의 최대 두께
32-
},
33-
],
34-
};
35-
36-
const options: ChartOptions<"bar"> = {
37-
plugins: {
38-
legend: {
39-
display: false, // 범례를 숨김
40-
},
41-
title: {
42-
display: true,
43-
text: "Assets Base Run",
44-
},
45-
},
46-
scales: {
47-
y: {
48-
beginAtZero: true,
49-
min: -1750000000000,
50-
max: 0,
51-
ticks: {
52-
stepSize: 250000000000,
53-
callback: function (value) {
54-
return value.toLocaleString("ko-KR", {
55-
minimumFractionDigits: 2,
56-
maximumFractionDigits: 2,
57-
});
58-
},
59-
},
60-
},
61-
},
62-
};
2+
import { data, options } from "../data/BarChartNegativeConstant";
633

644
const BarChartNegative = ({ chartRef }: { chartRef: React.RefObject<any> }) => {
655
return <Bar ref={chartRef} data={data} options={options} />;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { ChartOptions } from "chart.js";
2+
3+
export const data = {
4+
labels: ["USD"],
5+
datasets: [
6+
{
7+
data: [-1750000000.0], // 데이터 값 설정
8+
backgroundColor: function (context: any) {
9+
const chart = context.chart;
10+
const { ctx, chartArea } = chart;
11+
12+
if (!chartArea) {
13+
return null;
14+
}
15+
16+
// 그라데이션 설정
17+
const gradient = ctx.createLinearGradient(
18+
0,
19+
chartArea.top,
20+
0,
21+
chartArea.bottom
22+
);
23+
gradient.addColorStop(0, "#015F8C"); // 그라데이션 시작 색상
24+
gradient.addColorStop(1, "#151C26"); // 그라데이션 끝 색상
25+
26+
return gradient;
27+
},
28+
borderColor: "#FFB3BA",
29+
borderWidth: 2,
30+
barThickness: 60, // 막대 두께 설정
31+
// maxBarThickness: 30, // 막대의 최대 두께
32+
},
33+
],
34+
};
35+
36+
export const options: ChartOptions<"bar"> = {
37+
plugins: {
38+
legend: {
39+
display: false, // 범례 숨김
40+
},
41+
title: {
42+
display: true,
43+
text: "Assets Base Run",
44+
},
45+
},
46+
scales: {
47+
y: {
48+
beginAtZero: true,
49+
min: -1750000000,
50+
max: 0,
51+
ticks: {
52+
stepSize: 250000000,
53+
callback: function (value) {
54+
return value.toLocaleString("en-US", {
55+
minimumFractionDigits: 2,
56+
maximumFractionDigits: 2,
57+
});
58+
},
59+
},
60+
},
61+
},
62+
};

0 commit comments

Comments
 (0)