ChartDoughnut.js 2.29 KB
Newer Older
Spark's avatar
layout    
Spark committed
1
import React from 'react'
Spark's avatar
Spark committed
2
import {  Row, Card } from 'react-bootstrap';
Spark's avatar
layout    
Spark committed
3
4
5
import { Doughnut } from 'react-chartjs-2'

function ChartDoughnut() {
6
    const cardstyled = {
Spark's avatar
layout    
Spark committed
7
8
9
10
11
        margin: 'auto',
        padding: '1em',
        display: 'flex',
        justifyContent: 'center',
        width: '100%',
12
        borderWidth: '3px',
13
        borderRadius: '20px',
14
15
        borderColor: 'rgb(110, 189, 142)',
        color: '#04AB70'
Spark's avatar
layout    
Spark committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
    }

    const options = {
        legend: {
            display: true, // label 보이기 여부
        },
        scales: {
            yAxes: [{
                ticks: {
                    min: 0, // y축 스케일에 대한 최소값 설정
                    stepSize: 1, // y축 그리드 한 칸당 수치
                }
            }]
        },

        // false : 사용자 정의 크기에 따라 그래프 크기가 결정됨.
        // true : 크기가 알아서 결정됨.
        maintainAspectRatio: false
    }
    const data = {
        labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        datasets: [
          {
            label: '온도',
            fill: false,
            lineTension: 0.1,
            backgroundColor: 'rgba(75,192,192,0.4)',
            borderColor: 'rgba(75,192,192,1)',
            borderCapStyle: 'butt',
            borderDash: [2,10], //점선
            borderDashOffset: 0.0,
            borderJoinStyle: 'miter',
            pointBorderColor: 'rgba(75,192,192,1)',
            pointBackgroundColor: '#fff',
            pointBorderWidth: 1,
            pointHoverRadius: 5,
            pointHoverBackgroundColor: 'rgba(75,192,192,1)',
            pointHoverBorderColor: 'rgba(220,220,220,1)',
            pointHoverBorderWidth: 2,
            pointRadius: 1,
            pointHitRadius: 10,
            data: [-10, -2, 13, 18, 22, 25, 31, 28, 25, 18, 6, -8]
          }
        ]
      };

    return (

        <>
            <Row className='text-center w-100 my-2'>
66
                <Card style={cardstyled}>
Spark's avatar
layout    
Spark committed
67
68
69
70
71
72
73
74
75
76
77
78
                    <Doughnut
                        data={data}
                        options={options}
                        height={300}
                    />
                </Card>
            </Row>
        </>
    )
}

export default ChartDoughnut;