Creating simple graphs using Canvas
The first graph we want to produce is a simple line graph that shows the growth of our plants over time. Each lab has varying climate conditions, and we want to see how those conditions are affecting the growth of all plants, so the chart will have one line per lab showing the average of the median height measurements for all plots in the lab over the days of the experiment.
We'll start by creating a model method to return the raw data, then create a Canvas
-based line-chart view, and finally create an application callback to pull the data and send it to the chart view.
Creating the model method
Working with another data analyst at ABQ, you develop a SQL query that determines the day number of a plot check by subtracting its date from the oldest date in the plot_checks
table, then pulls lab_id
and the average of median_height
for all plants in the given lab on the given day. The query looks like this:
SELECT
date - (SELECT...