I recently received an interesting problem. A multi bar graph needed to have drillthroughs pointing to separate reports. The requirement is to have it seamless for the end-user, no transitional screens. If the user clicks on the revenue bar, it needs to go to the revenue report. If they click on the planned revenue bar, it goes to the planned revenue report.
As the product is currently built, drillthroughs are defined on the graph level, not a measure level. Let’s take a look at the actual HTML being generated:
<area dttargets="<drillTarget drillIdx=\"2\" label=\"Planned revenue\"/><drillTarget drillIdx=\"3\" label=\"Revenue\"/>" display="914,352,803.72" tabindex="-1" ctx="27::22::18" title="Year = 2010 Revenue = 914,352,803.72" coords="157, 309, 157, 174, 118, 174, 118, 310, 157, 310" shape="POLY" type="chartElement" class="dl chart_area" ddc="1" href="#" >
In this example, I have a chart with two bars. In the area of each bar, the dttargets is defined with both drills. The drills themselves I’ve named the same as the data item of the measure. We can then use JavaScript to extract the dttargets string, match the label of the drill to the data item name, and place the correct one in there.
/* * This will loop through every chart and replace multiple drill definitions with one. */ paulScripts.fixChartDrills = function(chartName){ var oCV = window['oCV'+'_THIS_'] , areas = paulScripts.getElement(chartName).parentNode.previousSibling.getElementsByClassName('chart_area') , areasLen = areas.length , areaDataItemName , drills=[] , dtargets=[] ; for (var i=0;i<areasLen;++i){ if(!areas[i].getAttribute('dttargets')) continue; areaDataItemName=oCV.getDataItemName(areas[i].getAttribute('ctx')); drills = areas[i].getAttribute('dttargets'); dtargets =drills.split('>'); for (var j=0;j<dtargets.length;++j){ var regexp = /label...(.+?)."/g; var match = regexp.exec(dtargets[j]); if(match&&match[1] == areaDataItemName) areas[i].setAttribute('dttargets',dtargets[j]+'>'); }
First we’re finding the chart that we want to do this on, and finding the area map. We loop through the areas, skipping the ones that don’t have any dttargets (like the legend or labels).
For each area with a dttarget, we get the source data item name. Fortunately for us, there’s a useful Cognos JavaScript function to do it! Then a little hackey JS magic to get the label for each individual dttarget we can finally match and replace the dttargets attribute.
Let’s see it in action!
Now it’s very important that the drillthroughs have exactly the same names as the data items. If they don’t do that, this script won’t work – but of course that wouldn’t stop you from using different logic. I built this in Cognos 10.2.2, but I have no reason to think it’s not backwards compatible. The full JavaScript, including the paulScripts.getElement can be found in the report XML below.
separateDrills.txt (1046 downloads)
Hi paul
is there any way to increase the bar width of the column chart in cognos 10.2.1 using javascript?
Unfortunately no, the graphs themselves are actually static images. If you’re using the non-legacy column graphs, you should be able to specify the column widths as a percentage though.
Can this code be used in Cognos 11? Also , can we use this with a stacked bar chart?
It can be used in C11 in non-interactive mode. It should work fine with a stacked bar chart.
I’ve installed C11 on my laptop, so I can start experimenting with the JS in interactive mode. If I recall, the interactive mode doesn’t work with drills, but once it does I’ll look into adapting this.
Great… we are running without Interactive mode for our other dashboards. So that shouldn’t be an issue for us. l
This is cool, and very close to what I want! But I’m having trouble on getting a variation of this working.
(Sorry for the long comment)
In my case I have a stacked bar. The columns(stacks) are the last 12 months and a final column for the average, defined as
union(lastPeriods(12,[p_Date]),[12MthAvg]).
The [12MthAvg] is defined as
member(average(currentMeasure within set lastPeriods(12,[p_Date])),’12M AVG’)
I want to activate one drill-through if one of the months is clicked, and another when the 12 month average is clicked.
Your JS finds the area using getAttribute(‘ctx’) – when I display that with a console.log I get the same name for all columns, yet inspecting the HTML shows the ctx attribute having different numbers, ie one area has ctx=”1″, then next has ctx=”2″ etc. I also tried getting the title attribute, but these also all have the same value when displayed in the console.log, while having different values in the HTML inspection.
Here’s the HTML for one of the months:
<area class="chart_area" type="ordinalAxisLabel" shape="POLY" coords="101, 477, 119, 446, 109, 438, 89, 472, 101, 478" title="Month = 07/31/16" ctx="3" tabindex="-1" dttargets="”>
This is the HTML for the 12 month average:
<area class="chart_area" type="ordinalAxisLabel" shape="POLY" coords="327, 483, 349, 446, 339, 438, 315, 478, 327, 484" title="Month = 12M AVG" ctx="19" tabindex="-1" dttargets="”>
Do you have any suggestion on identifying the 12 month average, or even have an idea on why the console.log(‘ctx = ‘ + oCV.getDataItemName(areas[i].getAttribute(‘ctx’))) statement reports “ctx = Month” vs the number shown in the HTML and how they correlate?