update_chart
Modify existing Datawrapper chart data or configuration while preserving the original chart type. Update titles, styling, axes, and data points for visualizations.
Instructions
⚠️ DATAWRAPPER MCP TOOL ⚠️ This is part of the Datawrapper MCP server integration.
Update an existing Datawrapper chart's data or configuration using Pydantic models.
⚠️ IMPORTANT LIMITATION: You CANNOT change the chart type with this tool. Chart types are immutable once created. To change from one chart type to another (e.g., column → stacked_bar, or line → area), you must create a new chart instead.
WHAT YOU CAN UPDATE: • Chart data (add/modify/replace data points) • Title, intro, byline, source information • Colors, styling, axes configuration • Tooltips, annotations, labels • Any other configuration options for the existing chart type
WHAT YOU CANNOT UPDATE: ✗ Chart type (bar, line, column, etc.) - this is permanent
The chart_config must use high-level Pydantic fields only (title, intro, byline, source_name, source_url, etc.). Do NOT use low-level serialized structures like 'metadata', 'visualize', or other internal API fields.
STYLING UPDATES: Use get_chart_schema to see available fields, then apply styling changes:
Colors: {"color_category": {"sales": "#ff0000"}}
Line properties: {"lines": [{"column": "sales", "width": "style2"}]}
Axis settings: {"custom_range_y": [0, 200], "y_grid_format": "0,0"}
Tooltips: {"tooltip_number_format": "0.0"}
See https://datawrapper.readthedocs.io/en/latest/ for detailed examples. The provided config will be validated through Pydantic and merged with the existing chart configuration.
Args: chart_id: ID of the chart to update data: New chart data (optional). Same formats as create_chart. chart_config: Updated chart configuration using high-level Pydantic fields (optional)
Returns: Confirmation message with editor URL
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chart_id | Yes | ||
| data | No | ||
| chart_config | No |
Implementation Reference
- handlers/update.py:12-59 (handler)The 'update_chart' handler function that processes data updates and configuration adjustments for a Datawrapper chart.
async def update_chart(arguments: UpdateChartArgs) -> list[TextContent]: """Update an existing chart's data or configuration.""" chart_id = arguments["chart_id"] # Get chart using factory function - returns correct Pydantic class instance chart = get_chart(chart_id) # Update data if provided if "data" in arguments: df = json_to_dataframe(arguments["data"]) chart.data = df # Update config if provided if "chart_config" in arguments: # Directly set attributes on the chart instance # Pydantic will validate each assignment automatically due to validate_assignment=True try: # Build a mapping of aliases to field names alias_to_field = {} for field_name, field_info in chart.model_fields.items(): # Add the field name itself alias_to_field[field_name] = field_name # Add any aliases if field_info.alias: alias_to_field[field_info.alias] = field_name for key, value in arguments["chart_config"].items(): # Convert alias to field name if needed field_name = alias_to_field.get(key, key) setattr(chart, field_name, value) except Exception as e: raise ValueError( f"Invalid chart configuration: {str(e)}\n\n" f"Use get_chart_schema to see the valid schema for this chart type. " f"Only high-level Pydantic fields are accepted." ) # Update using Pydantic instance method chart.update() result = { "chart_id": chart.chart_id, "message": "Chart updated successfully!", "edit_url": chart.get_editor_url(), } return [TextContent(type="text", text=json.dumps(result, indent=2))] - dw_types.py:20-26 (schema)The 'UpdateChartArgs' TypedDict defining the expected input structure for the 'update_chart' handler.
class UpdateChartArgs(TypedDict): """Arguments for update_chart handler.""" chart_id: str data: NotRequired[str | list[dict] | dict[str, list]] chart_config: NotRequired[dict[str, Any]] - server.py:289-349 (registration)The 'update_chart' tool registration in the MCP server, which interfaces with the 'update_chart_handler'.
async def update_chart( chart_id: str, data: str | list | dict | None = None, chart_config: dict | None = None, ) -> str: """⚠️ DATAWRAPPER MCP TOOL ⚠️ This is part of the Datawrapper MCP server integration. --- Update an existing Datawrapper chart's data or configuration using Pydantic models. ⚠️ IMPORTANT LIMITATION: You CANNOT change the chart type with this tool. Chart types are immutable once created. To change from one chart type to another (e.g., column → stacked_bar, or line → area), you must create a new chart instead. WHAT YOU CAN UPDATE: • Chart data (add/modify/replace data points) • Title, intro, byline, source information • Colors, styling, axes configuration • Tooltips, annotations, labels • Any other configuration options for the existing chart type WHAT YOU CANNOT UPDATE: ✗ Chart type (bar, line, column, etc.) - this is permanent The chart_config must use high-level Pydantic fields only (title, intro, byline, source_name, source_url, etc.). Do NOT use low-level serialized structures like 'metadata', 'visualize', or other internal API fields. STYLING UPDATES: Use get_chart_schema to see available fields, then apply styling changes: - Colors: {"color_category": {"sales": "#ff0000"}} - Line properties: {"lines": [{"column": "sales", "width": "style2"}]} - Axis settings: {"custom_range_y": [0, 200], "y_grid_format": "0,0"} - Tooltips: {"tooltip_number_format": "0.0"} See https://datawrapper.readthedocs.io/en/latest/ for detailed examples. The provided config will be validated through Pydantic and merged with the existing chart configuration. Args: chart_id: ID of the chart to update data: New chart data (optional). Same formats as create_chart. chart_config: Updated chart configuration using high-level Pydantic fields (optional) Returns: Confirmation message with editor URL """ arguments: dict[str, Any] = {"chart_id": chart_id} if data is not None: arguments["data"] = data if chart_config is not None: arguments["chart_config"] = chart_config try: result = await update_chart_handler(cast(UpdateChartArgs, arguments)) return result[0].text except Exception as e: return f"Error updating chart with ID '{chart_id}': {str(e)}"