def get_quick_chart(json_data, output_file): qc = QuickChart() qc.width = 500 qc.width = 500 labels = [] #Declare to hold the x-axis tick labels weather_readings = [] #get the data labels for index in range(1, 8): local_time = datetime.datetime.fromtimestamp( json_data['daily'][index]['dt'], tz=pytz.timezone('Asia/Singapore')) labels.append(local_time.strftime('%a %d/%m ')) weather_readings.append( round(json_data['daily'][index]['temp']['day'], 1)) qc.config = """{ type: 'line', data: { labels: """ + str(labels) + """, datasets: [ { backgroundColor: 'rgb(255, 99, 132)', data: """ + str(weather_readings) + """, lineTension: 0.4, fill: false, } ], }, options: { title: { display: true, text: '7-Day Weather Forecast' }, legend: { display: false}, scales: { yAxes: [ { scaleLabel: { display: true, labelString: 'Temperature Degrees Celcius' } } ]}, plugins: { datalabels: { display: true, align: 'bottom', backgroundColor: '#ccc', borderRadius: 3 }, } }, }""" print(qc.get_short_url()) #Print out the chart URL qc.to_file(output_file) #Save to a file
from quickchart import QuickChart qc = QuickChart() qc.width = 600 qc.height = 300 qc.device_pixel_ratio = 2.0 qc.config = { "type": "bar", "data": { "labels": ["Hello world", "Test"], "datasets": [{ "label": "Foo", "data": [1, 2] }] } } qc.to_file('/tmp/mychart.png') print('Done.')