Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
CrossTab cell formatting?
hevi
Hi,<br />
<br />
I have report with several graphs and one crosstab. The layout of the crosstab is as follows<br />
<br />
<p class='bbc_indent' style='margin-left: 40px;'><p class='bbc_indent' style='margin-left: 40px;'>ColumnName[colIndex]</p></p>
DataFrom | DataType[rowIndex] || Data<br />
<br />
It should look something like<br />
<br />
<p class='bbc_indent' style='margin-left: 40px;'>Monday Tuesday ......</p>
Paris Furniture 1200 2000<br />
<p class='bbc_indent' style='margin-left: 40px;'>Candies 120 220</p>
<p class='bbc_indent' style='margin-left: 40px;'>ROI 5.5% 7.0%</p>
<br />
London Furniture 2200 2700<br />
<p class='bbc_indent' style='margin-left: 40px;'>Candies 220 320</p>
<p class='bbc_indent' style='margin-left: 40px;'>ROI 6.5% 8.0%</p> <br />
etc<br />
<br />
The data is produced by a database query and all computation is done (in Java) before pushing the data to the <br />
report.<br />
<br />
A line of data to the report looks like:<br />
<br />
{dataFrom:sales, dataType:candies, columnName:Monday, columnIndex:1, data:1200,.....}<br />
<br />
Everything works okay, for the exception of the rows (and a specific columns) containing percentages. All data, including percentage is pushed in the double datatype from Java, i.e. 0.055 for 5.5%. The report design data type is decimal.<br />
<br />
The requirement of the rows and columns containing percentages is that its shows the %-sign and if value is positive the color of the cell/number should be green, if negative then red.<br />
<br />
I have managed to get the colors on the correct row and column cells containing the percentages. However I am unable to get the % sign into those same cells.<br />
<br />
In the crosstab script I have <br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function onCreateCell( cellInst, reportContext )
{
if( cellInst.getDataValue("columnName")=="ComparedToPreviousMonth" ||
cellInst.getDataValue("dataType")=="ROI")
{
// cellInst.getStyle().setNumberFormat("##.##%");
if(cellInst.getDataValue("data_TypeGroup/dataType_columns/columnName") < 0)
cellInst.getStyle().setColor("RGB(253,120,120)");
if(cellInst.getDataValue("data_TypeGroup/dataType_columns/columnName") > 0)
cellInst.getStyle().setColor("RGB(0,139,8)");
}
}
</pre>
As I said the coloring works correctly for the given rows and columns. But if I remove the comment on the line with setNumberFormat, then every cell in the whole crosstab gets formatted with % and extra zeros. <br />
<br />
It appears that setNumberFormat somehow affects every cell while the coloring works as expected, for the specified row and column cells. <br />
<br />
How should I solve this problem?
Find more posts tagged with
Comments
kclark
It looks like you are wanting to add the number format to every third row, is the correct? You could try adding a counter in onCreateCell() and check to see <br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>if (counter == 3) {
// Add number formatting
counter = 1;
}else{
counter++;
}</pre>
hevi
Thanks for your reply, but I don't think that makes a difference.<br />
<br />
Let me try to clarify. This is how the rows for a DataFrom object with 5 dataTypes looks like without setNumberFormat in the if-block (here the percentage row is the first, and the percentage column is the last):<br />
<br />
messiii
This really answered my problem, thank you!
mutzbraten
<p>Hi,</p>
<p> </p>
<p>I know, it's an old post, but I run into the same problem. Depending on the group inside a crosstab I want to format the numbers.</p>
<p>If I format the background color it works fine but formatting the numbers just works once.</p>
<p> </p>
<p>And this is the script</p>
<p style="margin-left:40px;">var y = reportContext.evaluate("dimension");</p>
<p style="margin-left:40px;"> </p>
<p style="margin-left:40px;">// Cells of group 0Bestand should be formatted red with number format '#.###'</p>
<p style="margin-left:40px;">// This works fine<br>
if (y == '0Bestand') {<br>
this.getStyle().backgroundColor = "red";<br>
this.getStyle().setNumberFormat("#,###");<br>
}</p>
<p style="margin-left:40px;"> </p>
<p style="margin-left:40px;">// Cells of group 1Anteil should be formatted yellow with number format '#.###,00'</p>
<p style="margin-left:40px;">// Coloring the cell does work fine, but formatting the number doesnt<br>
if (y == '1Anteil') {<br>
this.getStyle().backgroundColor = "yellow";<br>
<span style="color:#ff0000;"> this.getStyle().setNumberFormat("#,###.00");</span><br>
}<br>
</p>
<p>The cells background is changed depending on the current crosstab group but the number format is'nt.</p>
<p> </p>
<p>Any ideas?</p>
<p> </p>
<p>Thanks in advance,</p>
<p>Dirk</p>