Python
⚡️Official Image-charts Python library
Install / Use
/learn @image-charts/PythonREADME
Official Image Charts API client. Generate URLs of static image charts. Embed them everywhere in emails, pdf reports, chat bots...!
Getting started
1. Install Image-Charts Python Package
pip install image-charts
2. Import Image-Charts library
from ImageCharts import ImageCharts
3. Generate a chart image
pie = ImageCharts().cht('p').chd('a:2.5,5,8.3').chs('100x100')
pie.to_url()) # https://image-charts.com/chart?chd=a%3A2.5%2C5%2C8.3&chs=600x300&cht=p
pie.to_file('/path/to/chart.png'); #
pie.to_data_uri() # data:image/png;base64,iVBORw0KGgo...
pie.to_binary() # b'\x89PNG\r\n\x1a\n\x00\x00...
<p align="center">
<a href="https://www.image-charts.com/">
<img src="https://image-charts.com/chart?cht=bvs&chd=s:theresadifferencebetweenknowingthepathandwalkingthepath&chs=700x200&chxt=y&chf=b0,lg,90,4CA4F5,0.1,C371D3,0.8,EA469E,1" />
</a>
</p>
Table of Contents
- Enterprise support
- On-Premise support
- Constructor
- Methods
- to_url()
- to_file()
- to_buffer()
- to_data_uri()
- cht(value) - Chart type
- chd(value) - chart data
- chds(value) - data format with custom scaling
- choe(value) - QRCode data encoding
- chld(value) - QRCode error correction level and optional margin
- chxr(value) - Axis data-range
- chof(value) - Image output format
- chs(value) - Chart size (<width>x<height>)
- chdl(value) - Text for each series, to display in the legend
- chdls(value) - Chart legend text and style
- chg(value) - Solid or dotted grid lines
- chco(value) - series colors
- chtt(value) - chart title
- chts(value) - chart title colors and font size
- chxt(value) - Display values on your axis lines or change which axes are shown
- chxl(value) - Custom string axis labels on any axis
- chxs(value) - Font size, color for axis labels, both custom labels and default label values
- chm(value) - compound charts and line fills
- chls(value) - line thickness and solid/dashed style
- chl(value) - bar, pie slice, doughnut slice and polar slice chart labels
- chlps(value) - Position and style of labels on data
- chma(value) - chart margins
- chdlp(value) - Position of the legend and order of the legend entries
- chf(value) - Background Fills
- chbr(value) - Bar corner radius. Display bars with rounded corner.
- chan(value) - gif configuration
- chli(value) - doughnut chart inside label
- icac(value) - image-charts enterprise
account_id - ichm(value) - HMAC-SHA256 signature required to activate paid features
- icff(value) - Default font family for all text from Google Fonts. Use same syntax as Google Font CSS API
- icfs(value) - Default font style for all text
- iclocale(value) - localization (ISO 639-1)
- icretina(value) - retina mode
- icqrb(value) - Background color for QR Codes
- icqrf(value) - Foreground color for QR Codes
Constructor
Create an instance, the argument within [ ] is optional. See usage
ImageCharts( [ Dict opt ] )
Options
Default options are listed below.
opt = {
#
# Request timeout (in millisecond) when calling to_binary() or to_data_uri()
#
'timeout': 5000,
#
# (Enterprise and Enterprise+ subscription only) SECRET_KEY
#
'secret': null,
#
# (Enterprise, Enterprise+ and On-Premise subscription only) custom domain
#
'host': 'image-charts.com',
#
# (On-Premise subscription only) custom protocol
#
'protocol': 'https',
#
# (On-Premise subscription only) custom port
#
'port': 443,
#
# (On-Premise subscription only) custom pathname
#
'pathname': '/chart'
}
Methods
<a name="to_url"></a>
to_url() : String
Get the full Image-Charts API url (signed and encoded if necessary)
Usage
from ImageCharts import ImageCharts
# vertical bar chart
# 300px x 300px
# 2 data points: 60 and 40
# get the generated URL
chart_url = ImageCharts().cht('bvg') .chs('300x300') .chd('a:60,40') .to_url()
print(chart_url) # https://image-charts.com/chart?cht=bvg&chs=300x300&chd=a%3A60%2C40
<a name="to_file"></a>
to_file() : String
Creates a file containing generated chart image (blocking)
Usage
from ImageCharts import ImageCharts
# genertates a
# vertical bar chart (cht=bvg)
# of 300px x 300px (chs=300x300)
# with 2 data points: 60 and 40 (chd=a:60,40)
# and write it to /tmp/chart.png
ImageCharts().cht('bvg').chs('300x300').chd('a:60,40').to_file('/tmp/awesome_chart.png')
<a name="to_binary"></a>
to_binary() : Buffer
Do a request to Image-Charts API with current configuration and yield image data as bytes
Usage
from ImageCharts import ImageCharts
# vertical bar chart
# 300px x 300px
# 2 data points: 60 and 40
# download chart image
chart_url = ImageCharts().cht('bvg').chs('300x300').chd('a:60,40').to_binary()
print(chart_url) # b'\x89PNG\r\n\x1a\n\x00\x00...
<a name="to_data_uri"></a>
to_data_uri() : String
Do a blocking request to Image-Charts API with current configuration and yield a base64 encoded data URI
Usage
from ImageCharts import ImageCharts
# vertical bar chart
# 300px x 300px
# 2 data points: 60 and 40
# download chart image and generate a data URI string
chart_url = ImageCharts().cht('bvg').chs('300x300').chd('a:60,40').to_data_uri()
print(chart_url) # "data:image/png;base64,iVBORw0KGgo...
Enterprise Support
Image-Charts Enterprise and Enterprise+ subscriptions remove the watermark and enable advanced features like custom-domain, high-resolution charts, custom fonts, multiple axis and mixed charts.
Usage
Once subscribed to a plan you will receive an ACCOUNT_ID and a SECRET_KEY.
These two parameters are mandatory to sign your request and remove the watermark.
Replace both values in the code example below:
from ImageCharts import ImageCharts
# pie chart
# 700px x 190px
# 2 data points: 60 and 40
# 1 label per pie slice : "Hello" and "World"
# 1 gradient per pie slice
# enable paid-only features like high-resolution charts
# get the whole (HMAC signed) URL
chart_url = ImageCharts({'secret': 'SECRET_KEY'}).icac('ACCOUNT_ID').cht('p3').chs('700x190').chd('t:60,40').chl('Hello|World').chf('ps0-0,lg,45,ffeb3b,0.2,f44336,1|ps0-1,lg,45,8bc34a,0.2,009688,1').icretina('1').to_url()
print(chart_url)
# https://image-charts.com/chart?chd=t%3A60%2C40&chf=ps0-0%2Clg%2C45%2Cffeb3b%2C0.2%2Cf44336%2C1%7Cps0-1%2Clg%2C45%2C8bc34a%2C0.2%2C009688%2C1&chl=Hello%7CWorld&chs=700x190&cht=p3&icac=documentation&icretina=1&ichm=122242bb700d825d69b3fafe4ec67193b45dcfe0ed93fcca307e0d0a84b73ea2
<p align="center"><img src="https://image-charts.com/chart?chd=t%3A60%2C40&chf=ps0-0%2Clg%2C45%2Cffeb3b%2C0.2%2Cf44336%2C1%7Cps0-1%2Clg%2C45%2C8bc34a%2C0.2%2C009688%2C1&chl=Hello%7CWorld&chs=700x190&cht=p3&icac=documentation&icretina=1&ichm=122242bb700d825d69b3fafe4ec67193b45dcfe0ed93fcca307e0d0a84b73ea2"/></p>
On-Premise Support
Image-Charts virtual appliance can be deployed anywhere inside

