1. Create a simple xaction with parameter DN.
2. Query:
select deptno,sum(sal) totsal
from emp where deptno={DN}
group by deptno;
Output for xaction
3. Now create a widgetsample.widget.xml file with the following code:
<chart>
<!-- Created August 6, 2008
@author Yoganand-->
<!-- This file defines the bar chart that shows the actual values for each delivery SL -->
<chart-type>BarChart</chart-type>
<!-- Specify the title of the chart -->
<title>EmployeeID v/s Salary Chart</title>
<!-- Specify the location of the title -->
<title-position>top</title-position>
<!-- Specify the font of the title -->
<title-font>
<font-family>Verdana</font-family>
<size>13</size>
<is-bold>false</is-bold>
<is-italic>false</is-italic>
</title-font>
<width>450</width>
<height>500</height>
<!-- to set background for chart -->
<chart-background type="color">#FFFFFF</chart-background>
<plot-background type="color">#FFFFFF</plot-background>
<!-- sets the color of the pie's-->
<color-palette>
<color>#FF9900</color>
<color>#339900</color>
<color>#0099FF</color>
<color>#CCCCCC</color>
<color>#996633</color>
<color>#DDCC88</color>
<color>#123D82</color>
<color>#4A0866</color>
<color>#445500</color>
<color>#FFAA00</color>
<color>#1E8AD3</color>
<color>#AA6611</color>
<color>#772200</color>
</color-palette>
<!-- Specify the 3D-ness of the bars -->
<is-3D>true</is-3D>
<!-- Specify the stacked property -->
<is-stacked>true</is-stacked>
<!-- Defines the angle (in degrees) at which the first pie section starts Default 90-->
<start-angle>150</start-angle>
<!-- Specify if the chart has a border and the border color -->
<border-visible>true</border-visible>
<max-bar-width>0.08</max-bar-width>
<min-bar-width>0.06</min-bar-width>
<!-- Specify is the chart legend should be shown -->
<include-legend>true</include-legend>
<!-- Specify the legend font -->
<legend-font>
<font-family>Verdana</font-family>
<size>10</size>
<is-bold>false</is-bold>
<is-italic>false</is-italic>
</legend-font>
<!-- Specify the label font-->
<label-font>
<font-family>Verdana</font-family>
<size>10</size>
<is-bold>false</is-bold>
<is-italic>false</is-italic>
</label-font>
<label-background-paint>#FFFFFF</label-background-paint>
<label-gap>0.01</label-gap>
<!-- Specify where the data for the chart comes from -->
<data>
<!-- Specify the path to the action sequence that provides the data -->
<data-solution>sample</data-solution>
<data-path>samplesofwidget</data-path>
<data-action>widgetsample.xaction</data-action>
<!-- Specify the output of the action sequence that contains the data -->
<data-output>query_result</data-output>
<!-- Specify whether to get the pie series from the rows or columns -->
<data-orientation>columns</data-orientation>
</data>
</chart>
4. Save xaction and widgetsample.widget.xml file at following location
C:\Program Files\pentaho\server\biserver-ee\pentaho-solutions\sample\samplesofwidget
5. Create a JSP file with following code:
<%@ page language="java"
import="java.util.ArrayList,
java.util.Date,
java.io.ByteArrayOutputStream,
org.pentaho.platform.util.web.SimpleUrlFactory,
org.pentaho.platform.web.jsp.messages.Messages,
org.pentaho.platform.engine.core.system.PentahoSystem,
org.pentaho.platform.uifoundation.chart.DashboardWidgetComponent,
org.pentaho.platform.web.http.request.HttpRequestParameterProvider,
org.pentaho.platform.web.http.session.HttpSessionParameterProvider,
org.pentaho.platform.api.engine.IPentahoSession,
org.pentaho.platform.web.http.WebTemplateHelper,
org.pentaho.platform.util.VersionHelper,
org.pentaho.platform.util.messages.LocaleHelper,
org.pentaho.platform.engine.core.solution.SimpleParameterProvider,
org.pentaho.platform.uifoundation.chart.ChartHelper,
org.pentaho.platform.web.http.PentahoHttpSessionHelper"%>
<%
// set the character encoding e.g. UFT-8
response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
// get the current Pentaho session or create a new one if needed
IPentahoSession userSession = PentahoHttpSessionHelper.getPentahoSession( request );
%>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/pentaho-style/active/default.css"></link>
<title>Chart By sumeet</title>
</head>
<body>
<div style="margin:10px;border:0px none #808080;padding:5px;">
<table class="parameter_table" width="90%" border="2" cellspacing="5" cellpadding="5">
<tr>
<td> <!-- -------------------------- BAR CHART ------------------------- -->
<%
SimpleParameterProvider parameters = new SimpleParameterProvider();
parameters.setParameter( "image-width", "400"); //$NON-NLS-1$ //$NON-NLS-2$
parameters.setParameter( "image-height", "400"); //$NON-NLS-1$ //$NON-NLS-2$
parameters.setParameter("DN","20");
StringBuffer content = new StringBuffer();
ArrayList messages = new ArrayList();
ChartHelper.doChart( "sample", "samplesofwidget", "widgetsample.widget.xml", parameters, content, userSession, messages, null ); //$NON-NLS-1$ //$NON-NLS-2$
%>
<br/>
<%= content.toString() %>
</td>
</tr>
</table>
</div>
</body>
</html>
6. Run the jsp page
7. END
No comments:
Post a Comment