Visual Mining contact us | site map | search

Products Solutions Resource Library Services Customers Partners Developers Company
Developers

NetCharts® Server: Java Toolkit getNDSDataAsCSV Example

This example shows how to utilize the NetCharts Server Java Toolkit to retrieve data from a configured data source as CSV (Comma Separated Values). The CSV can be then saved, displayed to the user or modified as needed. The example uses the netcharts.server.api.NSToolkit class to retrieve the data and then parses the CSV to display the data in an HTML table. See the Source Code.

Note: This is a static image only - no interactivity.
NetCharts Server using a csv data source

Source Code

<%@ page import="netcharts.server.api.NSToolKit" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="java.util.StringTokenizer" %>

<html>
<head>
<title>NetCharts Server Java Toolkit Example - getNDSDataAsCSV</title>
</head>
<p>Create an instance of the <i>NSToolKit</i> class.</p>
<body>
<%
NSToolKit toolKit = new NSToolKit("localhost", 8001, "Examples/Suppliers");
// If the JSP page is running with NetCharts Server, use this constructor instead.
// NSToolKit toolKit = new NSToolKit("Examples/Suppliers");
%>

<p>The function <i>getNDSDataAsCSV</i> is used to get data from a
server configured data source formatted as a <b>CSV (Comma Separated Value)</b> string.
(NOTE: The data is parsed, using the java.util.StringTokenizer, into an HTML table for display purposes)</p>

<div align="center">
<center>
<table border="1" width="80%">
<%
StringBuffer sb = new StringBuffer();
String data = toolKit.getNDSDataAsCSV("SupplierByFacility.ndx", (Hashtable)null, '/');
StringTokenizer st = new StringTokenizer(data, "\n");
while (st.hasMoreTokens()) {
StringTokenizer tokens = new StringTokenizer(st.nextToken(), "/", false);
sb.append("<tr>");
while (tokens.hasMoreTokens()) {
sb.append("<td width=\"100%\">");
sb.append(tokens.nextToken());
sb.append("</td>");
}
sb.append("</tr>");
}
%>
<%=sb.toString()%>
</table>
</center>
</div>

</body>
</html>


© 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: Scientech