Common Component Themes

January 25, 2021 ยท View on GitHub

This guide discusses applying themes to common TOAST UI Chart components including chart titles, axes, legends, export menus, tooltips, and plots.

type Theme = {
  chart?: ChartTheme;
  title?: FontTheme;
  yAxis?: AxisTheme | AxisTheme[];
  xAxis?: AxisTheme;
  legend?: LegendTheme;
  tooltip?: TooltipTheme;
  plot?: PlotTheme;
  exportMenu?: ExportMenuTheme;
  series?: {
    // More details in respective guides
  };
}

Global Chart Themes

The theme.chart.fontFamily option is used to configure fonts that are used with everything in the chart. Fonts for title, axis, label text, and legend are configured using this font. If you use the theme.chart.backgroundColor option, you can set the background color of the chart.

fontFamily

  • default: 'Arial'

backgroundColor

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

image

Chart Title Themes

The theme.title can be used to style the chart's title.

type FontTheme = {
  fontSize?: number;
  fontFamily?: string;
  fontWeight?: string | number;
  color?: string;
};
NameTypeDetails
fontSizenumberFont size
fontFamilystringFont family
fontWeightnumber | stringFont weight
colorstringText color
const options = {
  theme: {
    title: {
      fontFamily: 'Comic Sans MS',
      fontSize: 45,
      fontWeight: 100,
      color: '#ff416d'
    }
  }
};

image

Axis Themes

theme.xAxis and theme.yAxis can be used to style respective axis. It can be used to change the axis title, label, and line styles.

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[];
NameTypeDetails
titleobjectStyle configuration for the axis title
labelobjectStyle configuration for the axis label
widthnumberAxis line width
colorstringAxis line color
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

Legend Themes

The theme.legend can be used to style texts displayed in the legends.

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

Tooptip Themes

The theme.tooltip can be used to style the 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;
  };
};
NameTypeDetails
backgroundstringBackground color
borderColorstringBorder color
borderWidthnumberBorder width
borderStylestringBorder style; available options can be found in this MDN link
borderRadiusnumberBorder radius
headerobjectStyles for text displayed in the tooltip header area
bodyobjectStyles for text displayed in the tooltip body area
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

Plot Themes

The theme.plot can be used to style the plot's background and lines.

type PlotTheme = {
  lineColor?: string;
  lineWidth?: number;
  dashSegments?: number[];
  backgroundColor?: string;
  vertical?: {
    lineColor?: string;
    lineWidth?: number;
    dashSegments?: number[];
  };
  horizontal?: {
    lineColor?: string;
    lineWidth?: number;
    dashSegments?: number[];
  };
};
NameTypeDetails
lineColorstringLine color
lineWidthnumberLine width
dashSegmentsnumber[]dashSegment values for the plot lines
backgroundColorstringBackground color for the plot area
verticalobjectStyles for the plot lines drawn vertically
horizontalobjectStyles for the plot lines drawn horizontally
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

Export Menu Themes

The theme.exportMenu can be used to style the export button and the menu box.

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;
    };
  };
};
NameTypeDetails
buttonobjectStyles used for the export button
button.backgroundColorstringButton background color
button.borderRadiusnumberButton border radius
button.borderWidthnumberButton border width
button.borderColorstringButton border color
button.xIconobjectStyles used for the x icon
button.dotIconobjectStyles used for the dot icon
panelobjectStyles used for the panel that is displayed when the export button is clicked
panel.borderRadiusnumberMenu panel border radius
panel.borderWidthnumberMenu panel border width
panel.borderColorstringMenu panel border color
panel.headerobjectStyles used for the menu panel header
panel.bodyobjectStyles used for the menu panel 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',
        },
      },
    },
  },
};
Before ClickAfter Click
imageimage