Pentaho Dashboard – Show Message if No Data Available

I do not know how to achieve this in ‘jFreeChartComponent’ or in the CCC (community chart component). My solutions are built with action sequence and that’s where I needed to have this feature.

The concept is simple. After getting the result set from the database through ‘SQLLookupRule’ component, I am checking if the result set length is greater than zero or not. The ‘JavascriptRule’ component is used to determine the length of the result set. And then using the ‘if’ condition I am generating the chart or just a simple string saying ‘No Result Found’.

So my action sequence output will be

<outputs> 
	<image-tag type="string"/>  
	<output type="string"/>
</outputs>

The ‘JavascriptRule’ component to check the result set is simple

<action-definition>
	<component-name>JavascriptRule</component-name>
	<action-type>JavaScript</action-type>
	<action-inputs>
		<queryResult type="result-set" mapping="query_result"/> 
	</action-inputs>
	<action-outputs>
		<noData type="string"/>
	</action-outputs>
	<component-definition>
		<script><![CDATA[noData = "false";
		if(queryResult.getRowCount() == 0){
			noData = "true";
		}]]></script>
	</component-definition>
</action-definition>

So depending upon the result set name my output variable ‘noData’ will be “true” or “false”. And based on the ‘noData’ value I am generating respective output

<actions> 
	<condition><![CDATA[noData == "false"]]></condition>  
	<action-definition> 
		<component-name>ChartComponent</component-name>
		<action-type>Pie Chart</action-type>
		<action-inputs> 
			<chart-data type="result-set" mapping="query_result"/>  
		</action-inputs>
		<action-outputs> 
			<image-tag type="string"/> 
		</action-outputs>
		<component-definition> 
			<chart-attributes> 
			<chart-type>PieChart</chart-type>  
			<title>chartTitle</title>  
			<title-position>top</title-position>  
			<display-labels>false</display-labels>  
			<url-template>javascript:;</url-template>  
			<paramName>label</paramName>  
			<width>350</width>  
			<height>350</height> 
			</chart-attributes> 
		</component-definition> 
	</action-definition>
</actions>
  
<actions>
	<condition><![CDATA[noData == "true"]]></condition>
	<action-definition>
		<component-name>JavascriptRule</component-name>
		<action-type>JavaScript</action-type>
		<action-outputs>
			<output type="string"/>
		</action-outputs>
		<component-definition>
			<script><![CDATA[output = "No Result Found";]]></script>
		</component-definition>
	</action-definition>
</actions>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: