2019.10.08

 

다중 그래프 차트

 

한 canvas에 라인 그래프도 쓰고 바 그래프도 쓰고 싶다면?

 

 

 

 

1
<canvas id="chart"></canvas>
 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
66
67
<script th:inline="javascript">
 
    $(function() {
        var ctx = document.getElementById('chart').getContext('2d');
        var chart = new Chart(ctx, {
            
            // The type of chart we want to create
            type: 'bar',
        
            // The data for our dataset
            data: {
                labels: ['1월','2월','3월','4월','5월','6월'],
                datasets: [{
                    label: '바 그래프',
                    type : 'bar'// 'bar' type, 전체 타입과 같다면 생략가능
                    backgroundColor: 'rgb(255, 204, 102)',
                    borderColor: 'rgb(255, 204, 102)',
                    data: [102030405060]
                }, {
                    label: '라인 그래프1',
                    type : 'line',         // 'line' type
                    fill : false,         // 채우기 없음
                    lineTension : 0.2,  // 0이면 꺾은선 그래프, 숫자가 높을수록 둥글해짐
                    pointRadius : 0,    // 각 지점에 포인트 주지 않음
                    backgroundColor: 'rgb(255, 153, 0)',
                    borderColor: 'rgb(255, 153, 0)',
                    data: [405060708090]
                }, {
                    label: '라인 그래프2',
                    type : 'line',
                    fill : false,
                    lineTension : 0.2,
                    pointRadius : 0,
                    backgroundColor: 'rgb(255, 204, 0)',
                    borderColor: 'rgb(255, 204, 0)',
                    data: [100120150100180200]
                }]
            },
        
            // Configuration options
            options: {
                legend: {
                     labels: {
                          fontColor: 'white' // label color
                         }
                      },
                scales: {
                    // y축
                    yAxes: [{
                        stacked: true,
                        ticks: {
                            fontColor:'white' // y축 폰트 color
                        }
                     }],
                     // x축
                     xAxes: [{
                         stacked: true,
                        ticks: {
                            fontColor:'white' // x축 폰트 color
                        }
                     }]
                }
            }
        });
    });
</script>
 

 

 

+ Recent posts