Class TextStyleBuilder
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
TextStyleBuilder
用於建立 TextStyle
物件的建構工具。可設定文字的屬性,例如名稱、顏色和大小。
以下範例說明如何使用建構工具建立文字樣式。如需更完整的範例,請參閱 TextStyle
的說明文件。
// Creates a new text style that uses 26-point, blue, Ariel font.
const textStyleBuilder =
Charts.newTextStyle().setColor('#0000FF').setFontName('Ariel').setFontSize(
26);
const style = textStyleBuilder.build();
內容詳盡的說明文件
build()
建構並傳回使用這個建構工具建構的文字樣式設定物件。
// Creates a new text style that uses 26-point blue font.
const textStyleBuilder =
Charts.newTextStyle().setColor('#0000FF').setFontSize(26);
const style = textStyleBuilder.build();
回攻員
TextStyle
:使用這個建構工具建立的文字樣式物件。
setColor(cssValue)
設定文字樣式的顏色。
// Creates a new text style that uses blue font.
const textStyleBuilder = Charts.newTextStyle().setColor('#0000FF');
const style = textStyleBuilder.build();
參數
名稱 | 類型 | 說明 |
cssValue | String | 顏色的 CSS 值 (例如 "blue" 或 "#00f" )。 |
回攻員
TextStyleBuilder
:這個建構工具可用於串連。
setFontName(fontName)
設定文字樣式的字型名稱。
// Creates a new text style that uses Ariel font.
const textStyleBuilder = Charts.newTextStyle().setFontName('Ariel');
const style = textStyleBuilder.build();
參數
名稱 | 類型 | 說明 |
fontName | String | 文字樣式要使用的字型名稱。 |
回攻員
TextStyleBuilder
:這個建構工具可用於串連。
setFontSize(fontSize)
設定文字樣式的字型大小。
// Creates a new text style that uses 26-point font.
const textStyleBuilder = Charts.newTextStyle().setFontSize(26);
const style = textStyleBuilder.build();
參數
名稱 | 類型 | 說明 |
fontSize | Number | 文字樣式使用的字型大小 (以像素為單位)。 |
回攻員
TextStyleBuilder
:這個建構工具可用於串連。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eTextStyleBuilder is used to create TextStyle objects for customizing chart text appearance.\u003c/p\u003e\n"],["\u003cp\u003eIt allows configuration of text properties such as color, font name, and font size using methods like \u003ccode\u003esetColor\u003c/code\u003e, \u003ccode\u003esetFontName\u003c/code\u003e, and \u003ccode\u003esetFontSize\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ebuild\u003c/code\u003e method finalizes the configuration and returns a TextStyle object ready to be applied.\u003c/p\u003e\n"],["\u003cp\u003eTextStyleBuilder facilitates a chained approach for building the desired text style by returning the builder instance after each method call.\u003c/p\u003e\n"]]],["The `TextStyleBuilder` creates `TextStyle` objects, allowing text property configuration. Key actions include setting the text color via `setColor(cssValue)` using CSS values. The font is set using `setFontName(fontName)`, taking a string for the desired font. The font size is controlled with `setFontSize(fontSize)`, where the parameter represents pixel size. `build()` finalizes and returns the constructed `TextStyle` object. These methods can be chained.\n"],null,["# Class TextStyleBuilder\n\nTextStyleBuilder\n\nA builder used to create [TextStyle](/apps-script/reference/charts/text-style) objects. It allows configuration of the text's\nproperties such as name, color, and size.\n\nThe following example shows how to create a text style using the builder. For a more complete\nexample, refer to the documentation for [TextStyle](/apps-script/reference/charts/text-style).\n\n```javascript\n// Creates a new text style that uses 26-point, blue, Ariel font.\nconst textStyleBuilder =\n Charts.newTextStyle().setColor('#0000FF').setFontName('Ariel').setFontSize(\n 26);\nconst style = textStyleBuilder.build();\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------|-------------------------------------------------------|-----------------------------------------------------------------------------------------|\n| [build()](#build()) | [TextStyle](/apps-script/reference/charts/text-style) | Builds and returns a text style configuration object that was built using this builder. |\n| [setColor(cssValue)](#setColor(String)) | [TextStyleBuilder](#) | Sets the color of the text style. |\n| [setFontName(fontName)](#setFontName(String)) | [TextStyleBuilder](#) | Sets the font name of the text style. |\n| [setFontSize(fontSize)](#setFontSize(Number)) | [TextStyleBuilder](#) | Sets the font size of the text style. |\n\nDetailed documentation\n----------------------\n\n### `build()`\n\nBuilds and returns a text style configuration object that was built using this builder.\n\n```javascript\n// Creates a new text style that uses 26-point blue font.\nconst textStyleBuilder =\n Charts.newTextStyle().setColor('#0000FF').setFontSize(26);\nconst style = textStyleBuilder.build();\n```\n\n#### Return\n\n\n[TextStyle](/apps-script/reference/charts/text-style) --- A text style object built using this builder.\n\n*** ** * ** ***\n\n### `set``Color(cssValue)`\n\nSets the color of the text style.\n\n```javascript\n// Creates a new text style that uses blue font.\nconst textStyleBuilder = Charts.newTextStyle().setColor('#0000FF');\nconst style = textStyleBuilder.build();\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------|----------|-------------------------------------------------------------|\n| `css``Value` | `String` | The CSS value for the color (such as `\"blue\"` or `\"#00f\"`). |\n\n#### Return\n\n\n[TextStyleBuilder](#) --- This builder, useful for chaining.\n\n*** ** * ** ***\n\n### `set``Font``Name(fontName)`\n\nSets the font name of the text style.\n\n```javascript\n// Creates a new text style that uses Ariel font.\nconst textStyleBuilder = Charts.newTextStyle().setFontName('Ariel');\nconst style = textStyleBuilder.build();\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------|----------|------------------------------------------|\n| `font``Name` | `String` | The font name to use for the text style. |\n\n#### Return\n\n\n[TextStyleBuilder](#) --- This builder, useful for chaining.\n\n*** ** * ** ***\n\n### `set``Font``Size(fontSize)`\n\nSets the font size of the text style.\n\n```javascript\n// Creates a new text style that uses 26-point font.\nconst textStyleBuilder = Charts.newTextStyle().setFontSize(26);\nconst style = textStyleBuilder.build();\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------|----------|----------------------------------------------------|\n| `font``Size` | `Number` | The font size in pixels to use for the text style. |\n\n#### Return\n\n\n[TextStyleBuilder](#) --- This builder, useful for chaining."]]