|
1 | | -import { ChartData, ChartOptions } from "chart.js"; |
2 | 1 | import ChartDataLabels from "chartjs-plugin-datalabels"; |
3 | 2 | import React from "react"; |
4 | 3 | import { Bar } from "react-chartjs-2"; |
5 | | -import { formatNumberWithCommas } from "../utils/numberUtils"; |
6 | | - |
7 | | -const data: ChartData<"bar"> = { |
8 | | - labels: [ |
9 | | - "보험", |
10 | | - "금리", |
11 | | - "신용", |
12 | | - "시장", |
13 | | - "운영", |
14 | | - "비금융", |
15 | | - "차이", |
16 | | - "요구자본", |
17 | | - ], |
18 | | - datasets: [ |
19 | | - { |
20 | | - label: "Waterfall", |
21 | | - data: [ |
22 | | - [0, 6489], |
23 | | - [6489, 6489 + 11188], |
24 | | - [6489 + 11188, 6489 + 11188 + 24523], |
25 | | - [6489 + 11188 + 24523, 6489 + 11188 + 24523 + 4086], |
26 | | - [6489 + 11188 + 24523 + 4086, 6489 + 11188 + 24523 + 4086 + 1435], |
27 | | - [ |
28 | | - 6489 + 11188 + 24523 + 4086 + 1435, |
29 | | - 6489 + 11188 + 24523 + 4086 + 1435 + 1406, |
30 | | - ], |
31 | | - [ |
32 | | - 6489 + 11188 + 24523 + 4086 + 1435 + 1406, |
33 | | - 6489 + 11188 + 24523 + 4086 + 1435 + 1406 - 9752, |
34 | | - ], |
35 | | - [6489 + 11188 + 24523 + 4086 + 1435 + 1406 - 9752 - 39375, 39375], |
36 | | - ], |
37 | | - backgroundColor: function (context: { dataset: any; dataIndex: number }) { |
38 | | - const value = context.dataset.data[context.dataIndex]; |
39 | | - |
40 | | - // 마지막 차트는 보라색, 나머지는 양수는 녹색, 음수는 빨간색 |
41 | | - if (context.dataIndex === context.dataset.data.length - 1) { |
42 | | - return "#B798C5"; // 보라색 |
43 | | - } |
44 | | - |
45 | | - return value[1] >= value[0] ? "#B8EFEF" : "#FBADB0"; // 양수는 녹색, 음수는 빨간색 |
46 | | - }, |
47 | | - // borderColor: "#000000", |
48 | | - // borderWidth: 1, |
49 | | - }, |
50 | | - ], |
51 | | -}; |
52 | | - |
53 | | -const options: ChartOptions<"bar"> = { |
54 | | - plugins: { |
55 | | - legend: { |
56 | | - display: false, // 범례 숨김 |
57 | | - }, |
58 | | - title: { |
59 | | - display: true, |
60 | | - text: "기준월 요구자본 세부", |
61 | | - }, |
62 | | - datalabels: { |
63 | | - color: "black", // 막대 안에서 읽기 쉽게 글자색을 흰색으로 설정 |
64 | | - anchor: "center", // 글자가 막대 안에서 중앙에 배치되도록 설정 |
65 | | - align: "center", // 가운데 정렬 |
66 | | - formatter: function (value: number[], context: any) { |
67 | | - return (value[1] - value[0]).toLocaleString("ko-KR"); |
68 | | - }, |
69 | | - }, |
70 | | - }, |
71 | | - scales: { |
72 | | - x: { |
73 | | - stacked: true, // 누적 설정 |
74 | | - ticks: { |
75 | | - maxRotation: 0, // X축 레이블을 기울이지 않음 |
76 | | - minRotation: 0, // X축 레이블 최소 회전 설정 |
77 | | - autoSkip: true, // 레이블이 겹칠 경우 자동으로 생략 |
78 | | - }, |
79 | | - }, |
80 | | - y: { |
81 | | - beginAtZero: true, |
82 | | - ticks: { |
83 | | - stepSize: 25000, |
84 | | - callback: function (value) { |
85 | | - const numValue = value as number; |
86 | | - return formatNumberWithCommas(numValue) + "억"; |
87 | | - }, |
88 | | - }, |
89 | | - }, |
90 | | - }, |
91 | | -}; |
| 4 | +import { data, options } from "../data/WaterfallChartConstant"; |
92 | 5 |
|
93 | 6 | const WaterfallChart = ({ chartRef }: { chartRef: React.RefObject<any> }) => { |
94 | 7 | return ( |
|
0 commit comments