Files
playbook/skills/tsl-api-reference/references/codegen/builtin/graph.md
T
csh 9010829c6d feat(tsl-api-reference): expand and reorganize api catalog
Flatten builtin pages, add third-party and platform scopes, and import financial and data warehouse references.

Keep the existing generated index without rebuilding after signature normalization.
2026-08-10 18:26:24 +08:00

591 lines
13 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Builtin - 图形对象
以下示例使用内存中的静态数组作为图形输入,不调用行情函数,也不需要登录账户。图形对象需在图形运行环境中显示。
## `decodeGraph(grap, _type, name, data, prop)`
声明:function
分解单个图形,将图形类型、名称、数据和属性分别写入输出参数。
| 参数 | 类型 | 说明 |
| ------- | ------- | ------------ |
| `grap` | tgraph | 待分解的图形 |
| `_type` | integer | 输出图形类型 |
| `name` | string | 输出图形名称 |
| `data` | array | 输出图形数据 |
| `prop` | array | 输出图形属性 |
返回:integer
### 示例
```tsl
source_data := array(("value": 1), ("value": 2));
source_graph := encodeGraph(gtLine(), "Series", source_data, array());
decodeGraph(source_graph, graph_type, graph_name, graph_data, graph_prop);
echo graph_type, ",", graph_name, ",", length(graph_data), ",", length(graph_prop);
// 输出:1,Series,2,0
```
## `decodeGraphGroup(graph_group, graph_array, graph_group_prop)`
声明:function
分解图形组合,将其中的图形和组合属性分别写入输出参数。
| 参数 | 类型 | 说明 |
| ------------------ | ----------- | ---------------- |
| `graph_group` | tgraphgroup | 待分解的图形组合 |
| `graph_array` | array | 输出 TGraph 数组 |
| `graph_group_prop` | array | 输出图形组合属性 |
返回:integer
### 示例
```tsl
source_data := array(("value": 1), ("value": 2));
source_graph := encodeGraph(gtLine(), "Series", source_data, array());
source_group := graphGroup(source_graph);
decodeGraphGroup(source_group, graph_array, graph_group_prop);
echo length(graph_array), ",", length(graph_group_prop);
// 输出:1,0
```
## `encodeGraph(_type, name, data, prop)`
声明:function
返回根据指定的类型、名称、数据以及属性数组生成的图形。
| 参数 | 类型 | 说明 |
| ------- | ------- | ---- |
| `_type` | integer | |
| `name` | string | |
| `data` | array | |
| `prop` | array | |
返回:tgraph
### 示例
```tsl
t1 := array(
("open": 9.3, "close": 9.24, "high": 9.35, "low": 9.23, "time": "2012-12-11", "color": 65280, "fill": -1),
("open": 9.24, "close": 9.24, "high": 9.33, "low": 9.06, "time": "2012-12-12", "color": 65535, "fill": -1),
("open": 9.23, "close": 9.32, "high": 9.42, "low": 9.12, "time": "2012-12-13", "color": 255, "fill": 0));
return encodeGraph(gtKLine(), 'KLine', t1, array());
```
## `encodeGraphGroup(graph_array, graph_group_prop)`
声明:function
根据 TGraph 数组和组合属性生成图形组合。
| 参数 | 类型 | 说明 |
| ------------------ | ----- | ------------ |
| `graph_array` | array | TGraph 数组 |
| `graph_group_prop` | array | 图形组合属性 |
返回:tgraphgroup
### 示例
```tsl
source_data := array(("value": 1), ("value": 2));
source_graph := encodeGraph(gtLine(), "Series", source_data, array());
source_group := encodeGraphGroup(array(source_graph), array());
decodeGraphGroup(source_group, graph_array, graph_group_prop);
echo length(graph_array), ",", length(graph_group_prop);
// 输出:1,0
```
## `fgDown()`
声明:function
返回:integer
## `fgLeft()`
声明:function
返回:integer
## `fgLeftDown()`
声明:function
左下
返回:integer
## `fgLeftUp()`
声明:function
左上
返回:integer
## `fgNone()`
声明:function
无标识
返回:integer
## `fgRight()`
声明:function
返回:integer
## `fgRightDown()`
声明:function
右下
返回:integer
## `fgRightUp()`
声明:function
右上
返回:integer
## `fgUp()`
声明:function
返回:integer
## `flBDiagonal()`
声明:function
反斜线填充
返回:integer
## `flClear()`
声明:function
空心体。
返回:integer
## `flCross()`
声明:function
交叉线填充
返回:integer
## `flDiagCross()`
声明:function
交叉斜线填充
返回:integer
## `flFDiagonal()`
声明:function
正斜线填充
返回:integer
## `flHorizontal()`
声明:function
横线填充
返回:integer
## `flSolid()`
声明:function
实心填充。
返回:integer
## `flVertical()`
声明:function
竖线填充
返回:integer
## `gfAmount()`
声明:function
成交金额(数据字段),也可用于指定柱线,细柱线的值
返回:string
## `gfClose()`
声明:function
收盘(数据字段),一般用于K线,美国线,宝塔线
返回:string
## `gfColor()`
声明:function
颜色(数据字段或TGraph的属性),可以修饰单个数据点或者整个图形的颜色。
返回:string
## `gfCoordinate()`
声明:function
图形的坐标系模式。设置为0为普通坐标,1为对数坐标,2为百分比坐标。
返回:string
## `gfFill()`
声明:function
填充状况(数据字段),用于设定柱线、K线、圆圈图等填充情况。
返回:string
## `gfFlag()`
声明:function
标示(数据字段),标示内容见图形标示函数
返回:string
## `gfHigh()`
声明:function
最高(数据字段),用于K线,宝塔线,美国线
返回:string
## `gfLeftTitleCaption()`
声明:function
图形辅助标题文字。
返回:string
## `gfLow()`
声明:function
最低(数据字段),用于K线,宝塔线,美国线
返回:string
## `gfLtp()`
声明:function
流通盘(TGraphGroup的属性字段)TGraphGroup的属性,用于换手率的计算,暂时未使用,将来扩展用。
返回:string
## `gfMaxValue()`
声明:function
设定显示的最大值(TGraphGroup的属性字段)TGraphGroup的属性。一般的,图形会用查找视图内最小最小值用于显示,同时,为了特殊显示,也可以指定其显示的最大最小值,例如成交量的图是用0作为最小值的。
返回:string
## `gfMinValue()`
声明:function
设定显示的最小值(TGraphGroup的属性字段)TGraphGroup的属性。一般的,图形会用查找视图内最小最小值用于显示,同时,为了特殊显示,也可以指定其显示的最大最小值,例如成交量的图是用0作为最小值的。
返回:string
## `gfOpen()`
声明:function
开盘(数据字段),用于K线,宝塔线,美国线
返回:string
## `gfRateFlag()`
声明:function
除权标示(数据字段),指示是否为除权日
返回:string
## `gfTime()`
声明:function
时间坐标(数据字段),用于X坐标轴的显示
返回:string
## `gfTitleCaption()`
声明:function
图形的标题文字,TGraphGroup的属性。
返回:string
## `gfTowerHigh()`
声明:function
宝塔线中的高值(数据字段),宝塔线也可以不需要使用此三个字段,该三个字段的内容可以被自动根据gfClose,gfOpen,gfHigh,gfLow计算出来
返回:string
## `gfTowerLow()`
声明:function
宝塔线中的低值(数据字段),宝塔线也可以不需要使用此三个字段,该三个字段的内容可以被自动根据gfClose,gfOpen,gfHigh,gfLow计算出来
返回:string
## `gfTowerMid()`
声明:function
宝塔线中的中值(数据字段),宝塔线也可以不需要使用此三个字段,该三个字段的内容可以被自动根据gfClose,gfOpen,gfHigh,gfLow计算出来
返回:string
## `gfValue()`
声明:function
值(数据字段),可指定折线,柱线,细柱线,圆圈图的值
返回:string
## `gfVol()`
声明:function
成交量(数据字段),也可用于指定柱线,细柱线的值
返回:string
## `gfZero()`
声明:function
零轴(TGraphgroup的属性字段)TGraphGroup的属性,用于标示中间值,特别用于MACD类的图形
返回:string
## `graph(_type, graph_name, data, prop1, prop1_value, prop2, prop2_value, ..., prop_n, prop_n_value)`
声明:function
用于生成单个图形。单个图形的含义是一条折线、K线或成交量柱壮图。函数的具体的功能是:用指定的数据Data生成一个类型为Type的图形,并且用后面指定的属性参数PropN和PropNValue为图形指定修饰属性。注意,如果横坐标要显示出数据,需要把横坐标设置列名为'time'
| 参数 | 类型 | 说明 |
| -------------- | ---------- | ---- |
| `_type` | integer | |
| `graph_name` | string | |
| `data` | tablearray | |
| `prop1` | string | |
| `prop1_value` | any | |
| `prop2` | string | |
| `prop2_value` | any | |
| `...` | | |
| `prop_n` | string | |
| `prop_n_value` | any | |
返回:tgraph
### 示例
范例01K 线与 MA10
```tsl
t1 := array(
("open": 9.3, "close": 9.24, "high": 9.35, "low": 9.23, "time": "2012-12-11", "color": 65280, "fill": -1),
("open": 9.24, "close": 9.24, "high": 9.33, "low": 9.06, "time": "2012-12-12", "color": 65535, "fill": -1),
("open": 9.23, "close": 9.32, "high": 9.42, "low": 9.12, "time": "2012-12-13", "color": 255, "fill": 0),
("open": 9.34, "close": 9.7, "high": 9.73, "low": 9.29, "time": "2012-12-14", "color": 255, "fill": 0),
("open": 9.68, "close": 9.57, "high": 9.9, "low": 9.49, "time": "2012-12-17", "color": 65280, "fill": -1),
("open": 9.51, "close": 9.22, "high": 9.67, "low": 9.16, "time": "2012-12-18", "color": 65280, "fill": -1),
("open": 9.21, "close": 9.31, "high": 9.36, "low": 9.01, "time": "2012-12-19", "color": 255, "fill": 0),
("open": 9.25, "close": 9.48, "high": 9.51, "low": 9.18, "time": "2012-12-20", "color": 255, "fill": 0),
("open": 9.5, "close": 9.43, "high": 9.6, "low": 9.33, "time": "2012-12-21", "color": 65280, "fill": -1),
("open": 9.45, "close": 9.55, "high": 9.61, "low": 9.43, "time": "2012-12-24", "color": 255, "fill": 0),
("open": 9.55, "close": 10.12, "high": 10.26, "low": 9.5, "time": "2012-12-25", "color": 255, "fill": 0));
t2 := array(
("MA10": 8.946),
("MA10": 9.036),
("MA10": 9.125),
("MA10": 9.22),
("MA10": 9.297),
("MA10": 9.324),
("MA10": 9.341),
("MA10": 9.362),
("MA10": 9.385),
("MA10": 9.406),
("MA10": 9.494));
g1 := graph(gtKLine(), 'KLine', t1);
g2 := graph(gtLine(), 'MA10', t2);
return graphGroup(g1, g2);
```
范例02:收盘价与均线
```tsl
g_data1 := array(
("close": 9.24),
("close": 9.32),
("close": 9.7),
("close": 9.57),
("close": 9.22));
g_data2 := array(
("MA5": 9.24),
("MA5": 9.28),
("MA5": 9.42),
("MA5": 9.46),
("MA5": 9.41));
g_data3 := array(
("MA20": 9.1),
("MA20": 9.15),
("MA20": 9.2),
("MA20": 9.25),
("MA20": 9.3));
g1 := graph(gtLine(), 'Close', g_data1, gfColor(), clBlue());
g2 := graph(gtLine(), 'MA5', g_data2, gfColor(), clGreen());
g3 := graph(gtLine(), 'MA20', g_data3, gfColor(), clRed());
return graphGroup(g1, g2, g3);
```
## `graphGroup(graph1, graph_n, prop_m, value_m)`
声明:function
用于生成图形组合,可以指定任意多个单个图形作为参数生成一个图形组合,在其后面还可以指定图形组合的共有属性。
| 参数 | 类型 | 说明 |
| --------- | ------ | -------------------------- |
| `graph1` | tgraph | TGraph 图形1 |
| `graph_n` | tgraph | TGraph 图形N |
| `prop_m` | string | 可选。TGraphGroup 属性名称 |
| `value_m` | any | 可选。TGraphGroup 属性值 |
返回:tgraphgroup
### 示例
```tsl
vol_data := array(
("vol": 1200, "color": 255),
("vol": 980, "color": 65280),
("vol": 1350, "color": 255),
("vol": 1100, "color": 65280),
("vol": 1420, "color": 255));
mavol := array(
("MA5": 1200),
("MA5": 1090),
("MA5": 1177),
("MA5": 1158),
("MA5": 1210));
vol_graph := graph(gtBar(), 'VOLGraph', vol_data);
mavol_graph := graph(gtLine(), 'MA5Graph', mavol, gfColor(), clBlue());
return graphGroup(vol_graph, mavol_graph, gfMinValue(), 0);
```
`GraphGroup` 包含成交量柱图 `VOLGraph` 和五日均量线 `MA5Graph`,共有属性 `gfMinValue()` 将纵轴最小值设为 `0``vol_data` 中的 `color` 字段控制各柱颜色;`MA5Graph``gfColor()` 属性将整条折线设为蓝色。折线数据未显式提供 `gfValue()` 字段时,系统使用第一个数据字段作为折线值。
## `gtAmerican()`
声明:function
美国线类型
返回:integer
## `gtBar()`
声明:function
柱线类型
返回:integer
## `gtCircle()`
声明:function
圆圈图类型
返回:integer
## `gtKLine()`
声明:function
K线类型
返回:integer
## `gtLine()`
声明:function
折线类型
返回:integer
## `gtSingleBar()`
声明:function
细柱线类型
返回:integer
## `gtTower()`
声明:function
宝塔线类型
返回:integer