Hey everybody!
This blog assumes you have some experience creating applications with SAP BusinessObjects Design Studio with CSS and scripting.
Last time out in Extending Design Studio with an HTML extension and HTML bars I showed you how to use HTML (and avoid script injection) to create a comparison bar for SAP BusinessObjects Design Studio, so you could make something that looks a bit like this:
Now, I will show you how to use that HTML within Design Studio including how to update it at runtime with real data.
You can find links to these in the resources section below...
For this you will either need an understanding of HTML and scripting in Design Studio as well as:
The choice is yours... Although I'd recommend option 1 for following along with this blog :wink:
These steps are for SAP BusinessObjects Design Studio 1.6 to create a fiori-like Headcount tile:
The tile should look something like this:
Here is the HTML for the hard coded bars from the last blog:
<table width="100%" style="bottom: 14px; border-collapse: collapse; position: absolute; line-height: normal; font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: normal;" border="0">
<tbody>
<tr style="border-top-color: transparent; border-top-style: solid;">
<td style="color: rgb(51, 51, 51);">Male</td>
<td align="right" style="color: rgb(51, 51, 51);">5,845</td>
</tr>
<tr>
<td height="12" style="background: linear-gradient(to right, rgb(88, 181, 230) 0%, rgb(88, 181, 230) 100%, rgb(211, 217, 221) 100%, rgb(211, 217, 221) 100%, rgb(211, 217, 221) 100%);" colspan="2" /> </tr>
<tr style="border-top-color: transparent; border-top-style: solid;">
<td style="color: rgb(51, 51, 51);">Female</td>
<td align="right" style="color: rgb(51, 51, 51);">4,957</td>
</tr>
<tr>
<td height="12" style="background: linear-gradient(to right, rgb(88, 181, 230) 0%, rgb(88, 181, 230) 84.81%, rgb(211, 217, 221) 84.81%, rgb(211, 217, 221) 84.81%, rgb(211, 217, 221) 100%);" colspan="2" /> </tr>
</tbody>
</table>
We are now going to turn that script into global scripts within Design Studio:
return "<table width='100%' style='bottom: 14px; " +
"border-collapse: collapse; " +
"position: absolute; line-height: normal; " +
"font-family: Arial, Helvetica, sans-serif; " +
"font-size: 14px; font-weight: normal;' border='0'>" +
"<tbody>";
// Max bar is 100%.
valuePercent = Math.min(100.0, valuePercent);
// Return the title, value and linear gradient bar html for the value percentage.
return "</tbody></table>";
Title | Value |
---|---|
Male | 5845 |
Female | 4957 |
// Calculate max value.
var title = "";
var value = 0.0;
var maxValue = 0.0;
var totalValue = 0.0;
var memberValues = DS_1.getMembers("Title", 2);
memberValues.forEach(function(element, index) {
// Get the value title and value.
title = element.internalKey;
value = DS_1.getData("Value", {
"Title": title
}).value;
// Keep track of the total and maximum value.
totalValue = totalValue + value;
maxValue = Math.max(value, maxValue);
});
// Create the mini chart HTML header.
var miniChart = GLOBAL_SCRIPTS_1.createMiniChartHeader();
// Create the mini chart HTML bars.
var valuePercent = 0.0;
var valueText = "";
var numFormat = "#,##0";
var color = "rgb(88, 181, 230)"; // Blue.
var noFillColor = " rgb(211, 217, 221)"; // Light gray.
memberValues.forEach(function(element, index) {
// Get the value title and value.
title = element.internalKey;
value = DS_1.getData("Value", {
"Title": title
}).value;
// Convert the value into a formatted string.
valueText = Convert.floatToString(value, numFormat);
// Calculate the value percentage.
valuePercent = 0;
if (maxValue > 0) {
valuePercent = value / maxValue * 100.0;
}
// Add the bar HTML.
miniChart = miniChart +
GLOBAL_SCRIPTS_1.createMiniChartBar(title,
valueText, valuePercent, color, noFillColor);
});
// Create the mini chart HTML footer.
miniChart = miniChart + GLOBAL_SCRIPTS_1.createMiniChartFooter();
// Set the HTML bar.
HTML_1.setHtml(miniChart);
// Set the KPI Tile footer - the total value.
KPITILE_1.setFooterText("Total: " +
Convert.floatToString(totalValue, numFormat));
Thats getting very close, finally we can add some CSS to the tile title and total.
.borderBox {
box-sizing: border-box !important; /* do not include the margins in the overall size, so we match the width and height set in Design Studio */
}
.kpiTile {
background-color: #FFFFFF;
border: 1px solid #797979;
border-radius: 4px;
box-sizing: border-box !important; /* do not include the margins in the overall size, so we match the width and height set in Design Studio */
}
.kpiTileHeader {
font-family: arial,sans-serif;
font-size: 16px;
font-weight: normal;
color: #333333 !important;
box-sizing: border-box !important; /* do not include the margins in the overall size, so we match the width and height set in Design Studio */
}
.kpiTileFooter {
font-family: arial,sans-serif;
font-size: 14px;
font-weight: normal;
color: #666666;
box-sizing: border-box !important; /* do not include the margins in the overall size, so we match the width and height set in Design Studio */
}
And as a bonus exercise you can tidy up the Design Studio script by moving the header and bar styles into your CSS file.
Thanks for tuning in, Happy Holidays, see you again in 2016!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Subject | Kudos |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
User | Count |
---|---|
13 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |