Framework/React

[React] react-apexcharts y์ถ• (yaxis) ๋‹จ์œ„ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•

yuri lee 2024. 7. 21. 14:20
๋ฐ˜์‘ํ˜•

Intro

์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” react-apexcharts ์˜ y์ถ• ๋‹จ์œ„๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. 

 

How to solve the problem

๊ธฐ์กด chart options ์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ €์˜ ๊ฒฝ์šฐ y์ถ•์ด ํ™”ํ ๋‹จ์œ„์˜€๊ธฐ ๋•Œ๋ฌธ์— ๋ณด๊ธฐ ์‰ฝ๊ฒŒ ์ž๋ฆฟ์ˆ˜ ํ‘œ์‹œ๊ฐ€ ํ•„์š”ํ–ˆ์Šต๋‹ˆ๋‹ค. 

const options: any = {
    chart: {
        height: 250,
        type: 'bar',
        stacked: false,
        toolbar: false,
        animations: {
            enabled: true,
            easing: 'easeinout',
            speed: 500,
        },
        zoom: {
            enabled: false,
        },
    },
    ...
    yaxis: {
        axisBorder: {
            show: false,
        },
        axisTicks: {
            show: false,
        },
        labels: {
            show: true,
            rotate: 0,
            style: {
                colors: '#666',
                fontSize: '11rem',
                fontFamily: 'SpoqaHanSans, Helvetica, Arial, sans-serif',
            },
        },
    },
};

 

 

์ด๋ฅผ ์œ„ํ•ด formatter์ด๋ผ๋Š” ์†์„ฑ์„ ํ™œ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ toLocaleString ๋ฅผ ํ™œ์šฉํ•ด commas๊ฐ€ ๋ถ™๋„๋ก ์ถ”๊ฐ€ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜์˜ ์ฝ”๋“œ ์ ์šฉ ์‹œ y์ถ•(yaxis)์ด ์ž๋ฆฟ์ˆ˜ ๋ณ„๋กœ ์ž˜ ํ‘œ์‹œ๊ฐ€ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. 

const options: any = {
    chart: {
        height: 250,
        type: 'bar',
        stacked: false,
        toolbar: false,
        animations: {
            enabled: true,
            easing: 'easeinout',
            speed: 500,
        },
        zoom: {
            enabled: false,
        },
    },
    ...
    yaxis: {
        axisBorder: {
            show: false,
        },
        axisTicks: {
            show: false,
        },
        labels: {
            show: true,
            rotate: 0,
            style: {
                colors: '#666',
                fontSize: '11rem',
                fontFamily: 'SpoqaHanSans, Helvetica, Arial, sans-serif',
            },
            formatter: (value: number) => {
                return value.toLocaleString(); 
            },
        },
    },
};

 

 

 


https://apexcharts.com/docs/formatting-axes-labels/

๋ฐ˜์‘ํ˜•