Skip to content

Instantly share code, notes, and snippets.

@bondgeek
Last active January 17, 2022 20:52
Show Gist options
  • Select an option

  • Save bondgeek/240a69d0cc06ad024e5cdca2a8e3c250 to your computer and use it in GitHub Desktop.

Select an option

Save bondgeek/240a69d0cc06ad024e5cdca2a8e3c250 to your computer and use it in GitHub Desktop.
# from
# https://quickchart.io/documentation/send-charts-in-email/#render-the-chart-image
# https://stackoverflow.com/questions/13137817/how-to-download-image-using-requests
#
# see also
# https://www.chartjs.org/docs/2.9.4/charts/doughnut.html
import shutil
import requests
churl = "https://quickchart.io/chart?c={type:'bar',data:{labels:[2012,2013,2014,2015,2016],datasets:[{label:'Users',data:[120,60,50,180,120]}]}}"
r = requests.get(churl, stream=True)
assert r.status_code == 200, f"chart failed: {r.status_code}"
with ("test.png", "wb") as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment