NetCharts® Pro and Font Selection Servlet
This example shows the fonts available on the platform on which the example is deployed. It allows users to select a font and preview a chart built using that font. The source code is below.

Source Code
// Copyright 2002 by Visual Mining, Inc, Rockville, MD USA
// Permission to use, copy, modify, and to distribute this software
// and its documentation for any purpose is hereby granted
// without notice appear in all copies and that both that copyright
// notice and this permission notice appear in supporting documentation.
// Visual Mining Inc. disclaims all warranties with regard to this software,
// including all implied warranties of merchantability and fitness.
// In no event shall Visual Mining Inc. be liable for any special, indirect
// or consequential damages or any damages whatsoever resulting from
// loss of use, data or profits, whether in an action of contract,
// negligence or other tortuous action, arising out of or in
// connection with the use or performance of this software
///*
getChartWithFont
Visual Mining, Inc.This servlet produces an HTML page that contains an image of a
chart generated by NetCharts Pro using the specified font.This servlet represents the simplest possible scenario for
generating a chart image. It creates a chart object, loads
a template, generates an image and returns it.*/
package ncpro.examples.servlet;
import java.io.*;
import java.awt.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import netcharts.pro.common.*;
import netcharts.pro.util.*;public class getChartWithFont extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
try {
String selectedFont = (String)request.getParameter("fontSelected");// create a chart object from the template
NFGraph chart = null;
chart = NFGraph.getGraphFromTemplate(getChartTemplate(selectedFont));// generate an image and image map
byte[] imageData = NFImageGeneration.generateImage(chart,NFServletUtil.MIME_TYPE_PNG);// Release graph for garbage collection.
chart.stop();
chart = null;// build a response containing the image data
response.setContentType(NFServletUtil.MIME_TYPE_PNG);
response.setContentLength(imageData.length);
ServletOutputStream os = response.getOutputStream();
os.write(imageData, 0, imageData.length);// deliver the response
response.flushBuffer();} catch (Exception ex) {
System.out.println("chart creation failed " + ex.toString());
return;
}
}private String getChartTemplate(String selectedFont) {
String chartTemplate =
"ChartType = BARCHART;"+
"ChartName = fonttestchart;"+
"Background = (white,NONE,1,null,TILE,black);"+
"Legend = (OFF,black," + selectedFont+ ",10,0);"+
"Header = (\"" + selectedFont + " (18)\",black,\"" + selectedFont+ "\",18,0);"+
"Footer = (\"" + selectedFont + " (14)\",black,\"" + selectedFont+ "\",14,0);"+
"RightTitle = (\" \",black,\"" + selectedFont + "\",12,0);"+
"RightTitleBox = (null,NONE,2,null,TILE,black);"+
"DwellLabel = (ON,white,\"" + selectedFont+ "\",10,0);"+
"DwellLabelBox = (grey,RAISED,1,null,TILE,black);"+
"ColorTable = x284b53,x005699,xb8bc9c,x271651,xaa0036,xecf0b9;"+
"ChartSize = (500,300);"+
"AntiAlias = ON;"+
"Grid = (lightgray,null,black);"+
"GridLine = (BOTH,SOLID,1);"+
"GridAxis = (BOTTOM,LEFT);"+
"LeftScale = ;"+
"LeftTics = (ON,,\"" + selectedFont+ "\",10,0);"+
"LeftTicLayout = (AUTO,0,2);"+
"RightScale = ;"+
"RightTics = (OFF,,\"" + selectedFont+ "\",10,0);"+
"RightTicLayout = (AUTO,0,2);"+
"BottomScale = ;"+
"BottomTics = (ON,black,\"" + selectedFont+ "\",10,0);"+
"BottomTicLayout = (AUTO,0,2);"+
"Grid3DDepth = -1;"+
"BarLabels = \"January\",\"February\",\"March\",\"April\",\"May\";"+
"DataSets = (\"BarSet1\",null,BAR);"+
"DataSet1 = 100.0,125.0,245.78,147.0,67.0;"+
"BarBorder = (NONE,1,black);"+
"Bar3DDepth = 10;"+
"BarWidth = 61;"+
"GraphLayout = VERTICAL;"+
"GraphType = GROUP;";
return chartTemplate;}
}
![]()



