跳到主要内容

参考线与标注

annotations 在数据之上画三类东西:直线参考线、阴影带、文字(可选带箭头)。三者都是列表,都可以不给。

参考线​

字段类型设置什么
orientationstring"horizontal"(默认)或 "vertical"。
valuenumber线的位置 —— 水平线是 y 值,垂直线是 x 值。
colorstring线颜色。
stroke_widthnumber线宽。
dasharraystringSVG 的 stroke-dasharray(例如 "4 2"),画虚线。
labelstring线上的文字标签。

阴影区域​

字段类型设置什么
orientationstring"horizontal"(默认)或 "vertical"。
min / maxnumber带的两条边。
colorstring填充色。
opacitynumber填充不透明度,0–1。

文字与箭头​

字段类型设置什么
textstring标签文字。
x / ynumber文字位置(数据坐标)。
target_x / target_ynumber两个都给时,从文字到该点画一条箭头。
colorstring文字颜色。
font_sizeinteger文字大小。
arrow_paddingnumber文字与箭头起点之间的间距。

示例​

在一个条件的时间序列上画一条基线、一条围绕它的阴影带,再加一个标签:

SELECT kuva_render(to_json({
'x_axis': {'name': 'time'},
'y_axis': {'name': 'value'},
'annotations': {
'reference_lines': [
{'orientation': 'horizontal', 'value': 1.5, 'color': 'crimson', 'dasharray': '4 2', 'label': 'baseline'}
],
'shaded_regions': [
{'orientation': 'horizontal', 'min': 1.2, 'max': 1.6, 'opacity': 0.15, 'color': 'crimson'}
],
'texts': [
{'text': 'steady state', 'x': 55, 'y': 2.6}
]
},
'series': [{'type': 'line', 'data': pts, 'color': 'steelblue'}]
})) AS chart
FROM (
SELECT array_agg({'x': time, 'y': value} ORDER BY time) AS pts
FROM read_csv_auto('{{DFK_BASE_URL}}data/measurements.tsv')
WHERE "group" = 'Condition_A'
);

说明​

标注画在 series 之上,所以填充型图形(开了 fill 的 line、band)可以垫在它们下面。