공통 컴포넌트 테마

January 25, 2021 · View on GitHub

이 가이드는 TOAST UI Chart에서 공통 컴포넌트로 분류되고 있는 차트 제목, 축, 범례, 내보내기 메뉴, 툴팁, 플롯에 테마를 적용하는 방법을 다룬다.

type Theme = {
  chart?: ChartTheme;
  title?: FontTheme;
  yAxis?: AxisTheme | AxisTheme[];
  xAxis?: AxisTheme;
  legend?: LegendTheme;
  tooltip?: TooltipTheme;
  plot?: PlotTheme;
  exportMenu?: ExportMenuTheme;
  series?: {
    // 각 차트에서 설명
  };
}

차트 전역 테마

theme.chart옵션은 차트 전역에서 사용할 스타일을 설정할 수 있다. theme.chart.fontFamily를 지정하면 제목, 축에 사용되는 라벨 폰트, 제목 폰트, 범례 폰트 등이 이 폰트로 기본 설정되며, theme.chart.backgroundColor 옵션을 사용하면 차트의 배경색을 설정할 수 있다.

fontFamily

  • 기본값: 'Arial'

backgroundColor

  • 기본값: #ffffff
type ChartTheme = {
  fontFamily?: string;
  backgroundColor?: string;
}
const options = {
  theme: {
    chart: {
      fontFamily: 'Verdana',
      backgroundColor: 'rgba(9, 206, 115, 0.1)',
    }
  }
};

image

차트 제목 테마

theme.title은 차트 제목의 스타일을 설정한다.

type FontTheme = {
  fontSize?: number;
  fontFamily?: string;
  fontWeight?: string | number;
  color?: string;
};
이름타입설명
fontSizenumber글자 크기
fontFamilystring폰트명
fontWeightnumber | string글자 굵기
colorstring글자 색상
const options = {
  theme: {
    title: {
      fontFamily: 'Comic Sans MS',
      fontSize: 45,
      fontWeight: 100,
      color: '#ff416d'
    }
  }
};

image

축 테마

theme.xAxis 또는 theme.yAxis는 축의 스타일을 설정한다. 축의 제목, 라벨, 선의 스타일을 변경할 수 있다.

type AxisTheme = {
  title?: {
    fontSize?: number;
    fontFamily?: string;
    fontWeight?: string | number;
    color?: string;
  };
  label?: {
    fontSize?: number;
    fontFamily?: string;
    fontWeight?: string | number;
    color?: string;
  };
  width?: number;
  color?: string;
};

type XAxisTheme = AxisTheme;
type YAxisTheme = AxisTheme | AxisTheme[];
이름타입설명
titleobject축 제목에 대한 스타일 설정
labelobject축 라벨에 대한 스타일 설정
widthnumber축의 선 두께
colorstring축의 선 색상
const options = {
  theme: {
    xAxis: {
      title: {
        fontFamily: 'Impact',
        fontSize: 15,
        fontWeight: 400,
        color: '#ff416d'
      },
      label: {
        fontFamily: 'fantasy',
        fontSize: 11,
        fontWeight: 700,
        color: '#6EB5FF'
      },
      width: 2,
      color: '#6655EE'
    },
    yAxis: [
      {
        title: {
          fontFamily: 'Impact',
          fontSize: 17,
          fontWeight: 400,
          color: '#03C03C'
        },
        label: {
          fontFamily: 'cursive',
          fontSize: 11,
          fontWeight: 700,
          color: '#6655EE'
        },
        width: 3,
        color: '#88ddEE'
      },
      {
        title: {
          fontFamily: 'Comic Sans MS',
          fontSize: 13,
          fontWeight: 600,
          color: '#00a9ff'
        },
        label: {
          fontFamily: 'cursive',
          fontSize: 11,
          fontWeight: 700,
          color: '#FFABAB'
        },
        width: 3,
        color: '#AFFCCA'
      }
    ]
  }
};

image

범례 테마

theme.legend는 범례에 표시되는 글자의 스타일을 지정한다.

type LegendTheme = {
  label?: {
    fontSize?: number;
    fontFamily?: string;
    fontWeight?: string | number;
    color?: string;
  };
};
const options = {
  theme: {
    legend: {
      label: {
        fontFamily: 'cursive',
        fontSize: 15,
        fontWeight: 700,
        color: '#ff416d'
      }
    }
  }
};

image

툴팁 테마

theme.tooltip은 툴팁의 스타일을 설정한다.

