Get Time Series Trend Chart¶
GET /api/v1/chart_image/get
Overview¶
Use a Client Token to run a DQL or PromQL time series query and download the PNG trend chart directly.
Before You Call and Usage Steps¶
This API uses a Client Token to determine the Workspace and does not require DF-API-KEY or a login Token. Keep the Token in the URL secure and avoid writing it to public pages or sharing links. The data access identity is different from the Workspace API Key; you cannot infer this API's access control from API Key role permissions. First verify the time series statement in the target Workspace, select a real data time range whose span does not exceed the site limit, then URL-encode the query parameters and download the image. The example times are for illustration only; replace them with a time window that has data before calling.
A successful response is raw PNG binary and has no JSON business fields such as code/content/success/traceId. Errors may return JSON, so the client must check the HTTP status, Content-Type, and PNG file signature at the same time and must not save any 200 response as a valid image. Chart rendering failures are logged on the server but may still return HTTP 200, image/png, and an empty body. Empty data may also produce an empty coordinate chart; this does not mean the request failed. For an empty body, first check the statement, time zone, and actual data, and retain the tracing information in the response headers when reporting to the administrator.
Only Query in the parameter table is supported. There is an internal showLegend read, but it is not exposed in the public declaration and must not be submitted; the legend is not displayed by default. Results are not cached, and responses set no-store. Token information is cached for 60 seconds in the Redis used by this process. After revocation, a short cache window may remain; immediate invalidation is not guaranteed.
Query Request Parameters¶
| Parameter Name | Type | Required | Description |
|---|---|---|---|
| clientToken | string | Y | Required. Only Client Tokens with valid status 0 are queried; leading and trailing whitespace is removed. The Token determines the query Workspace. Null allowed: False Example: <CLIENT-TOKEN>How to obtain or enter: Copy the actual Token value from Client Token Management in the current Workspace; it is not the token record UUID or an API Key. |
| qtype | string | Optional dql/promql. To avoid depending on downstream handling of default values, always pass it explicitly; the route has no configured default, so omitting it passes None to the query service. Null allowed: False Allowed values: ['dql', 'promql'] Example: dqlHow to obtain or enter: Explicitly select dql or promql according to the query statement type; see DQL and PromQL. |
|
| q | string | Y | Required query statement; it must return a series containing time and values. DQL and PromQL syntax cannot be mixed. Grouping by Tag can produce multiple lines. Null allowed: False Example: M::cpu:(avg(usage_idle)) BY hostHow to obtain or enter: Confirm a time series query with data in the query tool of the target Workspace, then URL-encode the Query. |
| startTime | integer | Y | Required integer. 10-digit values are multiplied by 1000 internally; other digit lengths are used directly as milliseconds. Passing seconds consistently is recommended to avoid relying on digit-length detection. 0 falls back to endTime minus 1 hour and is not the Unix epoch. Null allowed: False Example: 1785427200How to obtain or enter: Select the query start point where data actually exists, using a Unix timestamp in seconds. |
| endTime | integer | Y | Required integer. 10-digit second values are converted to milliseconds; all other values are treated as milliseconds; 0 uses the server's current time. The maximum span is constrained by the site's ChartImageSet.maxTimeSc; the code default is 3600 seconds, and administrators can override it. Null allowed: False Example: 1785429000How to obtain or enter: Select the query end point. It must be greater than or equal to startTime and use the same unit. |
| interval | integer | Optional, default 60 seconds; internally multiplied by 1000 as the query interval. 0 is calculated from the span and site point density, with a minimum of 1 millisecond; a negative value returns 406. The actual number of points is also limited by the query service and point density, and not every point is guaranteed to have data. Null allowed: False Example: 60How to obtain or enter: Select a positive integer number of seconds according to the granularity required for the image; pass 0 for automatic estimation. |
|
| tz | string | Optional, default Asia/Shanghai. Controls query alignment and horizontal axis display in the image; does not change the meaning of Unix timestamps. There is no time zone enum validation; an incorrect name can cause downstream query failures or an empty image. Null allowed: False Example: Asia/ShanghaiHow to obtain or enter: Select an IANA time zone name according to the business display time zone. |
Additional Parameter Notes¶
Query Notes
Note: This API uses clientToken for authentication. It takes effect only when clientToken is valid. This API can be called without the DF-API-KEY request header.
Request Example¶
curl --get 'https://openapi.guance.com/api/v1/chart_image/get' \
--data-urlencode 'clientToken=<CLIENT-TOKEN>' \
--data-urlencode qtype=dql \
--data-urlencode 'q=M::cpu:(avg(usage_idle)) BY host' \
--data-urlencode startTime=1785427200 \
--data-urlencode endTime=1785429000 \
--data-urlencode interval=60 \
--data-urlencode tz=Asia/Shanghai \
--output chart.png
Response¶
HTTP 200 raw PNG image stream; errors are usually JSON. Chart rendering failures may also return 200 with an empty body, so you must check the status, type, and file signature.
| Response Header | Type | Description |
|---|---|---|
| Content-Type | string | image/png on success; for exceptions, handle according to the actual JSON or proxy response type. |
| Cache-Control | string | no-store, max-age=0 on success; image responses are not cached. |
HTTP/1.1 200 OK
Content-Type: image/png
Cache-Control: no-store, max-age=0
<PNG binary; file header in hexadecimal is 89 50 4e 47 0d 0a 1a 0a>
Error Response¶
This endpoint has requireSignIn=false and does not apply DF-API-KEY authentication/role errors. Request validation still applies; the query service may return dynamic errors related to the statement, data source, capacity, or network. The actual HTTP status and error code in the response prevail. Chart rendering errors may return only a 200 empty PNG body; a JSON error is not guaranteed.
| HTTP Status | errorCode | Trigger Condition | Message or Response Description | Handling |
|---|---|---|---|---|
| 406 | ft.ParameterValidationFailed | A request field is missing, or a field value violates the declared validation conditions | Parameter parsing failed | Check the parameter location, field name, type, and value. |
| 406 | ft.DqlParseError | The DQL statement syntax or parse structure is invalid | dql parser parsing failed: {} | First verify the statement in the query tool and URL-encode it correctly; retain the actual parsing reason. |
| 406 | ft.NotSupportedByGroupQuery | Using BY index grouping | The index field is not supported for by grouping queries | Remove the index grouping field and use real business Tags for grouping instead. |
| 503 | ft.QueryServiceUnavailable | The upstream query returns HTTP 503, which is mapped uniformly | The query service is temporarily unavailable. Please try again later. | Check content.retryable in the error body, retry after backoff, and avoid high-frequency retries. |
| 404 | ft.ClientTokenNotExistOrDelete | The Client Token is empty after trimming whitespace, or the cache misses and there is no valid Token record | The specified Client Token does not exist or has been deleted | Check the actual Token value and target site, use a valid Token, and do not substitute the record UUID. |
| 400 | ft.IllegalStartOrEndTime | The end point is earlier than the start point, or the span exceeds the site maximum | Invalid start/end timestamp | Use timestamps in the same unit and reduce them to the allowed range. |
| 406 | ft.InvalidParameter | interval is less than 0 | Invalid parameter interval |
Change it to a positive integer number of seconds or 0 for automatic estimation. |
| 500 | ft.InternalServerError | Cache/database unavailable, abnormal returned data structure, or other uncaught errors | Internal error | Check the returned Content-Type and body, retain traceId, and contact the administrator; do not treat error JSON as PNG. |