September 07, 2021
npm install --save react-chartjs-2 chart.js
import { Line } from 'react-chartjs-2'
const Graph = ({ graphData }) => {
return (
<Wrapper>
<Position>
<Line />
</Position>
</Wrapper>
)
}
//...styled component 부분 생략
import { Line } from 'react-chartjs-2'
const Graph = ({ graphData }) => {
return (
<Wrapper>
<Position>
<Line width="10vw" height="3.5vh" />
</Position>
</Wrapper>
)
}
//...styled component 부분 생략
const data = () => {
labels: [1, 2, 3, 4, 5]
datasets: [
{
data: [100, 200, 300, 400, 500]
fill: true,
backgroundColor: ''rgba(225,116,103,0.2)',
borderColor: 'rgba(225,116,103)',
borderWidth: 1,
color: '#000'
}
]
}
import { Line } from 'react-chartjs-2';
const Graph = ({ graphData }) => {
const data = () => {
labels: [1, 2, 3, 4, 5, 6],
datasets: [
{
data: [330000, 460000, 500000, 600000, 500000, 600000],
fill: true,
backgroundColor: ''rgba(225,116,103,0.2)',
borderColor: 'rgba(225,116,103)',
borderWidth: 1,
color: '#000'
}
]
}
return (
<Wrapper>
<Position>
<Line width="10vw" height="3.5vh" data={data} />
</Position>
</Wrapper>
);
}
import { Line } from 'react-chartjs-2';
const Graph = ({ graphData }) => {
const data = (canvas) => {
const ctx = canvas.getContext('2d');
const gradientFill = ctx.createLinearGradient(0,0,0,200);
gradientFill.addColorStop(0, 'rgba(225,116,116,0.5)');
gradientFill.addColorStop(1, 'rgba(225,116,116,0.1)');
labels: [1, 2, 3, 4, 5]
datasets: [
{
data: [100, 200, 300, 400, 500]
fill: true,
backgroundColor: ''rgba(225,116,103,0.2)',
borderColor: 'rgba(225,116,103)',
borderWidth: 1,
color: '#000'
}
]
}
return (
<Wrapper>
<Position>
<Line width="10vw" height="3.5vh" data={canvas => data(canvas)} />
</Position>
</Wrapper>
);
}
const options = {
plugins: {
legend: { display: false }, // 라벨 숨기기
tooltip: {
// 툴팁 속성 설정
backgroundColor: 'rgba(255, 255, 255)',
titleColor: 'rgba(225,116,103)',
bodyColor: 'rgba(0,0,0)',
caretSize: 0,
displayColors: false,
boxWidth: '100px',
borderColor: 'rgba(225,116,103)',
borderWidth: 1,
},
},
elements: {
point: {
// 그래프 꼭짓점 모양
pointStyle: 'star',
radius: 2,
},
},
scales: {
x: { display: false }, // x축 보이지 않음
y: {
grid: { display: false, drawBorder: false }, //y축 선 없애기
position: 'right', // y축 오른쪽에 위치시키기
ticks: { color: `#a0a0a0` }, // y축 글자색 변경
},
},
animation: {
duration: 0, // 애니메이션 삭제
},
}