Skip to main content

Get Chart JSON

Retrieve chart data in structured JSON format for use with charting libraries.

Query Structure​

query GetChartJson($input: GetChartJsonInput!) {
getChartJson(input: $input) {
term_id
curve_id
graph_type
interval
count
data {
timestamp
value
}
}
}

Variables​

The query takes a single input object of type GetChartJsonInput:

FieldTypeRequiredDescription
term_idStringYesTerm ID to generate chart for
curve_idStringYesCurve ID (bonding curve)
intervalStringYesTime interval (e.g. "1h", "1d", "1w")
start_timeStringYesStart of time range (ISO 8601)
end_timeStringYesEnd of time range (ISO 8601)
graph_typeStringNoType of graph data
{
"input": {
"term_id": "0x57d94c116a33bb460428eced262b7ae2ec6f865e7aceef6357cec3d034e8ea21",
"curve_id": "1",
"interval": "1d",
"start_time": "2024-01-01T00:00:00Z",
"end_time": "2024-01-31T23:59:59Z"
}
}

Response Fields (ChartDataOutput)​

FieldTypeDescription
term_idString!Term ID for this chart
curve_idStringCurve ID used
graph_typeString!Type of graph
intervalString!Interval used for aggregation
countInt!Number of data points
data[ChartDataPoint!]!Array of chart data points
data[].timestampString!ISO 8601 timestamp for this data point
data[].valueString!Value at this timestamp

Interactive Example​

Query

query GetChartJson($input: GetChartJsonInput!) {
  getChartJson(input: $input) {
    term_id
    curve_id
    graph_type
    interval
    count
    data {
      timestamp
      value
    }
  }
}

Variables

Click "Run Query" to execute the GraphQL query and see results

Use Cases​

Recharts Integration​

import { GraphQLClient } from 'graphql-request'
import { API_URL_PROD } from '@0xintuition/graphql'

const client = new GraphQLClient(API_URL_PROD)

async function getChartData(termId: string, curveId: string, days: number = 30) {
const endTime = new Date()
const startTime = new Date()
startTime.setDate(startTime.getDate() - days)

const query = `
query GetChartJson($input: GetChartJsonInput!) {
getChartJson(input: $input) {
count
data
interval
}
}
`

const result = await client.request(query, {
input: {
term_id: termId,
curve_id: curveId,
interval: '1d',
start_time: startTime.toISOString(),
end_time: endTime.toISOString()
}
})

return result.getChartJson
}