Skip to content Skip to sidebar Skip to footer

Graphing Sqlite3 Data With Reportlab

trying to lineplot simple temperature data from a sqlite3 database. New to python, not sure what I'm doing wrong. my data from sql looks like: [(70.8,), (70.8,), (70.9,), (71.0,)

Solution 1:

after going through the report lab documentation and experimenting with their examples I determined the problem was with how my data was presented. Using the sample data from the report lab documentation I was able to eliminate the error I was getting when renderPM was called.

Then based on the help from Muhammad Haseeb Khan and Paul Rooney in this post

I was able to data from [(70.1,), (71.1,),(71.1,)] to [(70.1, 71.1, 71.1)] by modifying the about code to:

c.execute("SELECT {idf} FROM {tn} WHERE {cnn}='Kitchen' AND {cn} BETWEEN '18:00:00' AND '23:59:59'".\
format(idf="temp", time="read_ID", tn=table_name, cnn="sensor_name",        
cn="recorded_time"))
all_date_times = c.fetchall()
print "readings from 6 pm to midnight = ", len(all_date_times)

level1 = [list(row) for row in all_date_times]

level2=[i[0] for i in all_date_times]

level3=[tuple(level2)]


#### build report lab chart

drawing = Drawing(600, 400)
data = level3
lc = HorizontalLineChart()
lc.x = 25
lc.y = 25
lc.height = 450
lc.width = 550
lc.data = data
lc.joinedLines = 1
lc.valueAxis.valueMin = 70
lc.valueAxis.valueMax = 75
drawing.add(lc)
renderPM.drawToFile(drawing, 'chartgraphicfile.png')

Post a Comment for "Graphing Sqlite3 Data With Reportlab"