要从Apache Superset Rest API中获取图表截图,您需要使用libgraphein图表捕获库。
下面是使用Python的示例代码:
import requests
CHART_API = "http://{superset_host}/api/v1/chart"
# 填写Superset登录信息
headers = {
'Authorization': 'Bearer ',
'Content-Type': 'application/json'
}
# 填写需要查询的图表的id
query_param = {
"chart_id": 1,
"height": 480,
"width": 800,
"force": True
}
# 发送POST请求以获取图表截图
response = requests.post(CHART_API, headers=headers, json=query_param)
# 读取返回的图像
with open('chart.png', 'wb') as f:
f.write(response.content)
在上面的示例中,您需要将{superset_host}
替换为您的Apache Superset地址,并将
替换为您的访问令牌。
此外,需要注意的是,通过API获取图表截图必须将width
和height
参数设置为所需的像素大小。