ChartTemp.js 1.54 KB
Newer Older
Spark's avatar
Spark committed
1
import React from "react";
KangMin An's avatar
KangMin An committed
2
3
import { Col } from "react-bootstrap";
import { Bar } from "react-chartjs-2";
Spark's avatar
Spark committed
4
function ChartTemp({ temp, newLabel }) {
Spark's avatar
Spark committed
5

KangMin An's avatar
KangMin An committed
6
7
8
9
10
11
12
13
14
15
16
  const options = {
    legend: {
      display: true, // label 보이기 여부
    },
    scales: {
      yAxes: [
        {
          ticks: {
            min: 0, // y축 스케일에 대한 최소값 설정
            stepSize: 0.5, // y축 그리드 한 칸당 수치
          },
Spark's avatar
chartjs    
Spark committed
17
        },
KangMin An's avatar
KangMin An committed
18
19
      ],
    },
Spark's avatar
chartjs    
Spark committed
20

KangMin An's avatar
KangMin An committed
21
22
23
24
25
    // false : 사용자 정의 크기에 따라 그래프 크기가 결정됨.
    // true : 크기가 알아서 결정됨.
    maintainAspectRatio: false,
  };
  const data = {
KangMin An's avatar
KangMin An committed
26
    labels: newLabel,
KangMin An's avatar
KangMin An committed
27
28
29
30
31
32
33
34
35
36
37
38
    datasets: [
      {
        label: "온도",
        borderWidth: "2",
        data: temp,
        borderColor: [
          "rgba(75,192,192,1)",
          "rgba(75,192,192,1)",
          "rgba(75,192,192,1)",
          "rgba(75,192,192,1)",
          "rgba(75,192,192,1)",
          "rgba(75,192,192,1)",
Spark's avatar
chartjs    
Spark committed
39

KangMin An's avatar
KangMin An committed
40
41
42
43
          "rgba(191,191,191,1)",
          "rgba(191,191,191,1)",
          "rgba(191,191,191,1)",
        ],
Spark's avatar
chartjs    
Spark committed
44

KangMin An's avatar
KangMin An committed
45
        backgroundColor: [
KangMin An's avatar
KangMin An committed
46
47
48
49
50
51
          "rgba(75,192,192,0.1)",
          "rgba(75,192,192,0.1)",
          "rgba(75,192,192,0.1)",
          "rgba(75,192,192,0.1)",
          "rgba(75,192,192,0.1)",
          "rgba(75,192,192,0.1)",
Spark's avatar
Spark committed
52

KangMin An's avatar
KangMin An committed
53
54
55
          "rgba(191,191,191,0.1)",
          "rgba(191,191,191,0.1)",
          "rgba(191,191,191,0.1)",
KangMin An's avatar
KangMin An committed
56
57
58
59
        ],
      },
    ],
  };
Spark's avatar
Spark committed
60

KangMin An's avatar
KangMin An committed
61
62
63
64
65
66
  return (
    <Col id="chartTab">
      <Bar data={data} options={options} />
    </Col>
  );
}
Spark's avatar
chartjs    
Spark committed
67

KangMin An's avatar
KangMin An committed
68
export default ChartTemp;