NetCharts® Pro and a Simple Chart-Enabled Program
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.

Using NetCharts Pro in Stand Alone Applications
The standalone examples are meant to be run from the $NCPROINSTALL/lib directory via a command line interface similar to java
-classpath .;ncpro.jar;ncproexamples.jar CLASSNAME
There are example batch files to run the examples with a directory $NCPROINSTALL/examples/programs/standalone.
Source Code
/*
SimpleExample
Visual Mining, Inc.This program demonstrates the use of NetCharts Pro to create,
populate and display a chart.The program demonstrates the use of a common model for integrating
charts into applications. It factors the chart definition into two
components - a static component and a dynamic component.The static component, often referred to as the chart template, contains
that part of the chart definition which does not change from instance
to instance. It includes attributes such as chart style, layout, colors,
fonts and sizes. Chart templates can be quickly created with Visual Mining's
NetCharts Designer, a graphical desktop tool that allows point-and-click creation
of chart definitions. Chart templates can also be created manually.
Chart Templates can be stored in separate disk files, or inlined as
string variables.The dynamic component of a chart definition contains the attributes which
change between invocations. Typically this is the actual data to be plotted,
axis bounds and titles. This data is fetched or computed at runtime and
added to the chart through api calls.The program can be compiled with a command similar to:
d:\jdk1.3\bin\javac -classpath "d:\ncpro.jar;." SimpleExample.javaThe program can be run with a command similar to:
d:\jdk1.3\bin\java -classpath "d:\ncpro.jar;." SimpleExample
*/package ncpro.examples.standalone;
import java.io.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import netcharts.pro.common.*;
import netcharts.pro.charts.bar.NFBarchart;
import netcharts.pro.common.barset.*;public class SimpleExample {
private String chartTemplate =
"ChartType = BARCHART;"+
"ChartName = \"NetCharts Pro Example\";"+
"Background = (white,NONE,4,null,TILE,black);" +
"AntiAlias = ON;"+
"BarWidth = 61;"+
"Bar3DDepth = 0;"+
"Header = (\" \",black,\"Helvetica\",16,0);"+
"HeaderBox = (null,NONE,5,null,TILE,black);"+
"DataAxis = (BOTTOM,LEFT);"+
"Grid = (gainsboro,white,white,null,TILE);"+
"Legend = (\"Support Level \",black,\"Helvetica\",10,0);"+
"LegendLayout = (HORIZONTAL,BOTTOM,0,0,TOPLEFT,-1);"+
"LegendBox = (,BOX,1,,TILE,grey);"+
"RightTitle = (\" \",black,\"Helvetica\",12,0);"+
"LeftTitle = (\"Number\n of \nCalls\n (000's) \",black,\"Helvetica\",12,0);"+
"LeftTitleBox = (null,NONE,0,null,TILE,black);"+
"LeftScale = (null,null,null);"+
"LeftTics = (\"ON\",grey,\"Helvetica\",10,0,null);"+
"LeftColor = grey;"+
"BottomTics = (\"ON\",grey,\"Helvetica\",10,0,null);"+
"BottomColor = grey;"+
"DataSets = (\"Evaluation\",x008b87,BAR,4,FILLED),(\"Standard\",x99cccc,BAR,4,FILLED),
(\"Platinum\",xe2ebf0,BAR,4,FILLED);"+
"DwellLabel = (,black,\"Helvetica\",12,0);";public void go() {
NFBarchart chart;int chartWidth = 600;
int chartHeight = 350;try {
// create a new Barchart bean with the given chart template.
chart = new NFBarchart();// don't update the underlying graphic until we are done.
chart.setAlwaysUpdate(false);// initialize the chart from the base template.
chart.initializeFromString(chartTemplate);// load the dynamic content into the chart.
// Set the width and height of the chart.
chart.setSize(chartWidth, chartHeight);// At this point the program would likely go off and
// fetch the dynamic portions of the chart definition.
// For this example we'll hardcode that data into
// arrays to simulate data returned from some source
String titleData = "Eastern Region Call Centers";
String titleData2 = "Q2 Call Volume by Type";
String[] barLabelData = {"Atlanta","Washington","Philadelphia","Boston"};
int[] level0Data = {15,30,35,55};
int[] level1Data = {40,35,25,30};
int[] level2Data = {45,35,40,15};// load the bottom labels into the chart from a vector.
NFVector barLabels = new NFVector();
for (int i=0; i<barLabelData.length; i++) {
barLabels.addElement(barLabelData[i]);
}
chart.setDataLabels(barLabels);// set the bar values.
NFBarSeries bs = chart.getBarSeries();// load level0 support data bar values.
NFBarSet level0 = (NFBarSet)bs.elementAt(0);
for (int i=0; i<level0Data.length; i++) {
level0.addElement(new Integer(level0Data[i]));
}// load level1 support data bar values.
NFBarSet level1 = (NFBarSet)bs.elementAt(1);
for (int i=0; i<level1Data.length; i++) {
level1.addElement(new Integer(level1Data[i]));
}// load level2 support data bar values.
NFBarSet level2 = (NFBarSet)bs.elementAt(2);
for (int i=0; i<level2Data.length; i++) {
level2.addElement(new Integer(level2Data[i]));
}// save the bar series into the chart.
chart.setBarSeries(bs);// customize title for chart.
NFTitle header = (NFTitle)chart.getHeader();
header.setText(titleData + "\n" + titleData2);
chart.setHeader(header);// update the chart with all of the changes.
chart.sendUpdate();// (Debug) print the graph CDL as finally loaded.
System.out.println("Chart CDL:\n");
System.out.println(chart.toString());
System.out.println("\n\n");// create the Frame that will contain the chart.
JFrame f = new JFrame("Visual Mining NetCharts Pro Barchart Example");
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add(chart.getPanel());
f.setSize(chart.getPanel().getSize());
f.show();
} catch(Exception e) {
System.out.println("Error creating chart. Error: " + e.getMessage());
}
}public static void main(String[] args) {
SimpleExample example = new SimpleExample();
example.go();
}
}
![]()



