Visual Mining contact us | site map | search

Products Solutions Resource Library Services Customers Partners Developers Company
Developers

NetCharts® Server JSP Code Examples

Getting a Simple Chart

<%@ taglib uri="http://www.visualmining.com/taglibs/ncstaglib-1.0" prefix="ncs" %>
<!---
SimpleChart.jsp
Visual Mining, Inc.
This example inserts an SWF (Macromedia Flash) image of a chart into the page. The chart comes from a chart template named simpleline.cdx, which is located in a project called "ToolkitExamples" residing on a NetCharts Server running on localhost, port 8001.

The simpleline.cdx chart template containa a variable called THETITLE and LINESETDATA used to represent the title of the chart.

The HTML code resulting from exectuing this tag will contain a IMG tag for the chart image.
--->

<html>
<body>
<ncs:chart project="Examples/ToolkitExamples" chart="simpleline.cdx" type="SWF" drilldown="false">
<ncs:variable name="THETITLE" value="Ticket Sales"/>
<ncs:variable name="LINESETDATA" value="100,200,450,150"/>
</ncs:chart>
</body>
</html>

Getting a Dynamic Chart

<%@ taglib uri="http://www.visualmining.com/taglibs/ncstaglib-1.0" prefix="ncs" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<!---
InteractiveChart.jsp
Visual Mining, Inc.

This example inserts a drillable PNG image of a piechart into the page. The chart comes from a chart template named bannerads.cdx, which is located in a project called "ToolkitExamples" residing on a NetCharts Server running on localhost, port 8001.

The bannerads.cdx chart template contains two variables, THETITLE and CLICKDATA used to represent dynamic data in the chart. The chart displays pop-up labels over the pie slices. Each slice is also a drill target.

The HTML code resulting from exectuing this tag will contain a IMG tag for the chart image, a MAP tag for the image map, and some javascript to implement the mouse roll-over labels.
--->

<html>
<body>
<!---
Simulate getting real dynamic data for the chart. Each reload of the page will present different data.
--->
<%
int click1 = new Double(Math.random()* 100.0).intValue();
int click2 = new Double(Math.random()* 100.0).intValue();
int click3 = new Double(Math.random()* 100.0).intValue();
String clicks = click1 + "," + click2 + "," + click3;
String title = "Banner Ad Click-Throughs\n" +
DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date());
%>

<ncs:chart project="Examples/ToolkitExamples" chart="bannerads.cdx">
<ncs:variable name="THETITLE" value="<%=title%>"/>
<ncs:variable name="CLICKDATA" value="<%=clicks%>"/>
</ncs:chart>
</body>
</html>

Getting a Report

<%@page language="java" import="java.sql.*,java.util.*"%>
<%@ taglib uri="http://www.visualmining.com/taglibs/ncstaglib-1.0" prefix="ncs" %>
<!---
ReportWithJSPTag.jsp
Visual Mining, Inc.

This example uses the JSP Tag library to create a HTML report containing an interactive PNG chart image and an HTML table.

The data for the chart and table comes from a sample data base included with NetCharts Server. This JSP page uses JDBC to query the database, and then passes the ResultSet object to the server to be used for populating the chart and the table. This example plots corporate meal expenses by quarter for a year.

The chart comes from a chart template named expensechart.cdx, which is located in a project called "ToolkitExamples" residing on a NetCharts Server running on localhost, port 8001.

The chart template contains a variable THETITLE, used to populate the chart title.

The HTML code resulting from exectuing this tag will contain a IMG tag for the chart image, a MAP tag for the image map, and some javascript to implement the mouse roll-over labels as well an an HTML table representation of the result set data.
--->

<%
Driver driver = null;
String dbURL = null;
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
String[] columnNames = null;
try {
driver = (Driver) Class.forName("org.hsqldb.jdbcDriver").newInstance();
dbURL = "jdbc:hsqldb:root/sampledata/Examples";
connection = DriverManager.getConnection(dbURL,"SA","");
statement = connection.createStatement();
resultSet = statement.executeQuery("SELECT * FROM expensetable");
} catch (Exception e) {
out.print("Unable do make connection to examples database");
out.print(e);
}
%>

<html>
<body>
<p>
<table border="0" align="center">
<tr>
<td>
<ncs:session project="Examples/ToolkitExamples" query="<%=resultSet%>">
<ncs:chart chart="expensechart.cdx" drilldown="true">
<ncs:chartdata type="Bars" rows="7-9" columns="2-5"/>
<ncs:chartdata type="Bar Labels" rows="7-9" columns="0"/>
<ncs:chartdata type="Legend" rows="COLUMNNAMES" columns="2-5" rowMajor="true"/>
<ncs:variable name="THETITLE" value="Meal Expenses"/>
</ncs:chart>
</td>
</tr>
<tr>
<td>
<ncs:table table="expensetable.tbl">
<ncs:tabledata rows="7-9" columns="0,2-5"/>
<ncs:variable name="tableStyleSheet" value="http://localhost:8001/styles/defaultTableStyleRight.css"/>
<ncs:variable name="tableCaption" value=""/>
<ncs:variable name="column2FormatType" value="CURRENCY"/>
<ncs:variable name="column3FormatType" value="CURRENCY"/>
<ncs:variable name="column4FormatType" value="CURRENCY"/>
<ncs:variable name="column5FormatType" value="CURRENCY"/>
</ncs:table>
</ncs:session>
</td>
</tr>
</table>
</body>
</html>

<%
resultSet.close();
statement.close();
connection.close();
%>



© 2008 Visual Mining, Inc. All rights reserved.
1-800-308-0731 | info@visualmining.com | privacy statement | legal
15825 Shady Grove Rd., Suite 20, Rockville, MD 20850 USA

Quote: Ford