# Update a chart

Updates an existing chart by its ID. You only need to provide the fields you want to change.

[info]
When updating `queries`, the entire array will be replaced with the one you provide. Partial updates to queries are not supported.
[/info]

[endpoint]
base_url = "https://telemetry.betterstack.com"
path = "/api/v2/dashboards/{dashboard_id}/charts/{id}"
method = "PATCH"

[[path_param]]
name = "dashboard_id"
description = "The unique identifier of the dashboard."
required = true
type = "integer"

[[path_param]]
name = "id"
description = "The unique identifier of the chart to update."
required = true
type = "integer"

[[body_param]]
name = "name"
description = "A new name for the chart."
required = false
type = "string"

[[body_param]]
name = "description"
description = "A new description for the chart."
required = false
type = "string"

[[body_param]]
name = "settings"
description = "A new JSON object for chart-specific settings (e.g., units, stacking). This will replace the entire existing settings object."
required = false
type = "object"

[[body_param]]
name = "chart_type"
description = "A new type for the chart. The new type must be compatible with the chart's existing queries."
required = false
type = "string"

[[body_param]]
name = "queries"
description = "A new array of query objects to replace the existing ones."
required = false
type = "array"

[[body_param]]
name = "x"
description = "A new horizontal position."
required = false
type = "integer"

[[body_param]]
name = "y"
description = "A new vertical position."
required = false
type = "integer"

[[body_param]]
name = "w"
description = "A new width in grid units."
required = false
type = "integer"

[[body_param]]
name = "h"
description = "A new height in grid units."
required = false
type = "integer"

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"
[/endpoint]

[responses]
[[response]]
status = 200
description = "The chart was updated successfully."
body = '''
{
  "data": {
    "id": "567",
    "type": "chart",
    "attributes": {
      "chart_type": "line_chart",
      "name": "Updated Chart Name",
      "description": "Average CPU usage over time.",
      "x": 6,
      "y": 0,
      "w": 6,
      "h": 4,
      "settings": {
        "unit": "percent",
        "y_axis_scale": "linear"
      },
      "queries": [
        {
          "id": 890,
          "name": "CPU Query",
          "query_type": "sql_expression",
          "source_variable": "source",
          "sql_query": "SELECT {{time}} as time, avg(cpu) as value FROM metrics GROUP BY time"
        }
      ]
    }
  }
}
'''

[[response]]
status = 404
description = "The specified dashboard or chart was not found."
[/responses]

## Example request

```shell
[label cURL]
curl --request PATCH \
  --url https://telemetry.betterstack.com/api/v2/dashboards/1234/charts/567 \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "Updated Chart Name",
    "x": 6,
    "y": 0,
    "queries": [
      {
        "query_type": "sql_expression",
        "sql_query": "SELECT {{time}}, sum(value) FROM metrics GROUP BY time"
      }
    ]
  }'
```
