Skip to main content

Text2Chart API

Converts natural language queries to SQL, executes the query, and automatically generates interactive charts from the data.

POST/agent/api/v2/generate-chart

Request Parameters

ParameterTypeRequiredDescription
querystringYesNatural language query
streambooleanNoWhether to return streaming response
Default: true

AI Chart Selection

The system automatically analyzes your data and query to select the most suitable chart type:

  • Line Chart - Time series and trend data
  • Bar Chart - Categorical comparisons
  • Pie Chart - Proportional data
  • Scatter Plot - Correlation analysis
  • Area Chart - Cumulative data

Response Format

Standard Response (stream: false)

{
"sql": "SELECT date, price FROM token_prices WHERE date >= CURRENT_DATE - INTERVAL '30 days'",
"data": [
{"date": "2024-01-01", "price": 100.5},
{"date": "2024-01-02", "price": 102.3}
],
"chart": {
"chartType": "line",
"htmlCode": "<div>...</div>",
"previewUrl": "https://...",
"dataInsights": ["Price shows upward trend", "Peak reached on January 15th"],
"generationTime": 1500
},
"timestamp": "2024-01-20T10:30:00Z"
}

Streaming Response Event Types

Event TypeDescription
chart_startChart generation started
node_executionWorkflow node executing
chart_sql_completeSQL query execution completed
chart_generation_completeChart generation completed
chart_completeEntire process completed
chart_errorChart generation error
llm_start / token / llm_endLLM generation process

Responses

Chart generation successful
{
  "sql": "SELECT date, price FROM token_prices WHERE date >= CURRENT_DATE - INTERVAL '30 days'",
  "data": [
    {
      "date": "2024-01-01",
      "price": 100.5
    },
    {
      "date": "2024-01-02",
      "price": 102.3
    },
    {
      "date": "2024-01-03",
      "price": 98.7
    }
  ],
  "chart": {
    "chartType": "line",
    "htmlCode": "<div class=\"chart-container\"><canvas id=\"chart\"></canvas></div>",
    "previewUrl": "https://charts.hubble-rpc.xyz/preview/abc123",
    "dataInsights": [
      "Price shows upward trend",
      "Peak reached on January 15th",
      "Average daily volume: $2.5M"
    ],
    "generationTime": 1500
  },
  "timestamp": "2024-01-20T10:30:00Z"
}