일자별 쿼리로 지표 그래프 그리기 (증감률, 퍼센트 표시)

일자별 지표 쿼리를 월/주/일로 샘플링하여 표시합니다.

- type: query
  resource: mysql.qa
  name: bar percentage diff 
  sql: > 
    SELECT DATE_FORMAT(created_at, '%Y-%m-%d') as 'date', COUNT(id) as c, COUNT(user_id) as users
    FROM UserStageLog
    WHERE created_at BETWEEN :date1 AND :date2
    GROUP BY DATE_FORMAT(created_at, '%Y-%m-%d')
  chartOptions:
    type: bar
    x: date
    backgroundColor:
      c: "RoyalBlue"
      users: "Tomato"
    borderWidth:
      c: 0
      users: 0
    y: 
      - c
      - users

    gap: true
    interval: month
    daily: false
    weekly: false
    monthly: true

    sampleBy: sum
    options:
      layout: 
        padding: 50
      plugins:
        datalabels:
          anchor: end
          align: end
          offset: 4
          formatter: percentage-diff

그래프가 많은 경우 레이블을 기울이기

options:
  layout: 
    padding: 50
  plugins:
    datalabels:
      anchor: end
      align: end
      offset: 4
      formatter: percentage-diff
      color: RoyalBlue
      rotation: -45
      font: 
        size: 10
        weight: bold