Configurable reports: Creating graphs from database queries

Configurable reports: Creating graphs from database queries

by Betty Grazia -
Number of replies: 2

Can someone please share some sample bar/ pie charts created from database queries

Average of ratings: -
In reply to Betty Grazia

Re: Configurable reports: Creating graphs from database queries

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi Betty,
I don't have any examples for Configurable reports, but the grade pages for MooTyper has code for bar charts made from various database queries. The two files that include charts are the gview.php and owngrades.php files, with the pertinent code at the end of each of the files.
In reply to Betty Grazia

Re: Configurable reports: Creating graphs from database queries

by Mark Sharp -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
When you fetch data from the database the array is indexed by the first field returned (usually an id). When you're creating a series of data for the chart, you need to ensure the array is indexed sequentially (0,1,2 etc) - array_values($yourresults) - should do the trick.
ChartAPI documentation: https://docs.moodle.org/dev/Charts_API

This is a chart I've been working on: https://github.com/ltu-solent/moodle-report_participationlog/blob/main/classes/partchart.php