Package: quickchart-io
quickchart-pythonA Python client for thequickchart.ioimage charts web service.InstallationUse thequickchart.pylibrary in this project, or install throughpip:pip install quickchart.ioUsageThis library provides aQuickChartclass.  Import and instantiate it.  Then set properties on it and specify aChart.jsconfig:fromquickchartimportQuickChartqc=QuickChart()qc.width=500qc.height=300qc.config={"type":"bar","data":{"labels":["Hello world","Test"],"datasets":[{"label":"Foo","data":[1,2]}]}}Useget_url()on your quickchart object to get the encoded URL that renders your chart:print(qc.get_url())# https://quickchart.io/chart?c=%7B%22chart%22%3A+%7B%22type%22%3A+%22bar%22%2C+%22data%22%3A+%7B%22labels%22%3A+%5B%22Hello+world%22%2C+%22Test%22%5D%2C+%22datasets%22%3A+%5B%7B%22label%22%3A+%22Foo%22%2C+%22data%22%3A+%5B1%2C+2%5D%7D%5D%7D%7D%7D&w=600&h=300&bkg=%23ffffff&devicePixelRatio=2.0&f=pngIf you have a long or complicated chart, useget_short_url()to get a fixed-length URL using the quickchart.io web service (note that these URLs only persist for a short time unless you have a subscription):print(qc.get_short_url())# https://quickchart.io/chart/render/f-a1d3e804-dfea-442c-88b0-9801b9808401The URLs will render an image of a chart:Using Javascript functions in your chartChart.js sometimes relies on Javascript functions (e.g. for formatting tick labels).  There are a couple approaches:Build chart configuration as a string instead of a Python object.  Seeexamples/simple_example_with_function.py.Build chart configuration as a Python object and include a placeholder string for the Javascript function.  Then, find and replace it.Use the providedQuickChartFunctionclass.  Seeexamples/using_quickchartfunction.pyfor a full example.A short example usingQuickChartFunction:qc=QuickChart()qc.config={"type":"bar","data":{"labels":["A","B"],"datasets":[{"label":"Foo","data":[1,2]}]},"options":{"scales":{"yAxes":[{"ticks":{"callback":QuickChartFunction('(val) => val + "k"')}}],"xAxes":[{"ticks":{"callback":QuickChartFunction('''function(val) {return val + '???';}''')}}]}}}print(qc.get_url())Customizing your chartYou can set the following properties:config: dict or strThe actual Chart.js chart configuration.width: intWidth of the chart image in pixels.  Defaults to 500height: intHeight of the chart image  in pixels.  Defaults to 300format: strFormat of the chart. Defaults to png. svg is also valid.background_color: strThe background color of the chart. Any valid HTML color works. Defaults to #ffffff (white). Also takes rgb, rgba, and hsl values.device_pixel_ratio: floatThe device pixel ratio of the chart. This will multiply the number of pixels by the value. This is usually used for retina displays. Defaults to 1.0.version: strThe version of Chart.js to use. Acceptable values are documentedhere. Usually used to select Chart.js 3+.hostOverride the host of the chart render server. Defaults to quickchart.io.keySet an API key that will be included with the request.Getting URLsThere are two ways to get a URL for your chart object.get_url(): strReturns a URL that will display the chart image when loaded.get_short_url(): strUses the quickchart.io web service to create a fixed-length chart URL that displays the chart image.  Returns a URL such ashttps://quickchart.io/chart/render/f-a1d3e804-dfea-442c-88b0-9801b9808401.Note that short URLs expire after a few days for users of the free service.  You cansubscribeto keep them around longer.Other functionalityget_bytes()Returns the bytes representing the chart image.to_file(path: str)Writes the chart image to a file path.More examplesCheckout theexamplesdirectory to see other usage.