Class TextStyle

  • A TextStyle object is used to configure text style for elements in charts options.

  • It can be applied to elements like title, horizontal axis, vertical axis, legend, and tooltip.

  • You can set properties like color, font size, and font name for text styles.

  • Methods like getColor(), getFontName(), and getFontSize() allow you to retrieve the configured text style properties.

TextStyle

A text style configuration object. Used in charts options to configure text style for elementsthat accepts it, such as title, horizontal axis, vertical axis, legend and tooltip.

// This example creates a chart specifying different text styles for the title// and axes.constsampleData=Charts.newDataTable().addColumn(Charts.ColumnType.STRING,'Seasons').addColumn(Charts.ColumnType.NUMBER,'Rainy Days').addRow(['Winter',5]).addRow(['Spring',12]).addRow(['Summer',8]).addRow(['Fall',8]).build();consttitleTextStyleBuilder=Charts.newTextStyle().setColor('#0000FF').setFontSize(26).setFontName('Ariel');constaxisTextStyleBuilder=Charts.newTextStyle().setColor('#3A3A3A').setFontSize(20).setFontName('Ariel');consttitleTextStyle=titleTextStyleBuilder.build();constaxisTextStyle=axisTextStyleBuilder.build();constchart=Charts.newLineChart().setTitleTextStyle(titleTextStyle).setXAxisTitleTextStyle(axisTextStyle).setYAxisTitleTextStyle(axisTextStyle).setTitle('Rainy Days Per Season').setXAxisTitle('Season').setYAxisTitle('Number of Rainy Days').setDataTable(sampleData).build();

Methods

MethodReturn typeBrief description
getColor()StringGets the color of the text style.
getFontName()StringGets the font name of the text style.
getFontSize()NumberGets the font size of the text style.

Detailed documentation

getColor()

Gets the color of the text style.

// Creates a new text style that uses blue text and logs the color.consttextStyle=Charts.newTextStyle().setColor('blue').build();Logger.log(textStyle.getColor());

Return

String — The CSS value for the color (such as"blue" or"#00f").


getFontName()

Gets the font name of the text style.

// Creates a new text style that uses Ariel font and logs the font name.consttextStyle=Charts.newTextStyle().setFontName('Ariel').build();Logger.log(textStyle.getFontName());

Return

String — The font name.


getFontSize()

Gets the font size of the text style.

// Creates a new text style that uses 18 pixel font size and logs the font size.consttextStyle=Charts.newTextStyle().setFontSize(18).build();Logger.log(textStyle.getFontSize());

Return

Number — The font size in pixels.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.