type TooltipTheme = {
  background?: string;
  borderColor?: string;
  borderWidth?: number;
  borderStyle?: string;
  borderRadius?: number;
  header?: {
    fontSize?: number;
    fontFamily?: string;
    fontWeight?: string | number;
    color?: string;
  };
  body?: {
    fontSize?: number;
    fontFamily?: string;
    fontWeight?: string | number;
    color?: string;
  };
};
이름타입설명
backgroundstring배경 색상
borderColorstring테두리 선 색상
borderWidthnumber테두리 선 너비
borderStylestring테두리 선 스타일. 사용 가능한 옵션은 MDN 링크에서 확인할 수 있다.
borderRadiusnumber둥근 모서리 값
headerobject툴팁 header 영역의 글자 스타일
bodyobject툴팁 body 영역의 글자 스타일
const options = {
  theme: {
    tooltip: {
      background: '#80CEE1',
      borderColor: '#3065AC',
      borderWidth: 10,
      borderRadius: 20,
      borderStyle: 'double',
      header: {
        fontSize: 15,
        fontWeight: 700,
        color: '#333333',
        fontFamily: 'monospace',
      },
      body: {
        fontSize: 11,
        fontWeight: 700,
        color: '#a66033',
        fontFamily: 'monospace',
      }
    }
  }
};

image

플롯 테마

theme.plot은 플롯의 배경과 선 스타일을 설정한다.

type PlotTheme = {
  lineColor?: string;
  lineWidth?: number;
  dashSegments?: number[];
  backgroundColor?: string;
  vertical?: {
    lineColor?: string;
    lineWidth?: number;
    dashSegments?: number[];
  };
  horizontal?: {
    lineColor?: string;
    lineWidth?: number;
    dashSegments?: number[];
  };
};
이름타입설명
lineColorstring선 색상
lineWidthnumber선 두께
dashSegmentsnumber[]플롯 선의 dashSegment 값 (IE11 이상 지원)
backgroundColorstring플롯 영역 배경색
verticalobject세로로 그려지는 플롯 선의 스타일 설정
horizontalobject가로로 그려지는 플롯 선의 스타일 설정
const options = {
  theme: {
    plot: {
      vertical: {
        lineColor: 'rgba(60, 80, 180, 0.3)',
        lineWidth: 5,
        dashSegments: [5, 20],
      },
      horizontal: {
        lineColor: 'rgba(0, 0, 0, 0)',
      },
      backgroundColor: 'rgba(60, 80, 180, 0.1)'
    }
  }
};

image

내보내기 메뉴 테마

theme.exportMenu는 내보내기 버튼과 메뉴 박스에 대한 스타일을 설정한다.

type ExportMenuTheme = {
  button?: {
    backgroundColor?: string;
    borderRadius?: number;
    borderWidth?: number;
    borderColor?: string;
    xIcon?: {
      color?: string;
      lineWidth?: number;
    };
    dotIcon?: {
      color?: string;
      width?: number;
      height?: number;
      gap?: number;
    };
  };
  panel?: {
    borderRadius?: number;
    borderWidth?: number;
    borderColor?: string;
    header?: {
      fontSize?: number;
      fontFamily?: string;
      fontWeight?: string | number;
      color?: string;
      backgroundColor?: string;
    };
    body?: {
      fontSize?: number;
      fontFamily?: string;
      fontWeight?: string | number;
      color?: string;
      backgroundColor?: string;
    };
  };
};
이름타입설명
buttonobject내보내기 버튼 스타일 설정
button.backgroundColorstring버튼의 배경색
button.borderRadiusnumber버튼 둥근 모서리 값
button.borderWidthnumber버튼 테두리 두께
button.borderColorstring버튼 테두리 색상
button.xIconobjectX 아이콘 스타일 설정
button.dotIconobject점 아이콘 스타일 설정
panelobject내보내기 버튼 클릭 시 나타나는 메뉴 패널 스타일 설정
panel.borderRadiusnumber메뉴 패널의 둥근 모서리 값
panel.borderWidthnumber메뉴 패널의 테두리 두께
panel.borderColorstring메뉴 패널의 테두리 색상
panel.headerobject메뉴 패널의 header 스타일 설정
panel.bodyobject메뉴 패널의 body 스타일 설정
const options = {
  theme: {
    exportMenu: {
      button: {
        backgroundColor: '#ff0000',
        borderRadius: 5,
        borderWidth: 2,
        borderColor: '#000000',
        xIcon: {
          color: '#ffffff',
          lineWidth: 3,
        },
        dotIcon: {
          color: '#ffffff',
          width: 10,
          height: 3,
          gap: 1,
        },
      },
      panel: {
        borderColor: '#ff0000',
        borderWidth: 2,
        borderRadius: 10,
        header: {
          fontSize: 15,
          fontFamily: 'fantasy',
          color: '#ffeb3b',
          fontWeight: 700,
          backgroundColor: '#673ab7',
        },
        body: {
          fontSize: 12,
          fontFamily: 'fantasy',
          color: '#ff0000',
          fontWeight: '500',
          backgroundColor: '#000000',
        },
      },
    },
  },
};
클릭 전클릭 후
imageimage