PDA

View Full Version : Drill down for ChartComponent in xaction



raj2569
06-29-2007, 04:29 AM
Hi,

How can I enable drill down for pie charts generated from ChartComponent in xaction.

For example in the PCI google maps example, when I click on the map points I get a pie chart on the left, I want to click on that pie chart and create a next level chart. I am able to do this via

parameters.setParameter( "drill-url", "SampleDashboard?region={REGION}" );

in a jsp file.

I have seen tags like <url-template/> and outputs like HTML_IMG_TAG in http://wiki.pentaho.org/display/PentahoDoc/Chart+Component but there are no example of them being used from ChartComponent in xaction.

Any help here is much appreciated.

raj

raj2569
06-29-2007, 05:29 AM
After some digging through the source code, I found some answers.

(using pentaho-solutions/samples/google/chart.xaction)



--- chart.xaction.orig 2007-06-29 14:55:21.000000000 +0530
+++ chart.xaction 2007-06-29 14:40:00.000000000 +0530
@@ -69,9 +69,11 @@
</action-inputs>
<action-outputs>
<chart-filename type="string"/>
+ <chart-mapping type="string"/>
<base-url type="string"/>
</action-outputs>
<component-definition>
+ <url-template><![CDATA[/pentaho/Pivot?solution=samples&path=analysis&action=query1.xaction&department=.[{output-type}]]]></url-template>
<by-row>false</by-row>
<height>250</height>
<width>300</width>
@@ -125,7 +127,8 @@
<component-name>JavascriptRule</component-name>
<action-type>Get The Chart URL</action-type>
<action-inputs>
- <CHARTOUTPUT type="string" mapping="chart-filename"/>
+ <CHARTOUTPUT type="string" mapping="chart-mapping"/>
+ <!-- <CHARTOUTPUT type="string" mapping="chart-filename"/> -->
<BASEURL type="string" mapping="base-url"/>
</action-inputs>
<action-outputs>
@@ -134,7 +137,7 @@
<component-definition>
<script> <![CDATA[
function getImageURL( fileName ) {
- return '<img src="' + BASEURL + "getImage?image=" + fileName + '" />';
+ return '<div>' + BASEURL + "getContent?id=" + fileName + '</div>';
}
getImageURL( CHARTOUTPUT );
]]> </script>
As you can see I defined an output chart-mapping inside <action-outputs>

<chart-mapping type="string"/>

<url-template> inside <component-definition>

<url-template><![CDATA[/pentaho/Pivot?solution=samples&path=analysis&action=query1.xaction&department=.[{output-type}]]]></url-template>

in the action-inputs of JavascriptRule i defined <CHARTOUTPUT type="string" mapping="chart-mapping"/> and commented out the existing CHARTOUTPUT.

Now I can see a map file in pentaho-solutions/system/tmp/.


<map id="tmp_chart_20094" name="tmp_chart_20094">
<area shape="poly" coords="126,63,137,59,150,58,150,112,150,112" title="Vintage Cars = 8,801.08" alt=""
href="http://swathi:8080/pentaho//pentaho/Pivot?solution=samples&path=analysis&action=query1.xaction&department=.[{output-type}]"
target="pentaho-popup"/>
<area shape="poly" coords="98,128,96,119,96,109,97,100,100,91,104,82,110,75,117,68,126,63,150,112,150,112" title="Trucks and Buses = 27,800.52"
alt=""
href="http://swathi:8080/pentaho//pentaho/Pivot?solution=samples&path=analysis&action=query1.xaction&department=.[{output-type}]"
target="pentaho-popup"/>
<area shape="poly" coords="105,142,98,128,150,112,150,112" title="Trains = 5,351.61" alt=""
href="http://swathi:8080/pentaho//pentaho/Pivot?solution=samples&path=analysis&action=query1.xaction&department=.[{output-type}]"
target="pentaho-popup"/>
<area shape="poly" coords="126,160,114,152,105,142,150,112,150,112" title="Planes = 10,235.43" alt=""
href="http://swathi:8080/pentaho//pentaho/Pivot?solution=samples&path=analysis&action=query1.xaction&department=.[{output-type}]"
target="pentaho-popup"/>
<area shape="poly" coords="201,127,197,138,190,147,181,155,171,161,160,165,148,166,137,164,126,160,150,112,150,112" title="Motorcycles = 33,805.3"
alt=""
href="http://swathi:8080/pentaho//pentaho/Pivot?solution=samples&path=analysis&action=query1.xaction&department=.[{output-type}]"
target="pentaho-popup"/>
<area shape="poly" coords="150,58,162,59,174,63,184,70,193,79,199,90,203,102,203,115,201,127,150,112,150,112" title="Classic Cars = 36,144.2" alt=""
href="http://swathi:8080/pentaho//pentaho/Pivot?solution=samples&path=analysis&action=query1.xaction&department=.[{output-type}]"
target="pentaho-popup"/>
Now the question reduces to, how can I get this map file from server using http and create an html fragment out of it along with the image?

