用于创建 Text 对象的构建器。它允许配置文本的属性,例如名称、颜色和大小。
以下示例展示了如何使用构建器创建文本样式。如需查看更完整的示例,请参阅 Text 的文档。
// 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() | Text | 构建并返回使用此构建器构建的文本样式配置对象。 | 
| set | Text | 设置文字样式的颜色。 | 
| set | Text | 设置文本样式的字体名称。 | 
| set | Text | 设置文本样式的字体大小。 | 
详细文档
build()
构建并返回使用此构建器构建的文本样式配置对象。
// Creates a new text style that uses 26-point blue font. const textStyleBuilder = Charts.newTextStyle().setColor('#0000FF').setFontSize(26); const style = textStyleBuilder.build();
返回
Text - 使用此构建器构建的文本样式对象。
set
设置文字样式的颜色。
// Creates a new text style that uses blue font. const textStyleBuilder = Charts.newTextStyle().setColor('#0000FF'); const style = textStyleBuilder.build();
参数
| 名称 | 类型 | 说明 | 
|---|---|---|
| css | String | 颜色的 CSS 值(例如 "blue"或"#00f")。 | 
返回
Text - 此构建器,适用于链式调用。
set
设置文本样式的字体名称。
// Creates a new text style that uses Ariel font. const textStyleBuilder = Charts.newTextStyle().setFontName('Ariel'); const style = textStyleBuilder.build();
参数
| 名称 | 类型 | 说明 | 
|---|---|---|
| font | String | 要用于文本样式的字体名称。 | 
返回
Text - 此构建器,适用于链式调用。
set
设置文本样式的字体大小。
// Creates a new text style that uses 26-point font. const textStyleBuilder = Charts.newTextStyle().setFontSize(26); const style = textStyleBuilder.build();
参数
| 名称 | 类型 | 说明 | 
|---|---|---|
| font | Number | 要用于文本样式的字体大小(以像素为单位)。 | 
返回
Text - 此构建器,适用于链式调用。