Showing posts with label Charts. Show all posts
Showing posts with label Charts. Show all posts

Sunday, 2 November 2014

Report Studio: 100% stacked Bar chart displaying percentages in bars using Java Script

We can't display percentages in middle of the bars in cognos 10.2, 100% stacked bar chart. But the same has been fixed in Cognos 10.2.1.

We can do the same thing using Java Script. just follow the below steps..

Suppose we have the following columns in List Report..

Region, Actual, 100% stacked bar chart with percentages, Budget as follows..
1) take the columns Region, Actual, and budget into List Report
2) goto Query Explorer
3) Open Query1
4) Add Data Item, enter the following expression to calculate Actual percentage over total of actual and budget
                [actual]/([actual]+[Budget])* 100
5) Name this data Item in properties as  "actp'
6) Add another Data Item to calculate Budget percentage and enter the below expression
                  [Budget]/([actual]+[Budget])* 100

7) Name this data Item in properties as  "budp'

8) Goto Page explorer and select Page1 to see the list report

9) Drag one HTML item and drop between the columns Actual and Budget as a column

10) Click LOCK icon in tool bar  to unlock

11) Add 4 more HTML items next to previously added HTML item, so you should have 5 HTML items

12) double click First HTML item and add the following script

     <script>
           var bar1Percent =
13) Click OK to close the HTML box

14) Just click to second HTML item to select (dont  Open)

15) Goto properties, got to the property "Source Type"

16) Change to "Data Item Value" 

17) For the Property Data Item Value, select the column  "actp"

18) Double click 3rd HTML item and enter the following expression      (dont forget semicolon as first line)
          
                 ;     
                 var bar2Percent = 
       
            
 19) Select 4th HTML item, goto properties and change the following propertiesr

                  Source Type: Data Item Value
                  Data Item Value: budp  (this is data item that we have created in 6 the step)

20) double click 5th HTML item and enter the following script as it is (dont forget about semicolon in first line)

;

var bar1=bar1Percent;
var bar2=bar2Percent;
var barL=bar1Percent+bar2Percent;
var width_driver = 200;
var barheight = ((width_driver) / 10);
            
           
var myTotalBar = '<div style="background-color:red;width:' + barL + ';height:' + barheight + '">';
            
var percent1 = '<div style="background-color:#F15A29; font-family:Source Sans Pro; font-size:9px; color:white; float:left; text-align:center; display:table-cell; vertical-align: middle;  width:' + bar1Percent + ';height:' + barheight + '"> <span style="display:table-cell; width:inherit;height:inherit; vertical-align: middle"> <strong>' + bar1.toFixed(1) + '%</strong></span></div>';
var percent11 = '<div style="background-color:#F15A29; font-family:Source Sans Pro; font-size:9px; color:white; float:left; text-align:center; display:table-cell; vertical-align: middle;  width:' + bar1Percent + ';height:' + barheight + '"> <span style="display:table-cell; width:inherit;height:inherit; vertical-align: middle"> </span></div>';
            
var percent2 = '<div style="background-color:#2B3990; font-family:Source Sans Pro; font-size:9px;color:white; float:right;text-align:center; width:' + bar2Percent + ';height:' + barheight + '"> <span style="display:table-cell; height:inherit; width:inherit; vertical-align: middle"> <strong>' + bar2.toFixed(1) + '%</strong></span></div>';
var percent22 = '<div style="background-color:#2B3990; font-family:Source Sans Pro; font-size:9px;color:white; float:right;text-align:center; width:' + bar2Percent + ';height:' + barheight + '"> <span style="display:table-cell; height:inherit; width:inherit; vertical-align: middle"> </span></div>';

if (bar1Percent<20)
{
percent1=percent11;
}

if (bar2Percent<20)
{
percent1=percent22;
}

myTotalBar = myTotalBar + percent1 + percent2 + '</div>';




document.write(myTotalBar);



</script>



You will get the output as below...



Note: This chart does not show percentage on bar if percentage < 20 as the width bar is very low so we can't show text on it.


Please note that, we can do the same thing using Micro Chart, but we will get extra space around the bar therefore, the lines appear with unnecessary space that we can't avoid

Charts :Defect - Advanced Drill Link with Higher level Default prompt selections?

We have report with a value prompt on the report page and its default value is controlled by a prompt macro. The report also has a Pie chart and a Crosstab both based on different queries whose data items are linked for drills.The report is based on a cube.

The observation is that when the default value for the prompt is set to a higher level of the dimension say the year level in a Time dimension and when a user selects any value from the drop down and does a drill on the pie chart categories member the drill links don't work in the Crosstab only the pie chart gets updated.

This happens only the first time a selection is made. Selecting any other value and executing a drill on the pie chart categories and then selecting the same value and then executing a similar drill does not re-produce the above error.

This also does not happen if you execute the drill without making any selections. Any selection later doesn't re-produce the error.

So basically it seems like this happens for the  first selection made and when you have a higher level member set as the default through a prompt macro. Once a drill is executed and then any number of drill executions later doesn't re-produce the error.

This has been observed in a Pie - Crosstab combination and not in a Stacked Chart - Crosstab combination.

Some screenshots against Go Sales Cube to demonstrate the observation against a simmplified requirement:

First run of the report:


On selection of January 2004 from the drop down and then executing a drill up on Pie chart for January 2004:


The drill does not get reflected in the crosstab.

On selection of Q1 2004 and then executing a drill up on the Pie chart:


The drill is reflected in the crosstab.

When January 2004 is set as the default, first run of the report:


On selection of February 2004 and then executing a drill up on the pie chart:

The drill is reflected in the crosstab.
  

Report Studio : Cognos 10 Chart Properties

While I was on the subjects of Cognos 10, thought I will write about some properties of the Charts that are positioned differently between the older versions of Cognos and the newer ones as I don't want people to get frustrated like I did trying to find some properties with the newer version.

The Line Style and Marker properties are now positioned on the Palette dialog box which according to me isn't meaningful.





I had spent considerable time trying to find these properties out that had almost given up with the newer charts and had planned on using the legacy charts and opening a ticket with IBM. Hope this helps others in some way.