select 'Product 1' as PRODUCT, '90' as VALUE_0,100.3 as VALUE_1,
200 as VALUE_2, '121' as VALUE_3, '' as Sparkline from DUAL
UNION
select 'Product 2' as PRODUCT, '80' as VALUE_0, 103 as VALUE_1,
140 as VALUE_2, '99' as VALUE_3, '' as Sparkline from DUAL
UNION
select 'Product 3' as PRODUCT, '1,345' as VALUE_0, 1000 as VALUE_1,
900 as VALUE_2, '1,200' as VALUE_3, '' as Sparkline from DUAL
UNION
select 'Product 4' as PRODUCT, '7' as VALUE_0, 10 as VALUE_1,
7 as VALUE_2, '124' as VALUE_3, '' as Sparkline from DUAL
UNION
select 'Product 5' as PRODUCT, '756' as VALUE_0, 432.99 as VALUE_1,
632 as VALUE_2, '134' as VALUE_3, '' as Sparkline from DUAL
UNION
select 'Product 6' as PRODUCT, '66' as VALUE_0, 34 as VALUE_1,
333 as VALUE_2, 'non number' as VALUE_3, '' as Sparkline from DUAL
add this code into execute when page loads. The code should work on your existing IR as long as you add a new column at the end to display the sparkline. In my dummy SQL above the column is called Sparkline.
// Uses JQuery sparkline to add sparklines to an APEX Interactive Report.
// https://omnipotent.net/jquery.sparkline/#s-about
//
// Comments welcome, how about building this into an Apex Plugin?
// davielang@gmail.com
$(function(){
// Get column values for each row and place them in the cols array
var data =$.each($('#IR_STATIC_ID tr'), function(index, tr){
var cols = []; // place the row column data in here
// for each column in the row
$.each($(tr).find("td").not(":first"), function(columnIndex, td){
// add column value to cols array only if its a number and not empty
if(!isNaN($(td).text().replace(',','')) && $(td).text().length > 0)
cols.push($(td).text().replace(',',''));
// if we are at the last column then add the sparkline.
if ((columnIndex+2)==$('#IR_STATIC_ID').columnCount()){
var dataSpan = $("<span>").appendTo($(td));
dataSpan.sparkline(cols, {
// For more options, see https://omnipotent.net/jquery.sparkline/#common
type: 'box',
barWidth : '10px',
width : '100px'
});
}
})
});
})
$.fn.columnCount = function() {
return $('th', $(this).find('tbody')).length;
};
(Note the code expects the first column to be text, if you do not have this change the code accordingly.)
I was having difficulty showing the tooltip as I assume the APEX CSS was causing the sparkline tooltip some issues. Add this to page inline CSS;
.jqstooltip { box-sizing: content-box;}
The above example is a box plot. To get a bar sparkline change type: 'box' to type: 'bar' and refresh the page;

Type can be one of 'line', 'bar', 'tristate', 'discrete', 'bullet', 'pie' or 'box'. Try them all out!
Thanks for sharing this. It seems to work just fine, within its limitations. I just wish there were a better way to add this column, *especially* so it didn't have to be the last column on the IR. Maybe if you could define a target/fixed column ID on which you could append to sparkline?
ReplyDeleteCan I assume no one helped you convert this into an Apex plug-in? I've used Apex a long time, but never tried my hand at creating a plug-in because I'm too much a JS lightweight.
If I'd had to guess, it'd be that you can't add a plug-in directly onto an Interactive Report? But maybe you could make it a page plug-in???
Thanks for comments Stew. I tried to create this as a plugin but its just too difficult. I love APEX but the plugin development is just too complicated at the moment. Hopefully they can simplify it like they have with everything else and I will give it a go.
Delete