-
React/AntV G2plot Chart 적용Language/React 2022. 10. 12. 11:50
Module 추가
$ yarn add @antv/g2plot
https://yarnpkg.com/package/@antv/g2plot
JSX Source
Component base라서 ComponentDidMount 함수에서 적용
import { Pie } from '@antv/g2plot'; class UnitsDashboard extends Component { state = {} setPie = () => { const data = [ { type: '라벨1', value: 27 }, { type: '라벨2', value: 25 }, { type: '라벨3', value: 18 }, { type: '라벨4', value: 15 }, { type: '라벨5', value: 10 }, ]; const piePlot = new Pie('container', { appendPadding: 10, data, angleField: 'value', colorField: 'type', radius: 1, innerRadius: 0.6, label: { type: 'inner', offset: '-50%', content: '{value}', style: { textAlign: 'center', fontSize: 14, }, }, interactions: [{ type: 'element-selected' }, { type: 'element-active' }], statistic: { title: false, content: { style: { whiteSpace: 'pre-wrap', overflow: 'hidden', textOverflow: 'ellipsis', fontSize: 18, }, content: 'AntV\nG2Plot', }, } }); piePlot.render(); piePlot.update(); } componentDidMount() { this.setPie(); window.addEventListener('resize', this.resize.bind(this)); } resize() { if (this.context.isMobile() === true) { console.log('MOBILE'); } else { console.log('PC'); } } componentWillUnmount() { window.removeEventListener("resize", this.resize.bind(this)); } ... render() { ... return ( <> <div id="container"></div> </> ); ) ) ...
참조)
https://g2plot.antv.vision/en/examples/pie/donut#basic
https://g2plot.antv.vision/en/docs/api/options/theme
'Language > React' 카테고리의 다른 글
React/memory leak - componentWillUnmount Event 제거 이슈 (0) 2022.10.19 React/createContext, useContext 사용하기 (0) 2022.10.12 React/Swiper 적용 (0) 2022.10.12 React/Jwt 연동 (access token, refresh token) (0) 2022.08.10 React/nth-check - Dependabot cannot update nth-check to a non-vulnerable version (0) 2022.08.10