Skip to main content

Get Chart SVG

Retrieve a pre-rendered chart as an SVG image, ready for embedding in HTML or documents.

Query Structure​

query GetChartSvg($input: GetChartSvgInput!) {
getChartSvg(input: $input) {
svg
}
}

Variables​

The query takes a single input object of type GetChartSvgInput:

FieldTypeRequiredDescription
term_idStringYesTerm ID to generate chart for
curve_idStringYesCurve ID (bonding curve)
intervalStringYesTime interval (e.g. "1h", "1d")
start_timeStringYesStart of time range (ISO 8601)
end_timeStringYesEnd of time range (ISO 8601)
graph_typeStringNoType of graph data
widthIntNoChart width in pixels
heightIntNoChart height in pixels
background_colorStringNoBackground color (e.g. "#1a1a2e")
line_colorStringNoLine color (e.g. "#00ff00")
{
"input": {
"term_id": "0x57d94c116a33bb460428eced262b7ae2ec6f865e7aceef6357cec3d034e8ea21",
"curve_id": "1",
"interval": "1d",
"start_time": "2024-01-01T00:00:00Z",
"end_time": "2024-01-31T23:59:59Z",
"width": 800,
"height": 400
}
}

Response Fields (ChartSvgOutput)​

FieldTypeDescription
svgString!SVG markup string

Expected Response​

{
"data": {
"getChartSvg": {
"svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"800\" height=\"400\">...</svg>"
}
}
}

Interactive Example​

Query

query GetChartSvg($input: GetChartSvgInput!) {
  getChartSvg(input: $input) {
    svg
  }
}

Variables

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

Use Cases​

Direct HTML Embedding​

async function displayChart(termId: string, curveId: string, containerId: string) {
const query = `
query GetChartSvg($input: GetChartSvgInput!) {
getChartSvg(input: $input) {
svg
}
}
`

const endTime = new Date()
const startTime = new Date()
startTime.setDate(startTime.getDate() - 30)

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

document.getElementById(containerId).innerHTML = response.getChartSvg.svg
}