.
<%
/*
This is an example of a data-driven chart JSP, using a vertical
resultset.The period above has to be there to prevent the
javascript popup.style error; the character can't be a space.
*/
/*
Includes:
java.util has the Hashtable object and certain other methods
java.sql has the data access objects
netcharts.server has the chart building objects
*/
%>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="netcharts.server.api.*" %>
<%@ page import="netcharts.server.util.*" %>
<%
/*
Unlike IIS VBScript, this variable *must* be declared and initialized
before calling the Footer.inc include, even if it's supposed to be
empty.
*/
String strPageName = "";
String strQuery = "select left(item, 1) as FirstLetter, " +
"count(item) as thecount from " +
"C613.ASCOpenOrderDetail " +
"Where left(item, 1) in ('A', 'B', 'C', 'D') " +
"group by left(item, 1) " +
"order by thecount desc";
/*
GETTING THE DATA INTO THE NETCHARTS CHART OBJECT
================================================
The column names and data rows are first appended onto a string.
This string is then loaded into a hash table, where the key exactly
matches the key inside the CDX file. The resulting hash table can then
be passed to the NetCharts object. :)
*/
String strDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String strURL = "jdbc:microsoft:sqlserver://";
String strServer = "DCACNT53";
String strPort = "1433";
String strDB = "ERP_613";
String strUID = "userid";
String strPWD = "password";
String strCtype = "cursor";
String strSolution = "aaMMOChartsPre";
String strProject = "testbed";
String strCDX = "TEST_Chart_ByCode_DataMart.cdx";
String strConn = strURL + strServer + ":" + strPort + ";databaseName=" + strDB + ";selectMethod=" + strCtype + ";";
/*
Try to open a connection to the data source
*/
Connection objConn = null;
try
{
Class.forName(strDriver);
objConn = java.sql.DriverManager.getConnection(strConn,strUID,strPWD);
}
catch(Exception e)
{
e.printStackTrace();
out.println("Couldn't connect: " + e.getMessage() + "");
}
/*
If we have an open connection, we can try to get the data and build
the chart
*/
Statement objStmt = objConn.createStatement();
try
{
// get the data and metadata
ResultSet objRS = objStmt.executeQuery(strQuery);
// initialize the local strings
String strColumns = "BarLabels = ";
String strRows = "DataSet1 = ";
String strTheData = "";
/*
load the local strings with data. We have to do it like this
because the SQL Server driver we're using doesn't support cursor
movement methods. :(
*/
while(objRS.next())
{
strColumns = strColumns + "'" + objRS.getObject(1) + "',";
strRows = strRows + objRS.getObject(2) + ",";
}
strColumns = strColumns.substring(0, strColumns.length() - 1) + ";";
strRows = strRows.substring(0, strRows.length() - 1) + ";";
strTheData = strColumns + "\n" + strRows;
// We have the data locally; release the objects for GC
objRS.close();
objConn.close();
/*
load the local string into the Hashtable. In the CDX file, the
BarLabels and DataSet1 parameters should be replaced with the key
shown in the first parameter of the put method - in this case,
THEDATA.
*/
Hashtable objchartParams = new Hashtable();
objchartParams.put("THEDATA", strTheData);
/*
Create a NetCharts object and load the Hashtable into it. The
NetCharts object parameter is the project name in the Development
console. Note the name of the CDX file that goes with this dataset.
*/
NSWebToolKit objTK = new NSWebToolKit(strSolution + "\\" + strProject);
String strChart = objTK.getChartAsImageAndMap
(
strCDX,
objchartParams,
request,
true
);
// We're done; display the chart
out.println(strChart);
}
catch(Exception e)
{
e.printStackTrace();
out.println("
Query Failed." + "\n\n" +
e.getMessage() + "");
}
%>
<%@ include file="../Footer.inc" %>