- 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 REQUEST
call 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.run
function executes the report the same way we did before and then formats the data and places it in the#data-table
page 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 REPORT
report 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 REPORT
alone for now -
Modify the
dataElementType
parameter of theTREND GRAPH REPORT
to: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
refreshInterval
parameter 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
animateTotal
parameter of theTREND GRAPH REPORT
to:totalElement: "#total", animateTotal: true,
-
Click File > Live Preview. The
report.run
function grabs to total from the data, places it in the#total
page element, and animates it using a JQuery plugin.
-
Copy the entire
report.run
request from theMOST POPULAR REPORT
we've already placed and paste it below theTREND GRAPH REPORT
. You can label this report request asGAINERS REPORT
-
In the
report.run
block you just pasted, modify thealgorithm
,sortMethod
, anddateFrom
properties of thereportDescription
object to:"algorithm": "gainers", "dateGranularity": "minute:1", "dateFrom": "-60 minutes", "sortMethod": "gainers"
-
In the
GAINERS REPORT
request, change thedataElement
parameter to:dataElement: "#gainers-table"
-
Let's increase the refresh interval for this report. Change the
refreshInterval
parameter 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 REPORT
and paste it below this request. Label the new blockLOSERS REPORT
-
In the
report.run
block for the newLOSERS REPORT
, modify thealgorithm
,sortMethod
, anddateFrom
properties to:"algorithm": "losers", "dateGranularity": "minute:1", "dateFrom": "-60 minutes", "sortMethod": "losers"
-
In the same block, change the
dataElement
parameter 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)