raj

raj2569
06-29-2007, 10:58 AM
I was using 1.2.1.625-GA previously, now I am using 1.5.4.716-0. That made a big difference. I am attaching a diff of the chart.xaction file with drill down enabled for pie chart.



--- chart.xaction.orig 2007-06-29 20:26:30.000000000 +0530
+++ chart.xaction 2007-06-29 20:26:24.000000000 +0530
@@ -69,9 +69,12 @@
</action-inputs>
<action-outputs>
<chart-filename type="string"/>
+ <chart-map-html type="string"/>
<base-url type="string"/>
</action-outputs>
<component-definition>
+ <paramName>customer</paramName>
+ <url-template><![CDATA[javascript: alert('{customer}');]]></url-template>
<by-row>false</by-row>
<height>250</height>
<width>300</width>
@@ -126,6 +129,7 @@
<action-type>Get The Chart URL</action-type>
<action-inputs>
<CHARTOUTPUT type="string" mapping="chart-filename"/>
+ <MAP_TAG type="string" mapping="chart-map-html"/>
<BASEURL type="string" mapping="base-url"/>
</action-inputs>
<action-outputs>
@@ -133,10 +137,11 @@
</action-outputs>
<component-definition>
<script> <![CDATA[
- function getImageURL( fileName ) {
- return '<img src="' + BASEURL + "getImage?image=" + fileName + '" />';
+ function getImageURL( fileName, mapTag ) {
+ name = fileName.split(".")[0]
+ return '<img src="' + BASEURL + "getImage?image=" + fileName + '" usemap="#' + name +'" />' + mapTag;
}
- getImageURL( CHARTOUTPUT );
+ getImageURL( CHARTOUTPUT, MAP_TAG );
]]> </script>
</component-definition>
</action-definition>

raj2569
06-29-2007, 11:10 AM
When I was trying various combinations to get the image-map id, I hit up this but, can any one confirm this?



--- chart.xaction.orig 2007-06-29 20:26:30.000000000 +0530
+++ chart.xaction 2007-06-29 20:36:34.000000000 +0530
@@ -68,7 +68,9 @@
<chart-data type="result-set" mapping="chartData"/>
</action-inputs>
<action-outputs>
+ <chart-map-html type="string"/>
<chart-filename type="string"/>
+ <image-tag type="string"/>
<base-url type="string"/>
</action-outputs>
<component-definition>
I get java.lang.ArrayIndexOutOfBoundsException, to me it seems a bug, can some one confirm?



Error: Base.ERROR_0002 - Component execution failed - java.lang.ArrayIndexOutOfBoundsException: 1 (org.pentaho.plugin.jfreechart.ChartComponent)Debug: Starting execute of samples/google/chart.xaction (org.pentaho.core.solution.SolutionEngine)
Debug: Getting runtime context and data (org.pentaho.core.solution.SolutionEngine)
Debug: Loading action sequence definition file (org.pentaho.core.solution.SolutionEngine)
Debug: SolutionRepository.DEBUG_FILE_PATH - getFile path=/opt/pentaho-demo/pentaho-solutions/samples/google/chart.xaction (org.pentaho.repository.filebased.solution.SolutionRepository)
Debug: Adding variable source request to parameter chart-type (org.pentaho.repository.filebased.solution.SolutionRepository)
Debug: Adding default value of ".png" to parameter chart-type (org.pentaho.repository.filebased.solution.SolutionRepository)
Debug: Adding variable source request to parameter customer (org.pentaho.repository.filebased.solution.SolutionRepository)
Debug: audit: instanceId=5fc4a9ae-2652-11dc-9389-31fee00c5ba8, objectId=org.pentaho.core.runtime.RuntimeContext, messageType=action_sequence_start (org.pentaho.core.runtime.RuntimeContext)
Debug: validateComponent validating component SQLLookupRule (org.pentaho.core.runtime.RuntimeContext)
Debug: Validating component for action chart.xaction (org.pentaho.plugin.sql.SQLLookupRule)
Debug: validateComponent validating component ChartComponent (org.pentaho.core.runtime.RuntimeContext)
Debug: Validating component for action chart.xaction (org.pentaho.plugin.jfreechart.ChartComponent)
Debug: validateComponent validating component JavascriptRule (org.pentaho.core.runtime.RuntimeContext)
Debug: Validating component for action chart.xaction (org.pentaho.plugin.javascript.JavascriptRule)
Debug: Executing action sequence (org.pentaho.core.runtime.RuntimeContext)
Debug: Executing action definition: Iteration 0 (org.pentaho.core.runtime.RuntimeContext)
Debug: audit: instanceId=5fc4a9ae-2652-11dc-9389-31fee00c5ba8, objectId=SQLLookupRule, messageType=component_execution_started (org.pentaho.core.runtime.RuntimeContext)
Debug: execute pre-audit (org.pentaho.core.runtime.RuntimeContext)
Debug: Setting component log level to DEBUG (org.pentaho.core.runtime.RuntimeContext)
Debug: Initializing component (org.pentaho.core.runtime.RuntimeContext)
Debug: executeComponent starting audited execute (org.pentaho.core.runtime.RuntimeContext)
Debug: execute validation=true (org.pentaho.plugin.sql.SQLLookupRule)
Debug: Running query - select DISTINCT PRODUCTLINE, SUM(QUANTITYORDERED * PRICEEACH) as "TOTAL SALES" from PRODUCTS, ORDERDETAILS, CUSTOMERS, ORDERS where CUSTOMERS.CUSTOMERNUMBER = ? and CUSTOMERS.CUSTOMERNUMBER = ORDERS.CUSTOMERNUMBER and ORDERS.ORDERNUMBER = ORDERDETAILS.ORDERNUMBER and PRODUCTS.PRODUCTCODE = ORDERDETAILS.PRODUCTCODE GROUP BY PRODUCTLINE (org.pentaho.plugin.sql.SQLLookupRule)
Debug: executeComponent finished audited execute (org.pentaho.core.runtime.RuntimeContext)
Debug: execute post-audit (org.pentaho.core.runtime.RuntimeContext)
Debug: audit: instanceId=5fc4a9ae-2652-11dc-9389-31fee00c5ba8, objectId=SQLLookupRule, messageType=component_execution_ended (org.pentaho.core.runtime.RuntimeContext)
Debug: audit: instanceId=5fc4a9ae-2652-11dc-9389-31fee00c5ba8, objectId=ChartComponent, messageType=component_execution_started (org.pentaho.core.runtime.RuntimeContext)
Debug: execute pre-audit (org.pentaho.core.runtime.RuntimeContext)
Debug: Setting component log level to DEBUG (org.pentaho.core.runtime.RuntimeContext)
Debug: Initializing component (org.pentaho.core.runtime.RuntimeContext)
Debug: executeComponent starting audited execute (org.pentaho.core.runtime.RuntimeContext)
Debug: execute validation=true (org.pentaho.plugin.jfreechart.ChartComponent)
Error: Base.ERROR_0002 - Component execution failed - java.lang.ArrayIndexOutOfBoundsException: 1 (org.pentaho.plugin.jfreechart.ChartComponent)
Debug: executeComponent finished audited execute (org.pentaho.core.runtime.RuntimeContext)
Error: RuntimeContext.ERROR_0012 - ActionDefinition for ChartComponent did not execute successfully (org.pentaho.core.runtime.RuntimeContext)
Debug: audit: instanceId=5fc4a9ae-2652-11dc-9389-31fee00c5ba8, objectId=org.pentaho.core.runtime.RuntimeContext, messageType=action_sequence_failed (org.pentaho.core.runtime.RuntimeContext)
Error: SolutionEngine.ERROR_0007 - Action sequence execution failed (org.pentaho.core.solution.SolutionEngine)

Server Version 1.5.4 build 716 0

ingo.klose
07-07-2007, 03:22 AM
Hi,

here is an example of a action that produces a pie chart with a drill:



<action-definition>
<component-name>ChartComponent</component-name>
<action-type>Regions 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>
<border-visible>false</border-visible>
<include-legend>false</include-legend>
<is-3D>false</is-3D>
<url-template><![CDATA[javascript:loadRegionVariance('{region}')]]></url-template>
<paramName>region</paramName>
<title-font>
<font-family>Arial</font-family>
<size>12</size>
<is-bold>false</is-bold>
<is-italic>false</is-italic>
</title-font>
</chart-attributes>
<width><![CDATA[450]]></width>
<height><![CDATA[300]]></height>
<title><![CDATA[Headcount Spending by Region]]></title>
</component-definition>
</action-definition>


This is all you need to create a clickable pie chart.

All the best,
Ingo

Rice
07-19-2007, 09:55 AM
Raj, I get the same out of bounds error. I too am trying to figure out how to make drill down charts, so please let me know if you figured this one out. I'll also be taking a closer look at it after I finish writing this post.

Ingo, I copied that into an .xaction file and tried to access it, and I get a Null Pointer Exception on line 63 of Chart.jsp:
63: content = barChart.getContent( "text/html" ); //$NON-NLS-1$
Was there something else that I needed to change? Please let me know if you have any idea, thanks.

Chris