Skip to main content

Using the QuickChart Table Image API

QuickChart provides an API that lets you render a table as a PNG. This format allows the table to be portable, making it easy to embed tables in Slack bots, no-code applications, and more.

Getting started

The table API endpoint is available at https://api.quickchart.io/v1/table. It works by taking a data parameter that defines the columns and rows of the table. Here's an example data parameter:

{
"title": "My table",
"columns": [
{
"title": "Column 1",
"dataIndex": "col1"
},
{
"title": "Column 2",
"dataIndex": "col2"
}
],
"dataSource": [
{
"col1": "Foo",
"col2": 12
},
{
"col1": "Foo",
"col2": 12
}
]
}

Pack it into the URL, like so:

https://api.quickchart.io/v1/table?data={"title":"My table","columns":[{"title":"Column 1","dataIndex":"col1"},{"title":"Column 2","dataIndex":"col2"}],"dataSource":[{"col1":"Foo","col2":12},{"col1":"Foo","col2":12}]}

This creates the following image:

Not bad for a basic table. Here's a more advanced configuration. We're setting the width and alignment of columns. Also, notice that using - in dataSource will create a line.

{
"title": "Marketing Summary",
"columns": [
{
"width": 200,
"title": "Campaign",
"dataIndex": "campaign"
},
{
"width": 100,
"title": "Install",
"dataIndex": "install",
"align": "right"
},
{
"width": 100,
"title": "Cost",
"dataIndex": "cost",
"align": "right"
}
],
"dataSource": [
"-",
{
"campaign": "Google CPC",
"install": "12",
"cost": "$ 400"
},
{
"campaign": "Facebook CPC",
"install": "3",
"cost": "$ 60"
},
{
"campaign": "Youtube Video",
"install": "131",
"cost": "$ 1,230"
},
"-",
{
"campaign": "Total",
"install": "146",
"cost": "$ 1,690"
}
]
}

Once again, pack the above configuration into the URL:

https://api.quickchart.io/v1/table?data={"title":"Marketing Summary","columns":[{"width":200,"title":"Campaign","dataIndex":"campaign"},{"width":100,"title":"Install","dataIndex":"install","align":"right"},{"width":100,"title":"Cost","dataIndex":"cost","align":"right"}],"dataSource":["-",{"campaign":"Google CPC","install":"12","cost":"$ 400"},{"campaign":"Facebook CPC","install":"3","cost":"$ 60"},{"campaign":"Youtube Video","install":"131","cost":"$ 1,230"},"-",{"campaign":"Total","install":"146","cost":"$ 1,690"}]}

This is the generated PNG image:

Customizing your table

The underlying renderer is the open-source table-renderer project. We accept an options parameter with the following attributes:

ParameterTypeDescriptionDefault value
cellWidthnumberDefault width for a table cell100
cellHeightnumberDefault height for a table cell40
offsetLeftnumberDefault text offset from left border of table cell8
offsetRightnumberDefault text offset from top border of table cell26
spacingnumberSpacing between tables20
titleSpacingnumberSpacing between title and table10
fontFamilystringFont to usesans-serif
paddingVerticalnumberVertical padding of image0
paddingHorizontalnumberHorizontal padding of image0
backgroundColorstringBackground color#ffffff

Here's an example in which we use the options parameter to change the padding, background, and font of the table:

https://api.quickchart.io/v1/table?data={"title":"Marketing Summary","columns":[{"width":200,"title":"Campaign","dataIndex":"campaign"},{"width":100,"title":"Install","dataIndex":"install","align":"right"},{"width":100,"title":"Cost","dataIndex":"cost","align":"right"}],"dataSource":["-",{"campaign":"Google CPC","install":"12","cost":"$ 400"},{"campaign":"Facebook CPC","install":"3","cost":"$ 60"},{"campaign":"Youtube Video","install":"131","cost":"$ 1,230"},"-",{"campaign":"Total","install":"146","cost":"$ 1,690"}]}&options={"paddingVertical":20,"paddingHorizontal":20,"backgroundColor":"%23eee","fontFamily":"mono"}

Note that we have URL-encoded special characters. It is best practice to URL encode the entirety of each query parameter. Nearly every programming language has built-in URL encoding capability.

This gives us the following image:

Using a POST request

All the examples so far are GET requests, but you can POST the https://api.quickchart.io/v1/table endpoint too. Here's an example payload with content-type application/json:

{
"data": {
"title": "Marketing Summary",
"columns": [
{
"width": 200,
"title": "Campaign",
"dataIndex": "campaign"
},
{
"width": 100,
"title": "Install",
"dataIndex": "install",
"align": "right"
},
{
"width": 100,
"title": "Cost",
"dataIndex": "cost",
"align": "right"
}
],
"dataSource": [
"-",
{
"campaign": "Google CPC",
"install": "12",
"cost": "$ 400"
},
{
"campaign": "Facebook CPC",
"install": "3",
"cost": "$ 60"
},
{
"campaign": "Youtube Video",
"install": "131",
"cost": "$ 1,230"
},
"-",
{
"campaign": "Total",
"install": "146",
"cost": "$ 1,690"
}
]
},
"options": {
"paddingVertical": 20,
"paddingHorizontal": 20,
"backgroundColor": "#eee",
"fontFamily": "mono"
}
}

You can curl this directly:

curl -X POST -H 'content-type: application/json' -d @table.json -o table.png https://api.quickchart.io/v1/table

Conclusion

This API makes it straightforward to include basic tables as static images. You can use the options to customize the look & feel of your table. Check out the table-renderer open-source project for further details on building tables.

Stuck? Have questions? Feature request? Please reach out!


Ian Webster

About the author

Ian Webster is a software engineer and former Googler based in San Mateo, California. He has helped Google, NASA, and governments around the world improve their data pipelines and visualizations. In 2018, Ian created QuickChart, a collection of open-source APIs that support data visualization efforts.

Email · LinkedIn · Twitter