How Do I Show Percent of Students?

How Do I Show Percent of Students?

In a custom dashboard, you can easily build a bar chart that shows the number of unique students per course.

Chart Builder with simulated data offered in the free Veracity Learning LRS.

Problem

But what if you want to show the number of unique students per course as a percentage of all students?

Solution

You’ll need to count unique students per course, count all unique students, and then calculate the percentage proportion per course. You can’t do all that in Chart Builder. You must use Veracity Query Language (VQL).
  1. In your custom dashboard, from the left menu, select Add a Widget.

  2. In the Add a Widget pop-up, click Custom VQL Query.

  3. In the Advance Chart Builder page, in the Monaco Editor in the left panel, paste the following code:
{   "title": "Students per Course",
"subtitle": "Percent of All Students",
"filter": null,
"process": [{
"$frequentValues": {
"path": "context.contextActivities.parent.definition.name.en-US",
"limit": 100,
"metrics": {"metric1": {"$range": "actor.id"}},
"sort": {"count": "desc"}}}, {
"$addFields": {
"metric2": {
"$inlineSubQuery": {
"select": {"path": "$[0].value", "mode": "one"},
"filter": {"$source": "statements"},
"process": [{"$range": {"path": "actor.id"}}]}}}}, {
"$addFields": {
"metric3": {"$multiply": [{"$divide": ["$metric1", "$metric2"]}, 100]}}}, {
"$barChart": {
"categoryPath": "_id",
"valuePath": "metric3",
"sortCategory": false}}, {
"$addFields": {
"chart.yAxes.0.min": 0,
"chart.yAxes.0.max": 100,
"chart.yAxes.0.strictMinMax": true}}]}
  1. Click the OK button.

Outcome

You should then see a chart like this:


Notes

This custom code works because it builds a collection of documents with the iterative $frequentValues command and counts the unique students per course, and within that process it includes a count of all students using an $inlineSubQuery. This creates one collection with two fields per document: one varying and one static. It then calculates a third metric value as the percentage of the other two and charts that third metric.

A few small aesthetic details include:
  1. Turn sortCategory off so the chart inherits the sort order from the $frequentValues command.

  2. Change chart.yAxes properties to fit the chart to the limits of the percentages, as shown in the amCharts reference.


    • Related Articles

    • How Do I Tag Groups of Students?

      Our Veracity Launch LMS has a Learner Profile Field feature that lets you “tag” or label a student as belonging to a group that you designate. Then, you can use these metadata tags to streamline later operations on those students and groups in the ...
    • How Do I Add ‘Storytelling’ to a Dashboard?

      If you only use the out-of-the-box dashboards, or have a custom dashboard with one widget, then you’re all set. But, if you decide to build a custom dashboard (or more) with many widgets, then you must consider the overall design. “Widgets” include ...
    • Will Students See Errors in an xAPI Course with No LRS?

      If you develop an xAPI course package and don't yet have an LRS, or the LRS is down, then the student should not see any error messages. It will depend on the authoring tool you use. To be sure, you should test it. We've gotten more questions about ...
    • What Types of Charts Can I Make in the LRS?

      In general, you can make charts in a custom dashboard using two methods: using our Chart Builder, or by programming our Veracity Query Language (VQL). Chart Builder Charts The Chart Builder and similar form-based wizards in the Veracity Learning LRS ...
    • How Do I Build a Sankey Chart?

      How to Build a Sankey Chart If you want to analyze navigation patterns in your course, then you can show branching — and even abandonment — with a Sankey chart. How to create — In an Advanced Graph Query widget, insert code like this… { "title": ...