๐Ÿ‘จ‍๐Ÿ’ป kimtongting
article thumbnail

 

 

 

 

 

 

Chart.js

 

์ด๋ฒˆ์— ์‹ ๊ทœ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๊ฒŒ๋˜์–ด ์‹œ์•ˆ์„ ๋ฐ›์•˜๋‹ค.

๋งค์ถœ์ด๋‚˜ ํ˜„ํ™ฉ ๋“ฑ ์ฃผ๋กœ ๋Œ€์‹œ๋ณด๋“œ์—์„œ ์ž์ฃผ ์“ฐ์ด๋Š” ์ฐจํŠธ๋ฅผ ์‚ฌ์šฉ ํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค.

์•„! ์—ฌ๊ธฐ์—์„œ๋Š” ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค : )

 

 

๋””์ž์ด๋„ˆ๋ถ„๊ป˜ ์ „๋‹ฌ๋ฐ›์€ ์ด๋ฏธ์ง€ ์‹œ์•ˆ

Install

$ npm install chart.js --save

Import

import Chart from 'chart.js/auto';

 

How to Use

function ??? () {

const canvasDom = useRef(null);

    // Dependency array ์— props ์ถ”๊ฐ€ํ•˜๊ณ  return์— chart.destory() ์ถ”๊ฐ€ ์˜ˆ์ •
    useEffect(() => {
        const ctx = canvasDom.current.getContext("2d");
        new Chart(ctx, {
            type: "bar",
            data: {
                labels: ['์›”', 'ํ™”', '์ˆ˜', '๋ชฉ', '๊ธˆ', 'ํ† ', '์ผ' ], // x์ถ• Data
                datasets: [
                    {
                        data: [750, 640, 240, 200, 160, 400, 600], // y์ถ• Data
                        borderWidth : 1,			//Bar์— border width ๊ฐ’
                        barPercentage : 0.7,		//Bar์˜ ๋‘๊ป˜

                    },
                ],
            },
            options: {
                backgroundColor : "#9ac6ff",		//Bar์˜ ์ƒ‰์ƒ
            }
        });
    }, []);

	return (
    	<div>
       		<div className="chart-container">
       	 		<canvas ref={canvasDom} height="180"></canvas>
        	</div>
        </div>
    );
    
}

 

Result

์ขŒ์ธก : ์‹œ์•ˆ / ์šฐ์ธก : ๋งŒ๋“ ๊ฑฐ

๋งˆ๋ฌด๋ฆฌ

์‹œ์•ˆ์„ ์ด๋ฏธ์ง€ ํŒŒ์ผ๋กœ ๋ฐ›์•˜๊ธฐ ๋•Œ๋ฌธ์—, ๋””์ž์ด๋„ˆ๋ถ„๊ณผ ํ˜‘์˜ํ•˜๋ฉด์„œ ์„ธ๋ถ€์ ์ธ ์กฐ์ ˆ๋งŒ ํ•˜๋ฉด ๋  ๋“ฏ ํ•˜๋‹ค.

ํ—ท๊ฐˆ๋ฆฌ์‹œ๋Š” ๋ถ„๋“ค์€ ๋ฌด์ž‘์ • ๋”ฐ๋ผํ•ด๋ณด์‹œ๊ธธ ์ถ”์ฒœํ•œ๋‹ค.

 

 

 

 

 

 

 

 

๋ฐ˜์‘ํ˜•
profile

๐Ÿ‘จ‍๐Ÿ’ป kimtongting

@kimtongting ์ž…๋‹ˆ๋‹ค

ํฌ์ŠคํŒ…์ด ์ข‹์•˜๋‹ค๋ฉด "์ข‹์•„์š”โค๏ธ" ๋˜๋Š” "๊ตฌ๋…๐Ÿ‘๐Ÿป" ํ•ด์ฃผ์„ธ์š”!