NetCharts® Pro and a ChartEvent Example
This example uses the NetCharts Pro API to create a box chart. The source code is below.

Source Code
package ncpro.examples.standalone;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;import javax.swing.JFrame;
import netcharts.pro.charts.box.NFBoxSet;
import netcharts.pro.charts.box.NFBoxchart;
import netcharts.pro.common.NFDwell;
import netcharts.pro.common.NFFillPattern;
import netcharts.pro.common.NFFormat;
import netcharts.pro.common.NFGraph;
import netcharts.pro.common.NFLabel;
import netcharts.pro.common.NFLegend;
import netcharts.pro.common.NFLine;
import netcharts.pro.common.NFModalLabel;
import netcharts.pro.common.NFRegion;
import netcharts.pro.common.NFTitle;
import netcharts.pro.common.NFVector;
import netcharts.pro.common.lineset.NFLineSetSymbol;
import netcharts.pro.common.rectangular.NFAxis;public class MeanBoxExample {
public void go() {
NFBoxchart chart = null;try {
// create a new Barchart bean with the given chart template.
chart = new NFBoxchart();// don't update the underlying graphic until we are done.
chart.setAlwaysUpdate(false);// Set the width and height of the chart.
chart.setSize(300, 350);
// The color table.
NFVector colors = new NFVector();
colors.addElement(Color.gray);
chart.setColorTable(colors);
// Set the chart name.
chart.setChartName("boxwithmeanline");
// Set the background region.
chart.setBackgroundRegion(new NFRegion(Color.white, NFRegion.BOX, 1));
// Set antialias.
chart.setAntiAlias(true);
// Set the header.
chart.setHeader(new NFTitle(new NFLabel("Box with Mean Line", Color.black, new Font("SansSerif", Font.BOLD, 12), 0), null));
// Set the dwell area.
NFModalLabel dwellLabel = new NFModalLabel(true, Color.white, new Font("SansSerif", Font.PLAIN, 10));
NFRegion dwellRegion = new NFRegion(Color.gray, NFRegion.RAISED, 1);
chart.setDwell(new NFDwell(dwellLabel, dwellRegion));
// Turn the legend off.
NFLegend legend = new NFLegend();
legend.setLegendEnabled(false);
chart.setLegend(legend);
// Set the background fill pattern.
chart.setBackgroundFillPattern(new NFFillPattern(NFFillPattern.NONE));
// Set the box width.
chart.setBoxWidth(30);
// Set the box symbol width.
chart.setBoxSymbolWidth(70);
// Set the whisker type.
chart.setWhiskerType(NFBoxchart.LINE_WHISKER);
// Set the layout type.
chart.setLayout(NFBoxchart.VERTICAL);
// Set the display order.
chart.setNaturalDisplayOrder(true);
// Set the fence position.
chart.setFencePosition(NFBoxchart.UNDER);
// Set the median color.
chart.setMedianColor(new Color (0x69, 0x69, 0x69));
// Set the mean line.
chart.setMeanLine(NFLine.SOLID, 1, Color.blue);
// Set the data type.
chart.setDataIsSummary(false);
// You can disable the data related active labels
// by uncommenting the next line.
// chart.setDataActiveLabelsEnabled(false);
// Set the axis information.
NFAxis bottomAxis = chart.getBottomAxis();
bottomAxis.setTicLabel(new NFModalLabel(true, Color.black, new Font("SansSerif", Font.BOLD, 10)));
bottomAxis.setTicLayoutMode(NFAxis.AUTO);
bottomAxis.setSkipCount(0);
bottomAxis.setStaggerLevels(1);
chart.setBottomAxis(bottomAxis);
NFAxis leftAxis = chart.getLeftAxis();
leftAxis.setTicLabel(new NFModalLabel(true, Color.black, new Font("SansSerif", Font.BOLD, 10)));
leftAxis.setTicFormat(new NFFormat(NFFormat.INTEGER, "%4d"));
leftAxis.setScale(300, 900, 50);
chart.setLeftAxis(leftAxis);// At this point the program would likely go off and
// fetch the data for the chart. For this example
// we'll hardcode that data into arrays to simulate
// would could be returned.
double[] set1Data = new double[] {608.781,689.556,618.134,680.203,
726.232,518.655,740.447,666.83,710.272,751.669,697.979,
708.583,624.972,695.07,769.391,720.186,723.657,703.7,
697.626,714.98,657.712,609.989,650.771,707.977,712.199,
709.631,703.16,744.822,719.217,619.137,753.333,677.933,
735.919,695.274,504.167,693.333,625.0,596.667,640.898,
720.506,700.748,691.604,636.738,731.667,635.079,716.926,
759.581,673.903,736.648,675.957};
double[] set2Data = new double[] {729.23,697.239,728.499,797.662,
668.53,815.754,777.392,712.14,663.622,684.181,629.012,
640.193,644.156,642.469,639.09,439.418,614.664,537.161,
656.773,659.534,695.278,734.04,687.665,710.858,701.716,
382.133,719.744,756.82,690.978,670.864,670.308,660.062,
790.382,714.75,716.959,603.363,713.796,444.963,723.276,
745.527,778.333,723.349,708.229,681.667,566.085,687.448,
597.5,637.41,755.864,692.945};
double[] set3Data = new double[] {766.532,725.663,698.818,760.0,
775.272,708.885,727.201,642.56,690.773,688.333,743.973,
682.461,761.43,691.542,643.392,697.075,708.229,746.467,
744.819,655.029,715.224,614.417,761.363,716.106,659.502,
730.781,546.928,734.203,682.051,701.341,759.729,689.942,
769.424,715.286,776.197,547.099,619.942,696.046,573.109,
638.794,708.193,502.825,632.633,683.382,684.812,738.161,
671.492,709.771,685.199};
double[] set4Data = new double[] {624.973,757.363,633.417,658.754,
664.666,663.009,773.226,708.261,739.086,667.786,674.481,
695.688,588.288,545.61,752.305,684.523,717.159,721.343,
750.623,776.488,750.623,600.84,686.196,687.87,725.527,
658.796,690.38,737.144,663.851,766.63,625.922,694.43,
730.217,700.77,722.242,763.828,695.668,688.887,531.021,
698.915,735.905,732.039,751.832,618.663,744.845,690.826,
666.893,759.86,683.752,729.591,730.706,763.124,724.193,
630.352,750.338,752.417,707.899,715.582,728.746,591.193,
592.252,740.833,786.367,712.386,738.333,741.48,729.167,
795.833,723.502,718.333,768.08,747.5,775.0,760.599,758.333,
682.5,658.116,738.213,681.236,704.904,693.623,624.993,
700.228,611.874,579.167,720.872,690.32,677.933,674.6,
611.999,530.68};
double[] set5Data = new double[] {569.67,747.541,612.182,607.766,
605.38,589.226,588.375,531.384,633.417,619.06,632.447,
624.256,575.143,549.278,624.972,587.695,569.207,613.257,
565.737,662.131,543.177,512.394,611.19,659.982,569.245,
725.792,608.96,586.06,617.441,592.845,631.754,588.113,
555.724,702.411,631.754,698.254,616.791,551.953,636.738,
571.551,521.667,587.451,700.422,595.819,534.236,606.188,
575.303,590.628,729.314,619.313,624.234,651.304,724.175,
583.034,620.227,584.861,565.391,622.506,628.336,587.145,
584.319,538.239,538.097,595.686,648.935,583.827,534.905,
569.858,617.246,610.337,584.192,598.853,554.774,605.694,
627.516,574.522,582.682,563.872,715.962,616.43,778.011,
604.255,571.906,625.925,682.426,707.604,617.4,689.576,
676.678,563.29,581.879,447.701,557.772,593.537,632.585,
671.35,569.53,581.667,643.449,581.593,494.122,620.948,
615.903,606.667,579.167,662.51,436.237,644.223,586.035,
620.833,652.535,593.516,587.451,570.964,645.192,540.079,
707.117,621.779,585.777,703.98,698.237,757.12,621.751,
472.125,612.7,583.17,599.771,549.227,605.453,569.599,
637.233,621.774,558.041,583.17,345.294,570.999,603.232,
595.335,581.047,455.878,627.88,464.085,596.129,640.371,
621.471,612.727,606.46,571.76,599.304,579.459,761.511,
566.969,654.397,611.719,577.409,576.731,617.441,577.409,
548.957,623.315,621.761,553.978,657.157,610.882,552.304,
545.303,651.934,635.24,641.083,645.321,566.127,647.844,
554.815,620.087,711.301,644.355,713.812,696.707,589.453,
634.468,599.751,624.542,723.505,674.717,608.539,612.135,
591.935,676.656,647.323,811.97,603.883,608.643,630.778,
623.063,472.463,645.932,577.176,567.53,821.654,684.49,
600.427,686.023,628.109,605.214,640.26,700.767,665.924,
555.926,543.299,511.03,583.994,611.048,623.338,679.585,
665.004,655.86,715.711,611.999,577.722,615.129,540.316,
711.667,639.167,549.491,684.167,672.153,594.534,627.65,
551.87,594.534,602.66,585.45,555.724,574.934,584.625,
555.724,611.874,698.254,748.13,689.942};
// Add the box sets to the chart.
NFBoxSet boxSet1 = new NFBoxSet("Set1", null);
NFLineSetSymbol outlierSymbol = new NFLineSetSymbol(NFLineSetSymbol.CIRCLE, 4, NFLineSetSymbol.OUTLINED);
outlierSymbol.setOutlineColor(Color.red);
outlierSymbol.setOutlineWidth(1);
outlierSymbol.setColor(Color.red);
boxSet1.setOutlierSymbol(outlierSymbol);
NFLineSetSymbol meanSymbol = new NFLineSetSymbol(NFLineSetSymbol.DIAMOND, 6, NFLineSetSymbol.FILLED);
meanSymbol.setOutlineColor(Color.blue);
meanSymbol.setOutlineWidth(1);
meanSymbol.setColor(Color.blue);
boxSet1.setMeanSymbol(meanSymbol);
for (int i = 0; i < set1Data.length; i++) {
boxSet1.addElement(set1Data[i]);
}
chart.addBoxSet(boxSet1);
NFBoxSet boxSet2 = new NFBoxSet("Set2", null);
for (int i = 0; i < set2Data.length; i++) {
boxSet2.addElement(set2Data[i]);
}
chart.addBoxSet(boxSet2);
NFBoxSet boxSet3 = new NFBoxSet("Set3", null);
for (int i = 0; i < set3Data.length; i++) {
boxSet3.addElement(set3Data[i]);
}
chart.addBoxSet(boxSet3);
NFBoxSet boxSet4 = new NFBoxSet("Set4", null);
for (int i = 0; i < set4Data.length; i++) {
boxSet4.addElement(set4Data[i]);
}
chart.addBoxSet(boxSet4);
NFBoxSet boxSet5 = new NFBoxSet("Set5", null);
for (int i = 0; i < set5Data.length; i++) {
boxSet5.addElement(set5Data[i]);
}
chart.addBoxSet(boxSet5);
// 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 Mean Box Chart Example");
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add(chart.getPanel());
f.setSize(310, 375);
f.show();
} catch(Exception e) {
System.out.println("Error creating chart. Error: " + e.getMessage());
}
}
public static void main(String[] args) {
MeanBoxExample example = new MeanBoxExample();
example.go();
}
}
![]()



