- Populating a simple table with Real-time report data
- Adding additional tables with sorted data
- Calculating and displaying totals from the report data
- Displaying a line graph using the trended report data
Recall from lesson #2 that we simply displayed the raw report response on the page. This is very hard to read. We want to parse through the data and stick it in an HTML table.
-
Remove the
BASIC REPORT.RUN REQUESTcall that we uncommented the last lesson and uncomment the next section calledMOST POPULAR REPORT://///////////////////////// // MOST POPULAR REPORT /////////////////////////// var report = new RealTimeReport({ dataElement: "#data-table", dataElementType: "BasicTable", totalElement: null, animateTotal: false, refreshInterval: null }); report.run({ "reportDescription": { "source": "realtime", "reportSuiteID": "rtd-example", "algorithm": "most popular", "metrics": [ { "id": "instances" } ], "elements": [ { "id": "page" } ], "dateGranularity": "minute:60", "dateFrom": "-20 hours", "sortMethod": "mostpopular" } });
-
Click File > Live Preview. You should see the data in a tabular format on the page. The
report.runfunction executes the report the same way we did before and then formats the data and places it in the#data-tablepage element.
This report looks at the last 15 minutes of data so let's use it to power a line graph.
-
Simply uncomment the
TREND GRAPH REPORTreport request://///////////////////////// // TREND GRAPH REPORT /////////////////////////// report = new RealTimeReport({ dataElement: "#trendGraph", dataElementType: "BasicTable", totalElement: null, animateTotal: false, refreshInterval: null }); report.run({ "reportDescription": { "source": "realtime", "reportSuiteID": "rtd-example", "algorithm": "most popular", "metrics": [ { "id": "instances" } ], "elements": [ { "id": "page" } ], "dateGranularity": "minute:1", "dateFrom": "-15 minutes", "sortMethod": "mostpopular" } });
NOTE: Leave the existing
MOST POPULAR REPORTalone for now -
Modify the
dataElementTypeparameter of theTREND GRAPH REPORTto:dataElementType: "AnimatedTrendGraph",
-
Click File > Live Preview. The data is now formatted as displayed as a trended line graph.
Right now, the report only runs once when the page is loaded. Let's change it to refresh automatically every 10 seconds.
-
Modify the
refreshIntervalparameter of each report.run request to:refreshInterval: 10 -
Click File > Live Preview. If you wait 10 seconds you should see the data update itself.
The report data contains a total. Let's display it in a large animated format.
-
Modify the
animateTotalparameter of theTREND GRAPH REPORTto:totalElement: "#total", animateTotal: true,
-
Click File > Live Preview. The
report.runfunction grabs to total from the data, places it in the#totalpage element, and animates it using a JQuery plugin.
-
Copy the entire
report.runrequest from theMOST POPULAR REPORTwe've already placed and paste it below theTREND GRAPH REPORT. You can label this report request asGAINERS REPORT -
In the
report.runblock you just pasted, modify thealgorithm,sortMethod, anddateFromproperties of thereportDescriptionobject to:"algorithm": "gainers", "dateGranularity": "minute:1", "dateFrom": "-60 minutes", "sortMethod": "gainers"
-
In the
GAINERS REPORTrequest, change thedataElementparameter to:dataElement: "#gainers-table" -
Let's increase the refresh interval for this report. Change the
refreshIntervalparameter to:refreshInterval: 30 -
Click File > Live Preview. You you will now see a table of data sorted by gainers in addition to the line graph.
For an example of what the JavaScript Code should now look like, see the Finished HTML »
-
Copy the block for the
GAINERS REPORTand paste it below this request. Label the new blockLOSERS REPORT -
In the
report.runblock for the newLOSERS REPORT, modify thealgorithm,sortMethod, anddateFromproperties to:"algorithm": "losers", "dateGranularity": "minute:1", "dateFrom": "-60 minutes", "sortMethod": "losers"
-
In the same block, change the
dataElementparameter to:dataElement: "#losers-table" -
Click File > Live Preview. You you will now see a table of data sorted by losers in addition to the line graph and losers table.
Continue to Extra Credit Exercise 1 » (Advanced)


