generate_chart

Generates an Apache ECharts option with the executed rows embedded for rendering

Recent Requests
Log in to see full request history
TimeStatusUser Agent
Retrieving recent requests…
LoadingLoading…

The /generate_chart endpoint analyzes your question and data to produce an optimized visualization specification. It intelligently selects the appropriate chart type, colors, and layout based on your data characteristics and question intent.

Key Features

  • Automatic chart selection: Chooses the best visualization type based on your data
  • Embedded data: The executed rows are embedded in dataset.source for immediate rendering
  • Customizable instructions: Use customInstruction to request specific chart tweaks (e.g., renaming titles, sorting, changing chart type)

Wren AI charts are based on the Apache ECharts option.

Example

Response will be an Apache ECharts option you could render with the ECharts library. For example:

{
  "projectId": 1,
  "question": "Show me total payments by customer state",
  "sql": "SELECT customer_state, SUM(payment_value) AS total_payment_value FROM orders GROUP BY customer_state ORDER BY total_payment_value DESC",
  "customInstruction": "Rename the chart title to 'Payments by State'",
  "threadId": "75ab23c8-9124-4560-a125-fbe7e321dcba"
}

Understanding arguments

  • question: The original natural language query that was used to generate the SQL.
    It reflects the user’s data intent, not a prompt for customizing the chart appearance.
  • sql: The actual SQL statement generated from the question, which retrieves the necessary data for visualization.
  • customInstruction (optional)
    Instructions for how the visualization should be adjusted (e.g., change chart type, rename title, filter top N).
    This is separate from the question.

Response:

{
    "id": "a9597146-03ee-4de7-bcd6-57d71bffe86a",
    "chartSchema": {
        "title": {
            "text": "Payments by State",
            "left": "center"
        },
        "tooltip": {
            "trigger": "axis",
            "axisPointer": {
                "type": "shadow"
            }
        },
        "dataset": {
            "dimensions": [
                "customer_state",
                "total_payment_value"
            ],
            "source": [
                { "customer_state": "SP", "total_payment_value": 5998226.96 },
                { "customer_state": "RJ", "total_payment_value": 2144379.69 },
                { "customer_state": "MG", "total_payment_value": 1872257.26 },
                { "customer_state": "RS", "total_payment_value": 890898.54 },
                { "customer_state": "PR", "total_payment_value": 811156.38 },
                { "customer_state": "SC", "total_payment_value": 623086.43 },
                { "customer_state": "BA", "total_payment_value": 616645.82 },
                { "customer_state": "DF", "total_payment_value": 355141.08 },
                { "customer_state": "GO", "total_payment_value": 350092.31 },
                { "customer_state": "ES", "total_payment_value": 325967.55 },
                { "customer_state": "PE", "total_payment_value": 324850.44 },
                { "customer_state": "CE", "total_payment_value": 279464.03 },
                { "customer_state": "PA", "total_payment_value": 218295.85 },
                { "customer_state": "MT", "total_payment_value": 187029.29 },
                { "customer_state": "MA", "total_payment_value": 152523.02 },
                { "customer_state": "PB", "total_payment_value": 141545.72 },
                { "customer_state": "MS", "total_payment_value": 137534.84 },
                { "customer_state": "PI", "total_payment_value": 108523.97 },
                { "customer_state": "RN", "total_payment_value": 102718.13 },
                { "customer_state": "AL", "total_payment_value": 96962.06 },
                { "customer_state": "SE", "total_payment_value": 75246.25 },
                { "customer_state": "TO", "total_payment_value": 61485.33 },
                { "customer_state": "RO", "total_payment_value": 60866.2 },
                { "customer_state": "AM", "total_payment_value": 27966.93 },
                { "customer_state": "AC", "total_payment_value": 19680.62 },
                { "customer_state": "AP", "total_payment_value": 16262.8 },
                { "customer_state": "RR", "total_payment_value": 10064.62 }
            ]
        },
        "xAxis": {
            "type": "category"
        },
        "yAxis": {
            "type": "value",
            "name": "Total Payment Value"
        },
        "series": [
            {
                "name": "Total Payment Value",
                "type": "bar",
                "encode": {
                    "x": "customer_state",
                    "y": "total_payment_value"
                }
            }
        ]
    },
    "chartSchemaVersion": "v3",
    "threadId": "bfbef4db-5bb4-4133-a65f-9dd813569727"
}

The chart columns are bound through dataset.dimensions + series.encode, and the executed rows are injected into dataset.source. Pass the returned chartSchema straight to ECharts with myChart.setOption(chartSchema) and you'll see the rendered chart.

Error Handling

If chart generation fails, you'll receive an error response:

{
  "id": "c4f82c31-a40d-4b8e-9e5f-c1d8a742db55",
  "code": "INVALID_SQL_ERROR",
  "error": "Invalid SQL, please check your SQL syntax"
}

Error codes may include:

  • INVALID_SQL_ERROR: The SQL could not be executed (invalid syntax, or a table/column not defined in the MDL manifest)
  • FAILED_TO_GENERATE_VEGA_SCHEMA: The result could not be turned into a valid chart specification (shared code — the ECharts engine reuses it)

Supported Chart Types

Check Wren AI / Generate Chart for reference.

Body Params
integer
required
string
required
string
required
string
integer
Defaults to 10000

Integer in (0, 1000000].

string
Headers
string

Comma-separated key=value pairs applied as row/column-level security session properties (e.g. region=US,tier=pro). Unknown keys are echoed back in the invalidSessionProperties response field.

Responses

Language
Credentials
Bearer
LoadingLoading…
Response
Click Try It! to start a request and see the response here! Or choose an example:
application/json