Framework/React

[React] apexcharts legend ๋ฒ”๋ก€ padding ์กฐ์ ˆํ•˜๋Š” ๋ฐฉ๋ฒ•

yuri lee 2023. 3. 9. 01:05
๋ฐ˜์‘ํ˜•

Intro

์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” apexcharts ์—์„œ legend(๋ฒ”๋ก€) padding์„ ์กฐ์ ˆํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ œ ๊ฒฝ์šฐ ์•„๋ž˜์˜ ์ฐจํŠธ legend ๋ฒ”๋ก€๊ฐ€ ๊ธฐ์ค€ ์ขŒํ‘œ์— ๋น„ํ•ด ๋„ˆ๋ฌด ์™ผ์ชฝ์œผ๋กœ ์น˜์šฐ์ณ์ ธ ์žˆ์–ด์„œ left-padding์œผ๋กœ ํ•ด๊ฒฐํ•˜๊ณ  ์‹ถ์—ˆ์Šต๋‹ˆ๋‹ค.

First try

์šฐ์„  ์ €๋Š”apexchart lengend ์˜ ์†์„ฑ์— padding ์†์„ฑ ์œ ๋ฌด๊ฐ€ ์žˆ๋Š”์ง€ ๊ฒ€์ƒ‰ํ•ด๋ดค์Šต๋‹ˆ๋‹ค. apexChart ๋‚ด legend ์†์„ฑ์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. padding ๊ด€๋ จ ์†์„ฑ์ด ์—†๋Š” ๊ฒƒ ๊ฐ™์•˜์Šต๋‹ˆ๋‹ค.

  legend: {
      show: true,
      showForSingleSeries: false,
      showForNullSeries: true,
      showForZeroSeries: true,
      position: 'bottom',
      horizontalAlign: 'center', 
      floating: false,
      fontSize: '14px',
      fontFamily: 'Helvetica, Arial',
      fontWeight: 400,
      formatter: undefined,
      inverseOrder: false,
      width: undefined,
      height: undefined,
      tooltipHoverFormatter: undefined,
      customLegendItems: [],
      offsetX: 0,
      offsetY: 0,
      labels: {
          colors: undefined,
          useSeriesColors: false
      },
      markers: {
          width: 12,
          height: 12,
          strokeWidth: 0,
          strokeColor: '#fff',
          fillColors: undefined,
          radius: 12,
          customHTML: undefined,
          onClick: undefined,
          offsetX: 0,
          offsetY: 0
      },
      itemMargin: {
          horizontal: 5,
          vertical: 0
      },
      onItemClick: {
          toggleDataSeries: true
      },
      onItemHover: {
          highlightDataSeries: true
      },
  }

 

Second try

๊ฐœ๋ฐœ์ž ๋„๊ตฌ ํƒญ์—์„œ legend element๋ฅผ ์ฐพ์•„๋ดค๋Š”๋ฐ์š”, ์•„๋ž˜์˜ css๊ฐ€ ์ ์šฉ๋˜์–ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. 

.apexcharts-legend {
    display: flex;
    overflow: auto;
    padding: 0 10px;
}

ํ•ด๋‹น ๋ถ€๋ถ„์„ ํ™œ์šฉํ•˜์—ฌ css ์กฐ์ ˆ์„ ํ•˜๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ, ์ž˜ ์•ˆ๋˜๋”๋ผ๊ณ ์š”. ๐Ÿฅฒ 

 

How to solve the problem

๊ทธ๋ž˜์„œ ์ฒซ๋ฒˆ์งธ ์‹œ๋„๋กœ ๋‹ค์‹œ ๋Œ์•„๊ฐ€์„œ legend ์˜ต์…˜์„ ์ž์„ธํžˆ ์‚ดํŽด๋ดค์Šต๋‹ˆ๋‹ค. 

 

offsetX: Number

Sets the left offset for legend container
legend: {
    offsetX: 5,
},

์„ค๋ช…์„ ๋ณด๊ณ , ์ ์šฉ์ด ๋  ๊ฒƒ ๊ฐ™์•„์„œ ํ˜น์‹œ ๋ชฐ๋ผ ์œ„ ์˜ต์…˜์„ ์ ์šฉํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•ด๋ดค๋Š”๋ฐ์š”, legend (๋ฒ”๋ก€)๊ฐ€ ๋”ฑ ์ œ๊ฐ€ ์›ํ•˜๋Š” UI์— ๋งž์ถฐ ์ž˜ ๋‚˜์˜ค๋”๋ผ๊ณ ์š”.

 

Conclusion

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ์ œ๊ณตํ•˜๋Š” ์˜ต์…˜์€ ์ œ๋Œ€๋กœ ์ž˜ ์‚ดํŽด๋ด์•ผ ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๐Ÿ˜‚

 


https://apexcharts.com/docs/options/legend/

๋ฐ˜์‘ํ˜•