Create a chart

Creates a new chart on a specific dashboard.

POST https://telemetry.betterstack.com/api/v2/dashboards/{dashboard_id}/charts

URL parameters

dashboard_id
required integer

Headers

Authorization
required string

Body parameters

chart_type
required string
queries
required array
name
string
description
string
x
integer
y
integer
w
6 integer
h
4 integer
settings
object
201

Response body

{
  "data": {
    "id": "568",
    "type": "chart",
    "attributes": {
      "chart_type": "line_chart",
      "name": "New API Chart",
      "description": null,
      "x": 0,
      "y": 4,
      "w": 6,
      "h": 4,
      "settings": {},
      "queries": [
        {
          "id": 789,
          "query_type": "sql_expression",
          "source_variable": "source",
          "sql_query": "SELECT count() FROM {{source}}"
        }
      ]
    }
  }
}

If the created chart's position overlaps with existing charts or sections, the layout will be automatically consolidated after a short delay. The response will include a warnings field in this case.

Example request

cURL
curl --request POST \
  --url https://telemetry.betterstack.com/api/v2/dashboards/1234/charts \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
    "chart_type": "line_chart",
    "name": "New API Chart",
    "x": 0,
    "y": 4,
    "queries": [
      {
        "query_type": "sql_expression",
        "sql_query": "SELECT {{time}} as time, count(*) as value FROM {{source}} GROUP BY time"
      }
    ]
  }'


Chart and query compatibility

Not all query types are compatible with all chart types. Use this matrix to ensure you are using a valid combination.

Chart Type sql_expression tail_query static_text funnel_query (read-only)
line_chart Yes Yes - -
bar_chart Yes Yes - -
number_chart Yes Yes - -
table_chart Yes - - -
pie_chart Yes - - -
gauge_chart Yes Yes - -
tail_chart - Yes - -
static_text_chart - - Yes -
text_chart Yes Yes - -
scatter_chart Yes - - -
heatmap_chart Yes - - -
map_chart Yes - - -
anomalies_chart - Yes - -
funnel_chart - - - Yes

Queries

Each object in the queries array defines a data source for the chart.

  • query_type - The type of query. Choose one of:
    • sql_expression for querying using SQL.
    • tail_query for log filtering, similar to Live tail.
    • static_text for static markdown text.
  • sql_query - The SQL query string. Required for sql_expression.
  • where_condition - The filter query for tail_query.
  • static_text - The markdown content for static_text_chart.
  • source_variable - The name of the source type variable to use. Defaults to source.

Limitations

  • Read-only query types: Query types like query_builder, pql_expression, and funnel_query cannot be created or modified via the API as they require client-side compilation to SQL. These may appear in chart configurations or error messages.
  • funnel_chart: This chart type cannot be created via the API because it only accepts funnel_query, which is a read-only query type.
  • Multiple queries: Only line_chart supports multiple queries. All other chart types accept only a single query.