package org.corpstein.image;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import junit.framework.*;
public class TestChartFactory extends TestCase
{
private ChartFactory factory;
protected void setUp()
{
factory = ChartFactory.getInstance();
}
public void testCanReadFormat()
{
assertTrue(factory.canReadFormat("png"));
assertTrue(factory.canReadFormat("jpg"));
assertFalse(factory.canReadFormat("pdf"));
assertFalse(factory.canReadFormat("sh"));
assertFalse(factory.canReadFormat(""));
try { factory.canReadFormat(null); fail("Expected IllegalArgumentException since the argument is null"); } catch(IllegalArgumentException e) { }
}
public void testCanWriteFormat()
{
assertTrue(factory.canWriteFormat("png"));
assertTrue(factory.canWriteFormat("jpg"));
assertFalse(factory.canWriteFormat("pdf"));
assertFalse(factory.canWriteFormat("sh"));
assertFalse(factory.canWriteFormat(""));
try { factory.canWriteFormat(null); fail("Expected IllegalArgumentException since the argument is null"); } catch(IllegalArgumentException e) { }
}
public void testBar01()
{
ChartData data = new ChartData();
data.setTitle("Scottish Fishing Vessels by District, 1997");
data.addPoint("Aberdeen", 46);
data.addPoint("Arbroath", 72);
data.addPoint("Ayr", 181);
data.addPoint("Buckle", 151);
data.addPoint("Campbelltown", 190);
data.addPoint("Eyemouth", 125);
data.addPoint("Fraserburgh", 271);
data.addPoint("Kinlochbervie", 28);
data.addPoint("Lochinver", 32);
data.addPoint("Mallaig", 248);
data.addPoint("Oban", 175);
data.addPoint("Orkney", 206);
data.addPoint("Peterhead", 159);
data.addPoint("Pittenweem", 103);
data.addPoint("Shetland", 221);
data.addPoint("Stornoway", 353);
data.addPoint("Ullapool", 60);
data.addPoint("Wick", 142);
Image image = factory.createBarChart(data);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestBar01.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testBar02()
{
ChartStyle style = new ChartStyle();
style.setPaint(ChartStyle.COLOR_WALL, new Color(1.0f, 1.0f, 0.8f));
style.setBorderEnabled(true);
style.setValueLabelsEnabled(true);
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setBarPaint(Color.YELLOW);
try
{
ImageLayer layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage10.gif").getPath()));
layer.setX(40);
layer.setY(406);
layer.setZ(ChartMetrics.Z_INDEX_BACKDROP + 1);
style.addLayer(layer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
ChartData data = new ChartData();
data.setTitle("April 2003 Java Servlet Engine IP Addresses (www.netcraft.com)");
data.addPoint("Tomcat", 9253);
data.addPoint("Resin", 9059);
data.addPoint("IBM", 9049);
data.addPoint("Oracle", 5156);
data.addPoint("WebLogic", 1716);
data.addPoint("Orion", 1062);
data.addPoint("Jetty", 635);
data.addPoint("JavaWebServer", 388);
data.addPoint("SilverStream", 370);
data.addPoint("JRun", 264);
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestBar02.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testBar03()
{
ChartStyle style = new ChartStyle();
style.setPaint(ChartStyle.COLOR_LABEL, new Color(1.0f, 1.0f, 0.9f));
style.setPaint(ChartStyle.COLOR_SHADOW, new Color(0.0f, 0.2f, 0.0f));
style.setPaint(ChartStyle.COLOR_BACKGROUND, new Color(0.1f, 0.5f, 0.1f));
style.setPaint(ChartStyle.COLOR_WALL, new Color(0.4f, 0.8f, 0.4f));
style.setPaint(ChartStyle.COLOR_EDGE, new Color(0.0f, 0.1f, 0.0f));
style.setBarPaint(0, new Color(0.9f, 0.9f, 0.6f));
style.setKeyType(ChartStyle.KEY_TYPE_BAR_COLOR_ASSOCIATION);
style.setValueLabelsEnabled(true);
style.setBorderEnabled(true);
TextLayer layer = new TextLayer("Source: Netcraft (www.netcraft.com)");
layer.setFont(new Font("SansSerif", Font.BOLD, 12));
layer.setFontColor(Color.WHITE);
layer.setX(300);
layer.setY(100);
layer.setZ(ChartMetrics.Z_INDEX_BACKDROP + 1);
style.addLayer(layer);
ChartData data = new ChartData();
data.setTitle("April 2003 Java Servlet Engine Sites");
data.addPoint("Tomcat", 64532);
data.addPoint("Resin", 138664);
data.addPoint("IBM", 38730);
data.addPoint("Oracle", 18072);
data.addPoint("WebLogic", 6819);
data.addPoint("Orion", 6358);
data.addPoint("Jetty", 1865);
data.addPoint("JavaWebServer", 949);
data.addPoint("SilverStream", 966);
data.addPoint("JRun", 17859);
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestBar03.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testBar04()
{
ChartStyle style = new ChartStyle();
style.setPaint(ChartStyle.COLOR_LABEL, new Color(1.0f, 1.0f, 0.9f));
style.setPaint(ChartStyle.COLOR_SHADOW, new Color(0.0f, 0.2f, 0.0f));
style.setPaint(ChartStyle.COLOR_BACKGROUND, new GradientPaint(320, 240, new Color(0.1f, 0.5f, 0.1f), 640, 480, new Color(0.0f, 0.3f, 0.1f)));
style.setPaint(ChartStyle.COLOR_WALL, new GradientPaint(250, 135, new Color(0.4f, 0.8f, 0.4f), 500, 270, new Color(0.3f, 0.7f, 0.3f)));
style.setPaint(ChartStyle.COLOR_EDGE, new Color(0.0f, 0.1f, 0.0f));
style.setBarPaint(new Color(0.9451f, 0.9451f, 0.1059f));
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
try
{
ImageLayer layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage03.gif").getPath()));
layer.setX(416);
layer.setY(231);
layer.setZ(ChartMetrics.Z_INDEX_SCALE + 1);
style.addLayer(layer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
TextLayer textLayer = new TextLayer("Tornado reported at 22:56:00");
textLayer.setFont(new Font("SansSerif", Font.BOLD, 14));
textLayer.setFontColor(Color.WHITE);
textLayer.setX(355);
textLayer.setY(195);
textLayer.setZ(ChartMetrics.Z_INDEX_SCALE + 1);
style.addLayer(textLayer);
textLayer = new TextLayer("http://thunder.msfc.nasa.gov/bookshelf/docs/white_paper_driscoll.html");
textLayer.setFont(new Font("SansSerif", Font.BOLD, 14));
textLayer.setFontColor(Color.WHITE);
textLayer.setX(60);
textLayer.setY(430);
textLayer.setZ(ChartMetrics.Z_INDEX_TITLE + 1);
style.addLayer(textLayer);
ChartData data = new ChartData();
data.setTitle("Storm Cell Lightning Strikes (17 Apr 1995)");
data.addPoint("22:50:00", 2);
data.addPoint("22:50:30", 1);
data.addPoint("22:51:00", 2);
data.addPoint("22:51:30", 1);
data.addPoint("22:52:00", 75);
data.addPoint("22:52:30", 121);
data.addPoint("22:53:00", 95);
data.addPoint("22:53:30", 58);
data.addPoint("22:54:00", 51);
data.addPoint("22:54:30", 30);
data.addPoint("22:55:00", 5);
data.addPoint("22:55:30", 3);
data.addPoint("22:56:00", 0);
data.addPoint("22:56:30", 2);
data.addPoint("22:57:00", 1);
data.addPoint("22:57:30", 0);
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestBar04.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testBar05()
{
ChartStyle style = new ChartStyle();
style.setBorderEnabled(true);
style.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
style.setKeyType(ChartStyle.KEY_TYPE_HORIZONTAL_BAR_LABELS);
style.setValueLabelsEnabled(true);
try
{
ImageLayer layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage04.png").getPath()));
layer.setX(20);
layer.setY(20);
layer.setZ(ChartMetrics.Z_INDEX_TITLE + 1);
style.addLayer(layer);
layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage09.png").getPath()));
layer.setX(40);
layer.setY(396);
style.addLayer(layer);
layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage14.png").getPath()));
layer.setX(12);
layer.setY(180);
style.addLayer(layer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
TextLayer textLayer = new TextLayer("Source: Netcraft (www.netcraft.com)");
textLayer.setFont(new Font("SansSerif", Font.PLAIN, 12));
textLayer.setFontColor(new Color(0.0f, 0.0f, 1.0f));
textLayer.setX(415);
textLayer.setY(455);
textLayer.setZ(ChartMetrics.Z_INDEX_TITLE + 1);
style.addLayer(textLayer);
ChartData data = new ChartData();
data.addPoint("Apache", 68.43);
data.addPoint("Microsoft", 20.86);
data.addPoint("Sun", 3.14);
data.addPoint("Zeus", 1.19);
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestBar05.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testBar06()
{
ChartStyle style = new ChartStyle();
style.setPaint(ChartStyle.COLOR_LABEL, new Color(0.5f, 0.0f, 0.0f));
style.setPaint(ChartStyle.COLOR_SHADOW, new Color(0.95f, 0.85f, 0.85f));
style.setPaint(ChartStyle.COLOR_WALL, new Color(1.0f, 1.0f, 0.8f));
style.setPaint(ChartStyle.COLOR_EDGE, new Color(0.2f, 0.0f, 0.0f));
TextLayer layer = new TextLayer("Source: TechRepublic survey");
layer.setFontColor(new Color(0.5f, 0.0f, 0.0f));
layer.setX(390);
layer.setY(445);
style.addLayer(layer);
style.setValueLabelsEnabled(true);
style.setKeyType(ChartStyle.KEY_TYPE_BAR_COLOR_ASSOCIATION);
ChartData data = new ChartData();
data.setTitle("Most Influential Factors in Moving to Linux");
data.addPoint("Cost", 40.0);
data.addPoint("Ease of Implementation", 10.0);
data.addPoint("Ease of Training", 3.6);
data.addPoint("Reliability", 39.2);
data.addPoint("Scalability", 7.2);
for(int i=0; i<data.getTotalValues(); i++)
{
style.setBarPaint(i, new GradientPaint(330, 340, (Color)style.getBarPaint(i), 330, 200, Palette.brighten(style.getBarPaint(i), 3)));
}
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestBar06.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testBar07()
{
ChartStyle style = new ChartStyle();
style.setPaint(ChartStyle.COLOR_WALL, new Color(0.16f, 0.36f, 0.35f));
style.setPaint(ChartStyle.COLOR_EDGE, new Color(0.0f, 0.2f, 0.0f));
style.setValueLabelsEnabled(true);
try
{
ImageLayer layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage05.jpg").getPath()));
layer.setX(77);
layer.setY(74);
layer.setZ(ChartMetrics.Z_INDEX_BACKDROP + 1);
style.addLayer(layer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
TextLayer textLayer = new TextLayer("Source: British Columbia Ministry of Water, Land, and Air Protection");
textLayer.setFont(new Font("SansSerif", Font.BOLD, 12));
textLayer.setFontColor(new Color(0.0f, 0.0f, 1.0f));
textLayer.setX(120);
textLayer.setY(410);
style.addLayer(textLayer);
textLayer = new TextLayer("http://wlapwww.gov.bc.ca/soerpt/995wildlife/gheron.html");
textLayer.setFont(new Font("SansSerif", Font.BOLD, 12));
textLayer.setFontColor(new Color(0.0f, 0.0f, 1.0f));
textLayer.setX(145);
textLayer.setY(425);
style.addLayer(textLayer);
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setBarPaint(new Color(0.94f, 0.94f, 0.0f, 0.9f));
ChartData data = new ChartData();
data.setTitle("PCB Contaminants in Great Blue Heron Eggs (mg/kg)");
data.addPoint("1977", 7.3);
data.addPoint("1982", 4.4);
data.addPoint("1983", 1.6);
data.addPoint("1985", 2.4);
data.addPoint("1986", 1.1);
data.addPoint("1987", 1.2);
data.addPoint("1988", 1.3);
data.addPoint("1989", 0.8);
data.addPoint("1990", 1);
data.addPoint("1991", 1.8);
data.addPoint("1992", 1);
data.addPoint("1993", 1.7);
data.addPoint("1994", 1.9);
data.addPoint("1996", 3.4);
data.addPoint("1998", 0.9);
data.addPoint("2000", 1.1);
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestBar07.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testBar08()
{
ChartStyle style = new ChartStyle();
style.setPaint(ChartStyle.COLOR_LABEL, new Color(1.0f, 1.0f, 1.0f));
style.setPaint(ChartStyle.COLOR_SHADOW, new Color(0.16f, 0.35f, 0.64f));
style.setPaint(ChartStyle.COLOR_BACKGROUND, new GradientPaint(210, 160, new Color(0.16f, 0.35f, 0.64f), 420, 320, new Color(0.1f, 0.3f, 0.5f)));
style.setPaint(ChartStyle.COLOR_WALL, new Color(0.84f, 0.84f, 1.0f));
style.setPaint(ChartStyle.COLOR_EDGE, new Color(0.0f, 0.0f, 0.0f));
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setBarPaint(new Color(0.64f, 0.92f, 0.55f));
style.setBorderEnabled(true);
ChartData data = new ChartData();
data.setTitle("Long Title String Long Title String Long Title String Long Title String Long Title String Long Title String");
data.addPoint("- -", -1200);
data.addPoint("\"Watch out for", 91253);
data.addPoint("novel uses for COMGRAM", 90549);
data.addPoint("(CONtractor GRAMmar", -12020);
data.addPoint("defined by the", 3995156);
data.addPoint("imperfect past,", 0.0);
data.addPoint("the insufficient present", 10362.0);
data.addPoint("and the absolutely", 6375);
data.addPoint("perfect future.\"", 3688);
data.addPoint("-- Grammar advice from", 2135370);
data.addPoint("Amron Katz", 2464);
data.addPoint("- -", 97253);
data.addPoint("I took a course in", 96059);
data.addPoint("speed reading and was", -11200);
data.addPoint("able to read War and Peace", 8995156);
data.addPoint("in twenty minutes.", 0);
data.addPoint("It's about Russia.", 1062.1);
data.addPoint("-- Woody Allen", 6135);
data.addPoint("- -", 3818);
data.addPoint("Quidquid latine dictum sit,", 3701);
data.addPoint("altum viditur.", 2641);
data.addPoint("(Whatever is said in Latin", 92532);
data.addPoint("sounds profound)", 90593);
data.addPoint("- -", -13200);
data.addPoint("If you are", 7295254);
data.addPoint("seeing these, I", 0);
data.addPoint("must have finally", 1062.0);
data.addPoint("gotten around to", 635);
data.addPoint("fixing ChartStyle.MAX_BARS.", 388);
data.addPoint("Bully", 370);
data.addPoint("for", 264);
data.addPoint("me", 18995156);
data.addPoint("- -", 1277);
data.addPoint("Children are unpredictable. You never know what inconsistency they're going to catch you in next. --Franklin P. Jones", 71234);
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestBar08.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testLine01()
{
ChartStyle style = new ChartStyle();
style.setChartType(ChartStyle.CHART_TYPE_LINE);
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setBarPaint(0, new Color(0.4f, 0.0f, 0.3f));
style.setBarPaint(1, new Color(0.9f, 0.2f, 0.1f));
ChartData data = new ChartData();
data.setTitle("Turn Results");
data.addKeyLabel("BoN/K");
data.addKeyLabel("Masada");
data.addLabel("0");
data.addValue(20);
data.addValue(20);
data.addLabel("1");
data.addValue(19);
data.addValue(20);
data.addLabel("2");
data.addValue(18);
data.addValue(20);
data.addLabel("3");
data.addValue(18);
data.addValue(20);
data.addLabel("BoN");
data.addValue(18);
data.addValue(20);
data.addLabel("5");
data.addValue(15);
data.addValue(20);
data.addLabel("6");
data.addValue(12);
data.addValue(16);
data.addLabel("CoP");
data.addValue(12);
data.addValue(16);
data.addLabel("ET");
data.addValue(12);
data.addValue(16);
data.addLabel("K");
data.addValue(12);
data.addValue(9);
data.addLabel("10");
data.addValue(12);
data.addValue(2);
data.addLabel("11");
data.addValue(7);
data.addValue(0);
Image image = factory.createChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestLine01.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testLine02()
{
ChartStyle style = new ChartStyle();
style.setChartType(ChartStyle.CHART_TYPE_LINE);
style.setPaint(ChartStyle.COLOR_LABEL, new Color(1.0f, 1.0f, 0.9f));
style.setPaint(ChartStyle.COLOR_SHADOW, new Color(0.0f, 0.2f, 0.0f));
style.setPaint(ChartStyle.COLOR_BACKGROUND, new GradientPaint(210, 160, new Color(0.1f, 0.5f, 0.1f), 420, 320, new Color(0.0f, 0.45f, 0.0f)));
style.setPaint(ChartStyle.COLOR_WALL, new Color(0.4f, 0.8f, 0.4f));
style.setPaint(ChartStyle.COLOR_EDGE, new Color(0.0f, 0.1f, 0.0f));
style.setBorderEnabled(true);
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setShowPointMarks(true);
style.setBarPaint(0, new Color(0.9451f, 0.1882f, 0.10f, 0.8f));
style.setBarPaint(1, new Color(0.9843f, 0.5961f, 0.07f, 0.8f));
style.setBarPaint(2, new Color(0.3f, 1.0f, 0.3f, 0.8f));
style.setBarPaint(3, new Color(0.2f, 0.2f, 1.0f, 0.8f));
style.setBarPaint(4, new Color(0.9451f, 0.1059f, 0.94f, 0.8f));
style.setBarPaint(5, new Color(0.8f, 0.8f, 0.0f, 0.8f));
style.setBarPaint(6, new Color(0.6f, 0.1f, 0.2f, 0.8f));
style.setBarPaint(7, new Color(1.0f, 1.0f, 1.0f, 0.8f));
ChartData data = new ChartData();
data.setTitle("Peak Categories by Number of Calls");
data.addKeyLabel("Custom - Ardvaark");
data.addKeyLabel("Custom - Galleto");
data.addKeyLabel("Custom - Integrated POD");
data.addKeyLabel("Custom - MRP");
data.addKeyLabel("Desktop - Malware");
data.addKeyLabel("Servers - Document Management");
data.addKeyLabel("Networks - Connectivity");
data.addKeyLabel("Networks - Email");
data.addLabel("M 9/6");
data.addValue(1);
data.addValue(4);
data.addValue(11);
data.addValue(2);
data.addValue(0);
data.addValue(4);
data.addValue(7);
data.addValue(6);
data.addLabel("T 9/7");
data.addValue(0);
data.addValue(6);
data.addValue(3);
data.addValue(1);
data.addValue(0);
data.addValue(4);
data.addValue(8);
data.addValue(5);
data.addLabel("W 9/8");
data.addValue(1);
data.addValue(3);
data.addValue(10);
data.addValue(1);
data.addValue(0);
data.addValue(5);
data.addValue(1);
data.addValue(4);
data.addLabel("T 9/9");
data.addValue(0);
data.addValue(1);
data.addValue(3);
data.addValue(2);
data.addValue(0);
data.addValue(4);
data.addValue(0);
data.addValue(9);
data.addLabel("F 9/10");
data.addValue(1);
data.addValue(1);
data.addValue(2);
data.addValue(4);
data.addValue(0);
data.addValue(4);
data.addValue(0);
data.addValue(7);
data.addLabel("S 9/11");
data.addValue(0);
data.addValue(1);
data.addValue(0);
data.addValue(3);
data.addValue(0);
data.addValue(0);
data.addValue(0);
data.addValue(0);
data.addLabel("S 9/12");
data.addValue(0);
data.addValue(0);
data.addValue(1);
data.addValue(1);
data.addValue(0);
data.addValue(0);
data.addValue(0);
data.addValue(0);
data.addLabel("M 9/13");
data.addValue(12);
data.addValue(3);
data.addValue(0);
data.addValue(19);
data.addValue(1);
data.addValue(4);
data.addValue(0);
data.addValue(0);
data.addLabel("T 9/14");
data.addValue(16);
data.addValue(7);
data.addValue(0);
data.addValue(12);
data.addValue(6);
data.addValue(5);
data.addValue(0);
data.addValue(0);
data.addLabel("W 9/15");
data.addValue(4);
data.addValue(8);
data.addValue(0);
data.addValue(12);
data.addValue(0);
data.addValue(1);
data.addValue(0);
data.addValue(0);
data.addLabel("T 9/16");
data.addValue(0);
data.addValue(12);
data.addValue(1);
data.addValue(5);
data.addValue(1);
data.addValue(0);
data.addValue(0);
data.addValue(0);
data.addLabel("F 9/17");
data.addValue(0);
data.addValue(3);
data.addValue(4);
data.addValue(1);
data.addValue(0);
data.addValue(0);
data.addValue(0);
data.addValue(0);
data.addLabel("S 9/18");
data.addValue(0);
data.addValue(0);
data.addValue(2);
data.addValue(2);
data.addValue(0);
data.addValue(0);
data.addValue(0);
data.addValue(0);
data.addLabel("S 9/19");
data.addValue(0);
data.addValue(0);
data.addValue(1);
data.addValue(5);
data.addValue(0);
data.addValue(0);
data.addValue(0);
data.addValue(0);
Image image = factory.createChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestLine02.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testLine03()
{
ChartStyle style = new ChartStyle();
style.setChartType(ChartStyle.CHART_TYPE_LINE);
style.setPaint(ChartStyle.COLOR_LABEL, new Color(0.0f, 0.1f, 0.7f));
style.setPaint(ChartStyle.COLOR_WALL, new Color(1.0f, 1.0f, 0.9f));
style.setPaint(ChartStyle.COLOR_EDGE, new Color(0.0f, 0.0f, 0.0f));
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setBorderEnabled(true);
style.setShowPointMarks(true);
style.setPointMarkSize(6);
style.setBarPaint(0, new Color(0.9451f, 0.1882f, 0.1059f));
style.setBarPaint(1, new Color(0.9843f, 0.5961f, 0.0667f));
style.setBarPaint(2, new Color(0.1882f, 0.7451f, 0.1059f));
style.setBarPaint(3, new Color(0.2f, 0.2f, 1.0f));
style.setBarPaint(4, new Color(0.9451f, 0.1059f, 0.9451f));
style.setBarPaint(5, new Color(0.8f, 0.8f, 0.0f));
style.setBarPaint(6, new Color(0.6f, 0.1f, 0.2f));
style.setBarPaint(7, new Color(0.0f, 0.4f, 0.1f));
ChartData data = new ChartData();
data.setTitle("Compromised Windows 2K+ Server Traffic");
data.addKeyLabel("Microsoft-DS Sources");
data.addKeyLabel("Microsoft-DS Targets");
data.addKeyLabel("MS-SQL-S Sources");
data.addKeyLabel("MS-SQL-S Targets");
data.addKeyLabel("NetBIOS-NS Sources");
data.addKeyLabel("NetBIOS-NS Targets");
data.addKeyLabel("NetBIOS-SSN Sources");
data.addKeyLabel("NetBIOS-SSN Targets");
data.addLabel("8/28");
data.addValue(369111 );
data.addValue(151330);
data.addValue(9923 );
data.addValue(14843);
data.addValue(15930 );
data.addValue(148900);
data.addValue(24629 );
data.addValue(30750);
data.addLabel("8/29");
data.addValue(792567 );
data.addValue(209094);
data.addValue(21780);
data.addValue(40687);
data.addValue(21553 );
data.addValue(215164);
data.addValue(30995 );
data.addValue(98002);
data.addLabel("8/30");
data.addValue(504577 );
data.addValue(122203);
data.addValue(18231);
data.addValue(17233);
data.addValue(21134 );
data.addValue(167229);
data.addValue(52692 );
data.addValue(112815);
data.addLabel("8/31");
data.addValue(814728 );
data.addValue(253267);
data.addValue(22374);
data.addValue(37019);
data.addValue(36492 );
data.addValue(230224);
data.addValue(51340 );
data.addValue(87729);
data.addLabel("9/1");
data.addValue(797670 );
data.addValue(268238);
data.addValue(24345);
data.addValue(33067);
data.addValue(36491 );
data.addValue(238555);
data.addValue(48476 );
data.addValue(170650);
data.addLabel("9/2");
data.addValue(740808 );
data.addValue(243930);
data.addValue(24011);
data.addValue(44851);
data.addValue(35553 );
data.addValue(232850);
data.addValue(47752 );
data.addValue(198998);
data.addLabel("9/3");
data.addValue(735762 );
data.addValue(215556);
data.addValue(22116);
data.addValue(39651);
data.addValue(33838 );
data.addValue(232527);
data.addValue(46141 );
data.addValue(211998);
data.addLabel("9/4");
data.addValue(699300 );
data.addValue(188257);
data.addValue(19288);
data.addValue(87331);
data.addValue(23767 );
data.addValue(178592);
data.addValue(42219 );
data.addValue(173769);
data.addLabel("9/5");
data.addValue(696474 );
data.addValue(211101);
data.addValue(19581);
data.addValue(34480);
data.addValue(20999 );
data.addValue(157343);
data.addValue(40266 );
data.addValue(78668);
data.addLabel("9/6");
data.addValue(741702);
data.addValue(180191);
data.addValue(22087);
data.addValue(95206);
data.addValue(31363 );
data.addValue(193665);
data.addValue(46611 );
data.addValue(157081);
data.addLabel("9/7");
data.addValue(447580);
data.addValue(226929);
data.addValue(16576);
data.addValue(67022);
data.addValue(19476 );
data.addValue(218071);
data.addValue(34471 );
data.addValue(130507);
Image image = factory.createChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestLine03.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testLine04()
{
ChartStyle style = new ChartStyle();
style.setChartType(ChartStyle.CHART_TYPE_LINE);
style.setPaint(ChartStyle.COLOR_WALL, new GradientPaint(310, 205, new Color(0.7f, 1.0f, 0.7f), 240, 305, new Color(0.3f, 1.0f, 0.3f)));
style.setPaint(ChartStyle.COLOR_LABEL, new Color(0.0f, 0.0f, 0.6f));
style.setPaint(ChartStyle.COLOR_SHADOW, new Color(0.9f, 0.9f, 1.0f));
style.setPaint(ChartStyle.COLOR_EDGE, new Color(0.0f, 0.1f, 0.0f));
TextLayer layer = new TextLayer("Source: Netcraft (www.netcraft.com)");
layer.setFont(new Font("SansSerif", Font.PLAIN, 12));
layer.setFontColor(new Color(0.0f, 0.0f, 0.6f));
layer.setX(400);
layer.setY(462);
style.addLayer(layer);
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setShowPointMarks(true);
style.setPointMarkSize(5);
style.setBarPaint(0, Color.RED);
style.setBarPaint(1, Color.BLUE);
style.setBarPaint(2, Color.GRAY);
style.setBarPaint(3, new Color(0.7f, 0.0f, 0.7f));
style.setBarPaint(4, new Color(1.0f, 1.0f, 0.4f));
ChartData data = new ChartData();
data.setTitle("Totals for Active Servers Across All Domains");
data.addKeyLabel("Apache");
data.addKeyLabel("Microsoft");
data.addKeyLabel("Sun");
data.addKeyLabel("NCSA");
data.addKeyLabel("Other");
data.addLabel("Jun 00");
data.addValue(383000);
data.addValue(190000);
data.addValue(21000);
data.addValue(0);
data.addValue(84000);
data.addLabel("Sep 00");
data.addValue(540000);
data.addValue(198000);
data.addValue(22500);
data.addValue(0);
data.addValue(88000);
data.addLabel("Dec 00");
data.addValue(630000);
data.addValue(206000);
data.addValue(19500);
data.addValue(0);
data.addValue(88500);
data.addLabel("Mar 01");
data.addValue(660000);
data.addValue(270000);
data.addValue(20000);
data.addValue(0);
data.addValue(87000);
data.addLabel("Jun 01");
data.addValue(730000);
data.addValue(340000);
data.addValue(19000);
data.addValue(0);
data.addValue(92000);
data.addLabel("Sep 01");
data.addValue(790000);
data.addValue(360000);
data.addValue(19500);
data.addValue(0);
data.addValue(90000);
data.addLabel("Dec 01");
data.addValue(890000);
data.addValue(359000);
data.addValue(21000);
data.addValue(0);
data.addValue(88000);
data.addLabel("Mar 02");
data.addValue(960000);
data.addValue(380000);
data.addValue(20500);
data.addValue(0);
data.addValue(91000);
data.addLabel("Jun 02");
data.addValue(1080000);
data.addValue(430000);
data.addValue(21000);
data.addValue(0);
data.addValue(92500);
data.addLabel("Sep 02");
data.addValue(1060000);
data.addValue(420000);
data.addValue(20000);
data.addValue(0);
data.addValue(93000);
data.addLabel("Dec 02");
data.addValue(1080000);
data.addValue(415000);
data.addValue(18500);
data.addValue(0);
data.addValue(93500);
data.addLabel("Mar 03");
data.addValue(1160000);
data.addValue(440000);
data.addValue(19000);
data.addValue(0);
data.addValue(93000);
data.addLabel("Jun 03");
data.addValue(1260000);
data.addValue(445000);
data.addValue(21000);
data.addValue(0);
data.addValue(92500);
data.addLabel("Sep 03");
data.addValue(1350000);
data.addValue(476000);
data.addValue(20500);
data.addValue(0);
data.addValue(93000);
data.addLabel("Dec 03");
data.addValue(1476000);
data.addValue(486000);
data.addValue(18000);
data.addValue(0);
data.addValue(94000);
data.addLabel("Mar 04");
data.addValue(1530000);
data.addValue(522000);
data.addValue(17500);
data.addValue(0);
data.addValue(94500);
data.addLabel("Jun 04");
data.addValue(1620000);
data.addValue(540000);
data.addValue(16500);
data.addValue(0);
data.addValue(94000);
data.addLabel("Sep 04");
data.addValue(1746000);
data.addValue(558000);
data.addValue(16500);
data.addValue(0);
data.addValue(94500);
Image image = factory.createChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestLine04.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testLine05()
{
String pi = "" + '\u03C0';
ChartStyle style = new ChartStyle();
style.setChartType(ChartStyle.CHART_TYPE_LINE);
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setBarPaint(0, new Color(0.9451f, 0.1882f, 0.1059f));
style.setBarPaint(1, new Color(0.9843f, 0.5961f, 0.0667f));
style.setBarPaint(2, new Color(0.1882f, 0.7451f, 0.1059f));
style.setBarPaint(3, new Color(0.2f, 0.2f, 1.0f));
style.setBarPaint(4, new Color(0.9451f, 0.1059f, 0.9451f));
style.setBarPaint(5, new Color(0.8f, 0.8f, 0.0f));
style.setBarPaint(6, new Color(0.6f, 0.1f, 0.2f));
style.setBarPaint(7, new Color(0.0f, 0.4f, 0.1f));
style.setTitleFont(new Font("Dialog", Font.BOLD, 40));
ChartData data = new ChartData();
data.setTitle("y = F(x)");
data.addKeyLabel("y = sin(x) + 2");
data.addKeyLabel("y = cos(x) + 2");
data.addKeyLabel("y = sin(x + " + pi + ") + 2");
data.addKeyLabel("y = cos(x + " + pi + ") + 2");
data.addKeyLabel("y = 2sin(x) + 2");
data.addKeyLabel("y = 2cos(x) + 2");
data.addKeyLabel("y = 2sin(x + " + pi + ") + 2");
data.addKeyLabel("y = 2cos(x + " + pi + ") + 2");
double x;
for(int i=0; i<24; i++)
{
x = i * 0.27318 - Math.PI;
if(i == 0)
{
data.addLabel("-" + pi);
}
else if(i == 23)
{
data.addLabel("" + pi);
}
else
{
data.addLabel("");
}
data.addValue(Math.sin(x) + 2.0);
data.addValue(Math.cos(x) + 2.0);
data.addValue(Math.sin(x + Math.PI) + 2.0);
data.addValue(Math.cos(x + Math.PI) + 2.0);
data.addValue(2.0 * Math.sin(x) + 2.0);
data.addValue(2.0 * Math.cos(x) + 2.0);
data.addValue(2.0 * Math.sin(x + Math.PI) + 2.0);
data.addValue(2.0 * Math.cos(x + Math.PI) + 2.0);
}
Image image = factory.createChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestLine05.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testLine06()
{
ChartStyle style = new ChartStyle();
style.setPaint(ChartStyle.COLOR_WALL, new Color(0.7f, 0.7f, 1.0f, 0.7f));
try
{
ImageLayer layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage01.png").getPath()));
layer.setX(164);
layer.setY(138);
layer.setZ(ChartMetrics.Z_INDEX_BACKDROP - 1);
style.addLayer(layer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setShowPointMarks(true);
style.setBarPaint(0, new Color(0.9451f, 0.1882f, 0.1059f));
style.setBarPaint(1, new Color(0.9843f, 0.5961f, 0.0667f));
style.setBarPaint(2, new Color(0.1882f, 0.7451f, 0.1059f));
style.setBarPaint(3, new Color(0.2f, 0.2f, 1.0f));
style.setBarPaint(4, new Color(0.9451f, 0.1059f, 0.9451f));
style.setBarPaint(5, new Color(0.8f, 0.8f, 0.0f));
style.setBarPaint(6, new Color(0.6f, 0.1f, 0.2f));
style.setBarPaint(7, new Color(0.0f, 0.4f, 0.1f));
style.setTitleFont(new Font("Serif", Font.PLAIN, 40));
ChartData data = new ChartData();
data.setTitle("y = F(x)");
final char POW2 = '\u00B2';
final char POW3 = '\u00B3';
final char POW4 = '\u2074';
data.addKeyLabel("y = x" + POW2);
data.addKeyLabel("y = 2x" + POW2);
data.addKeyLabel("y = x" + POW2 + " / 2");
data.addKeyLabel("y = x" + POW4 + " / 100");
data.addKeyLabel("y = -(x" + POW2 + ") + 200");
data.addKeyLabel("y = -(2x" + POW2 + ") + 200");
data.addKeyLabel("y = (x" + POW2 + " / -2) + 200");
data.addKeyLabel("y = |x" + POW3 + "| / 5");
for(int i=-10; i<=10; i++)
{
data.addLabel("" + i);
data.addValue(i * i);
data.addValue(2.0 * i * i);
data.addValue(i * i / 2);
data.addValue(i * i * i * i / 100.0);
data.addValue(-1.0 * i * i + 200.0);
data.addValue(-2.0 * i * i + 200.0);
data.addValue(i * i / -2.0 + 200.0);
data.addValue(Math.abs(i * i * i) / 5.0);
}
Image image = factory.createLineChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestLine06.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testMultiRow01()
{
ChartStyle style = new ChartStyle();
style.setPaint(ChartStyle.COLOR_WALL, new Color(1.0f, 1.0f, 0.8f));
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setBarPaint(0, new Color(0.94f, 0.2f, 0.0f));
style.setBarPaint(1, new Color(0.5f, 0.7f, 0.94f));
ChartData data = new ChartData();
data.setTitle("Contaminants in Great Blue Heron Eggs (mg/kg)");
data.addKeyLabel("PCB");
data.addKeyLabel("DDE");
data.addLabel("1977");
data.addValue(7.3);
data.addValue(2.4);
data.addLabel("1982");
data.addValue(4.4);
data.addValue(1.4);
data.addLabel("1983");
data.addValue(1.6);
data.addValue(0.6);
data.addLabel("1985");
data.addValue(2.4);
data.addValue(1);
data.addLabel("1986");
data.addValue(1.1);
data.addValue(0.3);
data.addLabel("1987");
data.addValue(1.2);
data.addValue(0.5);
data.addLabel("1988");
data.addValue(1.3);
data.addValue(0.4);
data.addLabel("1989");
data.addValue(0.8);
data.addValue(0.5);
data.addLabel("1990");
data.addValue(1);
data.addValue(0.4);
data.addLabel("1991");
data.addValue(1.8);
data.addValue(0.8);
data.addLabel("1992");
data.addValue(1);
data.addValue(0.3);
data.addLabel("1993");
data.addValue(1.7);
data.addValue(1.6);
data.addLabel("1994");
data.addValue(1.9);
data.addValue(1);
data.addLabel("1996");
data.addValue(3.4);
data.addValue(0.9);
data.addLabel("1998");
data.addValue(0.9);
data.addValue(0.3);
data.addLabel("2000");
data.addValue(1.1);
data.addValue(0.4);
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestMultiRow01.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testMultiRow02()
{
ChartStyle style = new ChartStyle();
style.setPaint(ChartStyle.COLOR_WALL, new Color(0.7f, 0.7f, 1.0f, 0.7f));
try
{
ImageLayer layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage12.png").getPath()));
layer.setX(110);
layer.setY(10);
style.addLayer(layer);
layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage01.png").getPath()));
layer.setX(164);
layer.setY(136);
layer.setZ(ChartMetrics.Z_INDEX_BACKDROP - 1);
style.addLayer(layer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setBarPaint(0, new Color(1.0f, 0.39f, 0.39f));
style.setBarPaint(1, new Color(0.48f, 0.95f, 0.74f));
style.setBarPaint(2, new Color(0.97f, 0.95f, 0.74f));
ChartData data = new ChartData();
data.addKeyLabel("Budget");
data.addKeyLabel("Actual");
data.addKeyLabel("Variance");
data.addLabel("GM");
data.addValue(91000);
data.addValue(90000);
data.addValue(1000);
data.addLabel("CFO");
data.addValue(12000);
data.addValue(12000);
data.addValue(0);
data.addLabel("Legal");
data.addValue(8000);
data.addValue(7500);
data.addValue(500);
data.addLabel("R & D");
data.addValue(11500);
data.addValue(9500);
data.addValue(2000);
data.addLabel("MFG");
data.addValue(53000);
data.addValue(49000);
data.addValue(4000);
data.addLabel("QUAL");
data.addValue(2700);
data.addValue(2300);
data.addValue(400);
data.addLabel("INF");
data.addValue(30000);
data.addValue(26000);
data.addValue(4000);
data.addLabel("D & C");
data.addValue(5100);
data.addValue(3800);
data.addValue(1300);
data.addLabel("HR");
data.addValue(17000);
data.addValue(13500);
data.addValue(3500);
data.addLabel("PR");
data.addValue(21000);
data.addValue(18000);
data.addValue(3000);
data.addLabel("ENG");
data.addValue(35000);
data.addValue(32000);
data.addValue(3000);
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestMultiRow02.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testMultiRow03()
{
ChartStyle style = new ChartStyle();
style.setPaint(ChartStyle.COLOR_LABEL, new Color(0.20f, 0.35f, 0.64f));
try
{
ImageLayer layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage02.png").getPath()));
layer.setX(44);
layer.setY(20);
style.addLayer(layer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setBarPaint(0, new GradientPaint(320, 360, new Color(0.1f, 0.6f, 0.0f, 1.0f), 320, 115, new Color(0.4f, 0.9f, 0.3f, 0.9f)));
style.setBarPaint(1, new GradientPaint(320, 360, new Color(0.8f, 0.1f, 0.0f, 1.0f), 320, 115, new Color(1.0f, 0.4f, 0.3f, 0.9f)));
style.setBarPaint(2, new GradientPaint(320, 360, new Color(0.9f, 0.9f, 0.2f, 1.0f), 320, 115, new Color(1.0f, 1.0f, 0.4f, 0.9f)));
ChartData data = new ChartData();
data.addKeyLabel("Anderson Appreciation");
data.addKeyLabel("DCC Strategic Allocation Growth");
data.addKeyLabel("Richards Small-Cap Value");
data.addLabel("Dec 01");
data.addValue(16317);
data.addValue(5122);
data.addValue(7321);
data.addLabel("Mar 02");
data.addValue(15817);
data.addValue(5322);
data.addValue(7121);
data.addLabel("Jun 02");
data.addValue(15200);
data.addValue(6120);
data.addValue(7220);
data.addLabel("Sep 02");
data.addValue(16500);
data.addValue(6820);
data.addValue(7520);
data.addLabel("Dec 02");
data.addValue(17700);
data.addValue(7820);
data.addValue(7120);
data.addLabel("Mar 03");
data.addValue(18200);
data.addValue(9130);
data.addValue(7500);
data.addLabel("Jun 03");
data.addValue(18400);
data.addValue(12000);
data.addValue(8300);
data.addLabel("Sep 03");
data.addValue(14100);
data.addValue(13100);
data.addValue(9300);
data.addLabel("Dec 03");
data.addValue(15000);
data.addValue(13000);
data.addValue(9700);
data.addLabel("Mar 04");
data.addValue(16000);
data.addValue(15500);
data.addValue(11700);
data.addLabel("Jun 04");
data.addValue(16200);
data.addValue(17500);
data.addValue(12500);
data.addLabel("Sep 04");
data.addValue(14300);
data.addValue(19200);
data.addValue(15100);
data.addLabel("Dec 04");
data.addValue(13100);
data.addValue(19800);
data.addValue(17500);
data.addLabel("Mar 05");
data.addValue(11100);
data.addValue(20000);
data.addValue(19500);
data.addLabel("Jun 05");
data.addValue(12100);
data.addValue(19500);
data.addValue(21500);
data.addLabel("Sep 05");
data.addValue(15100);
data.addValue(22500);
data.addValue(22000);
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestMultiRow03.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testMultiRow04()
{
ChartStyle style = new ChartStyle();
try
{
ImageLayer layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage11.png").getPath()));
layer.setX(147);
layer.setY(424);
layer.setZ(ChartMetrics.Z_INDEX_BACKDROP + 1);
style.addLayer(layer);
layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage14.png").getPath()));
layer.setX(12);
layer.setY(180);
style.addLayer(layer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setBarPaint(0, new GradientPaint(560, 110, new Color(0.3f, 1.0f, 0.3f), 75, 340, new Color(0.0f, 0.5f, 0.0f)));
style.setBarPaint(1, new Color(0.9451f, 0.1882f, 0.1059f));
style.setBarPaint(2, new Color(0.9f, 0.9f, 0.2f));
ChartData data = new ChartData();
data.setTitle("Browser Trends for w3schools.com Visitors");
data.addKeyLabel("Internet Explorer");
data.addKeyLabel("Mozilla / Mozilla Firefox");
data.addKeyLabel("Opera");
data.addLabel("1/04");
data.addValue(84.1);
data.addValue(8.2);
data.addValue(2.1);
data.addLabel("2/04");
data.addValue(83);
data.addValue(9);
data.addValue(2.2);
data.addLabel("3/04");
data.addValue(82.8);
data.addValue(9.6);
data.addValue(2.1);
data.addLabel("4/04");
data.addValue(82.5);
data.addValue(10.3);
data.addValue(2.1);
data.addLabel("5/04");
data.addValue(81.8);
data.addValue(11);
data.addValue(2.2);
data.addLabel("6/04");
data.addValue(80.7);
data.addValue(11.8);
data.addValue(2.3);
data.addLabel("7/04");
data.addValue(78.7);
data.addValue(13.8);
data.addValue(2.3);
data.addLabel("8/04");
data.addValue(77.3);
data.addValue(15.5);
data.addValue(2.3);
data.addLabel("9/04");
data.addValue(75.8);
data.addValue(16.9);
data.addValue(2.3);
data.addLabel("10/04");
data.addValue(75.2);
data.addValue(17.5);
data.addValue(2.2);
data.addLabel("11/04");
data.addValue(73.5);
data.addValue(19.3);
data.addValue(2.2);
data.addLabel("12/04");
data.addValue(70.8);
data.addValue(21.3);
data.addValue(2.0);
data.addLabel("1/05");
data.addValue(69.7);
data.addValue(23.3);
data.addValue(1.9);
data.addLabel("2/05");
data.addValue(69);
data.addValue(26.6);
data.addValue(2.1);
data.addLabel("3/05");
data.addValue(67.7);
data.addValue(26.7);
data.addValue(1.8);
data.addLabel("4/05");
data.addValue(65.8);
data.addValue(28.5);
data.addValue(1.9);
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestMultiRow04.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testMultiRow05()
{
ChartStyle style = new ChartStyle();
style.setKeyType(ChartStyle.KEY_TYPE_HORIZONTAL_BAR_LABELS);
style.setBarPaint(0, new Color(0.2f, 0.9f, 0.1f, 0.8f));
style.setBarPaint(1, new Color(0.9f, 0.2f, 0.1f, 0.8f));
style.setBarPaint(2, new Color(1.0f, 1.0f, 0.2f, 0.8f));
try
{
ImageLayer layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage07.png").getPath()));
layer.setX(80);
layer.setY(404);
layer.setZ(ChartMetrics.Z_INDEX_BACKDROP + 1);
style.addLayer(layer);
layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage14.png").getPath()));
layer.setX(12);
layer.setY(180);
style.addLayer(layer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
ChartData data = new ChartData();
data.setTitle("Favored Development Platform for Free/Libre and Open Source Developers");
data.addKeyLabel("EU");
data.addKeyLabel("Japan");
data.addKeyLabel("Asia");
data.addLabel("Linux");
data.addValue(85.3);
data.addValue(50.6);
data.addValue(71.4);
data.addLabel("BSD");
data.addValue(6.6);
data.addValue(8.8);
data.addValue(8.3);
data.addLabel("Mac OS");
data.addValue(0.9);
data.addValue(5.2);
data.addValue(2.3);
data.addLabel("Windows");
data.addValue(2.2);
data.addValue(31.2);
data.addValue(15.0);
data.addLabel("Other");
data.addValue(5.0);
data.addValue(4.3);
data.addValue(3.0);
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestMultiRow05.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testMultiRow06()
{
ChartStyle style = new ChartStyle();
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setTitleFont(new Font("SansSerif", Font.PLAIN, 34));
style.setKeyFont(new Font("SansSerif", Font.PLAIN, 12));
style.setBarPaint(0, new GradientPaint(320, 120, new Color(0.2f, 0.9f, 0.1f, 0.7f), 320, 480, new Color(0.0f, 0.5f, 0.0f, 0.9f)));
style.setBarPaint(1, new GradientPaint(320, 120, new Color(0.4f, 0.4f, 1.0f, 0.7f), 320, 480, new Color(0.1f, 0.1f, 1.0f, 0.9f)));
style.setBarPaint(2, new GradientPaint(320, 120, new Color(1.0f, 0.4f, 0.2f, 0.7f), 320, 480, new Color(0.9f, 0.2f, 0.1f, 0.9f)));
ChartData data = new ChartData();
final char Ae = '\u0623';
final char A = '\u0627';
final char B = '\u0628';
final char e = '\u0629';
final char T = '\u062A';
final char J = '\u062C';
final char H = '\u062D';
final char D = '\u062F';
final char R = '\u0631';
final char S = '\u0633';
final char s = '\u0634';
final char X = '\u0635';
final char V = '\u0636';
final char U = '\u0637';
final char a = '\u0639';
final char G = '\u063A';
final char F = '\u0641';
final char Q = '\u0642';
final char K = '\u0643';
final char L = '\u0644';
final char M = '\u0645';
final char N = '\u0646';
final char W = '\u0648';
final char I = '\u064A';
final char N1 = '\u0661';
final char N2 = '\u0662';
final char N4 = '\u0664';
final char N6 = '\u0666';
final char N8 = '\u0668';
final char N9 = '\u0669';
data.setTitle("" + A+L+G+A+M + ' ' + M+V+A+V + ' ' + L+L+Ae+F+R+A+D);
data.addKeyLabel("" + B+U+N + ' ' + A+L+F+I+L);
data.addKeyLabel("" + A+F+N+D+M + ' ' + N9+N8+N1);
data.addKeyLabel("" + A+S+D + ' ' + F+I + ' ' + A+L+X+H+R+Ae);
data.addLabel("" + R+B+a+e);
data.addValue(430);
data.addValue(320);
data.addValue(20);
data.addLabel("" + M + ' ' + N4+N6);
data.addValue(340);
data.addValue(40);
data.addValue(0);
data.addLabel("" + U+L + ' ' + N9);
data.addValue(50);
data.addValue(30);
data.addValue(10);
data.addLabel("" + A+L+R+B+A+T);
data.addValue(10);
data.addValue(180);
data.addValue(70);
data.addLabel("" + B+L+B+I+S);
data.addValue(180);
data.addValue(50);
data.addValue(30);
data.addLabel("" + K+W+N+T+S);
data.addValue(80);
data.addValue(120);
data.addValue(20);
data.addLabel("" + A+B+W + ' ' + M);
data.addValue(140);
data.addValue(60);
data.addValue(40);
data.addLabel("" + M + ' ' + N1+N4);
data.addValue(80);
data.addValue(80);
data.addValue(90);
data.addLabel("" + U+N+T+e);
data.addValue(10);
data.addValue(300);
data.addValue(0);
data.addLabel("" + s+B+A+K);
data.addValue(10);
data.addValue(10);
data.addValue(0);
data.addLabel("" + U+L + ' ' + B+A+D+R);
data.addValue(30);
data.addValue(110);
data.addValue(40);
data.addLabel("" + M + ' ' + N2+N1);
data.addValue(0);
data.addValue(20);
data.addValue(0);
data.addLabel("" + U+L + ' ' + N4);
data.addValue(0);
data.addValue(20);
data.addValue(60);
data.addLabel("" + M+Q+H+e);
data.addValue(0);
data.addValue(240);
data.addValue(0);
data.addLabel("" + M+D+I+N+e);
data.addValue(130);
data.addValue(130);
data.addValue(0);
data.addLabel("" + A+B+W + ' ' + F);
data.addValue(70);
data.addValue(20);
data.addValue(0);
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestMultiRow06.png");
}
catch(Exception x)
{
x.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testMultiRow07()
{
ChartStyle style = new ChartStyle();
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setBarPaint(0, new GradientPaint(320, 360, new Color(0.1f, 0.6f, 0.0f, 1.0f), 320, 115, new Color(0.4f, 0.9f, 0.3f, 0.9f)));
style.setBarPaint(1, new GradientPaint(320, 360, new Color(0.8f, 0.1f, 0.0f, 1.0f), 320, 115, new Color(1.0f, 0.4f, 0.3f, 0.9f)));
style.setBarPaint(2, new GradientPaint(320, 360, new Color(0.4f, 0.4f, 1.0f, 1.0f), 320, 115, new Color(0.8f, 0.8f, 1.0f, 0.9f)));
style.setBarPaint(3, new GradientPaint(320, 360, new Color(0.9f, 0.9f, 0.2f, 1.0f), 320, 115, new Color(1.0f, 1.0f, 0.4f, 0.9f)));
TextLayer textLayer = new TextLayer("Source: Netcraft (www.netcraft.com)");
textLayer.setFont(new Font("SansSerif", Font.PLAIN, 12));
textLayer.setFontColor(Color.BLUE);
textLayer.setX(415);
textLayer.setY(455);
textLayer.setZ(ChartMetrics.Z_INDEX_TITLE + 1);
style.addLayer(textLayer);
final String labels[] =
{
"Jun 00", "Sep 00", "Dec 00", "Mar 01", "Jun 01", "Sep 01", "Dec 01", "Mar 02", "Jun 02",
"Sep 02", "Dec 02", "Mar 03", "Jun 03", "Sep 03", "Dec 03", "Mar 04", "Jun 04", "Sep 04",
"Dec 04"
};
final int values[] =
{
383000, 190000, 21000, 84000,
540000, 198000, 22500, 88000,
630000, 206000, 19500, 88500,
660000, 270000, 20000, 87000,
730000, 340000, 19000, 92000,
790000, 360000, 19500, 90000,
890000, 359000, 21000, 88000,
960000, 380000, 20500, 91000,
1080000, 430000, 21000, 92500,
1060000, 420000, 20000, 93000,
1080000, 415000, 18500, 93500,
1160000, 440000, 19000, 93000,
1260000, 445000, 21000, 92500,
1350000, 476000, 20500, 93000,
1476000, 486000, 18000, 94000,
1530000, 522000, 17500, 94500,
1620000, 540000, 16500, 94000,
1746000, 558000, 16500, 94500,
1850000, 560000, 16200, 95000,
};
ChartData data = new ChartData();
data.setTitle("Totals for Active Servers Across All Domains");
data.addKeyLabel("Apache");
data.addKeyLabel("Microsoft");
data.addKeyLabel("Sun");
data.addKeyLabel("Other");
for(int i=0; i<labels.length; i++)
{
data.addLabel(labels[i]);
data.addValue(values[i * 4]);
data.addValue(values[i * 4 + 1]);
data.addValue(values[i * 4 + 2]);
data.addValue(values[i * 4 + 3]);
}
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestMultiRow07.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testMultiRow08()
{
ChartStyle style = new ChartStyle();
style.setPaint(ChartStyle.COLOR_LABEL, new Color(0.20f, 0.35f, 0.64f));
try
{
ImageLayer layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage02.png").getPath()));
layer.setX(44);
layer.setY(20);
style.addLayer(layer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setBarPaint(0, new GradientPaint(320, 360, new Color(0.1f, 0.6f, 0.0f, 1.0f), 320, 115, new Color(0.4f, 0.9f, 0.3f, 0.9f)));
style.setBarPaint(1, new GradientPaint(320, 360, new Color(0.8f, 0.1f, 0.0f, 1.0f), 320, 115, new Color(1.0f, 0.4f, 0.3f, 0.9f)));
style.setBarPaint(2, new GradientPaint(320, 360, new Color(0.9f, 0.9f, 0.2f, 1.0f), 320, 115, new Color(1.0f, 1.0f, 0.4f, 0.9f)));
style.setBarPaint(3, new GradientPaint(320, 360, new Color(0.4f, 0.4f, 1.0f, 1.0f), 320, 115, new Color(0.8f, 0.8f, 1.0f, 0.9f)));
final String labels[] =
{
"Dec 01", "Mar 02", "Jun 02", "Sep 02", "Dec 02", "Mar 03", "Jun 03", "Sep 03",
"Dec 03", "Mar 04", "Jun 04", "Sep 04", "Dec 04", "Mar 05", "Jun 05", "Sep 05",
};
final int values[] =
{
16317, 5122, 7321, 2150,
15817, 5322, 7121, 2200,
15200, 6120, 7220, 2260,
16500, 6820, 7520, 2510,
17700, 7820, 7120, 2480,
18200, 9130, 7500, 2710,
18400, 12000, 8300, 2900,
14100, 13100, 9300, 3100,
15000, 13000, 9700, 3450,
16000, 15500, 11700, 3600,
16200, 17500, 12500, 3650,
14300, 19200, 15100, 3200,
13100, 19800, 17500, 3000,
11100, 20000, 19500, 2400,
12100, 19500, 21500, 2100,
15100, 22500, 22000, 1700,
};
ChartData data = new ChartData();
data.addKeyLabel("Anderson Appreciation");
data.addKeyLabel("DCC Strategic Allocation Growth");
data.addKeyLabel("Richards Small-Cap Value");
data.addKeyLabel("Grozny Venture Fund");
for(int i=0; i<labels.length; i++)
{
data.addLabel(labels[i]);
data.addValue(values[i * 4]);
data.addValue(values[i * 4 + 1]);
data.addValue(values[i * 4 + 2]);
data.addValue(values[i * 4 + 3]);
}
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestMultiRow08.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testMultiRow09()
{
ChartStyle style = new ChartStyle();
style.setKeyType(ChartStyle.KEY_TYPE_DIAGONAL_BAR_LABELS);
style.setPaint(ChartStyle.COLOR_EDGE, new Color(0.0f, 0.0f, 0.2f, 0.5f));
style.setPaint(ChartStyle.COLOR_WALL, new GradientPaint(250, 135, new Color(0.7f, 0.7f, 1.0f, 0.6f), 500, 270, new Color(0.6f, 0.6f, 1.0f, 0.6f)));
style.setValueLabelsEnabled(true);
style.setBarPaint(0, new Color(0.2f, 0.9f, 0.1f, 0.8f));
style.setBarPaint(1, new Color(1.0f, 1.0f, 0.2f, 0.8f));
try
{
ImageLayer titleLayer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage13.png").getPath()));
titleLayer.setX(140);
titleLayer.setY(16);
titleLayer.setZ(ChartMetrics.Z_INDEX_BACKDROP - 1);
style.addLayer(titleLayer);
ImageLayer watermarkLayer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage01.png").getPath()));
watermarkLayer.setX(155);
watermarkLayer.setY(178);
watermarkLayer.setZ(ChartMetrics.Z_INDEX_BACKDROP - 1);
style.addLayer(watermarkLayer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
ChartData data = new ChartData();
data.addKeyLabel("Assets");
data.addKeyLabel("Shareable Content Objects");
data.addLabel("2/05");
data.addValue(62);
data.addValue(72);
data.addLabel("3/05");
data.addValue(8);
data.addValue(12);
data.addLabel("4/05");
data.addValue(41);
data.addValue(12);
data.addLabel("5/05");
data.addValue(63);
data.addValue(8);
data.addLabel("6/05");
data.addValue(82);
data.addValue(7);
data.addLabel("7/05");
data.addValue(71);
data.addValue(17);
data.addLabel("8/05");
data.addValue(42);
data.addValue(9);
data.addLabel("9/05");
data.addValue(24);
data.addValue(33);
data.addLabel("10/05");
data.addValue(41);
data.addValue(21);
data.addLabel("11/05");
data.addValue(21);
data.addValue(7);
data.addLabel("12/05");
data.addValue(26);
data.addValue(17);
data.addLabel("1/06");
data.addValue(32);
data.addValue(24);
ChartFactory factory = ChartFactory.getInstance();
Image image = factory.createBarChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestMultiRow09.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testPie01()
{
ChartStyle style = new ChartStyle();
try
{
ImageLayer layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage09.png").getPath()));
layer.setX(230);
layer.setY(130);
layer.setZ(ChartMetrics.Z_INDEX_BACKDROP - 1);
style.addLayer(layer);
layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage04.png").getPath()));
layer.setX(20);
layer.setY(10);
layer.setZ(ChartMetrics.Z_INDEX_TITLE + 1);
style.addLayer(layer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
TextLayer textLayer = new TextLayer("Source: Netcraft (www.netcraft.com)");
textLayer.setFont(new Font("SansSerif", Font.PLAIN, 12));
textLayer.setFontColor(new Color(0.0f, 0.0f, 1.0f));
textLayer.setX(370);
textLayer.setY(430);
textLayer.setZ(ChartMetrics.Z_INDEX_TITLE + 1);
style.addLayer(textLayer);
ChartData data = new ChartData();
data.addPoint("Apache", 68.43);
data.addPoint("Microsoft", 20.86);
data.addPoint("Sun", 3.14);
data.addPoint("Zeus", 1.19);
for(int i=0; i<data.getTotalValues(); i++)
{
style.setBarPaint(i, Palette.setAlpha(style.getBarPaint(i), 0.6f));
}
Image image = factory.createPieChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestPie01.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testPie02()
{
ChartStyle style = new ChartStyle();
style.setChartType(ChartStyle.CHART_TYPE_PIE);
TextLayer layer = new TextLayer("Source: TechRepublic survey");
layer.setFont(new Font("SansSerif", Font.PLAIN, 12));
layer.setFontColor(new Color(0.5f, 0.0f, 0.0f));
layer.setX(425);
layer.setY(460);
layer.setZ(ChartMetrics.Z_INDEX_SLICES + 1);
style.addLayer(layer);
style.setPaint(ChartStyle.COLOR_LABEL, new Color(0.5f, 0.0f, 0.0f));
style.setPaint(ChartStyle.COLOR_SHADOW, new Color(0.95f, 0.85f, 0.85f));
style.setPaint(ChartStyle.COLOR_WALL, new Color(1.0f, 1.0f, 0.8f));
style.setPaint(ChartStyle.COLOR_EDGE, new Color(0.2f, 0.0f, 0.0f));
ChartData data = new ChartData();
data.setTitle("Most Influential Factors in Moving to Linux");
data.addPoint("Cost", 40.0);
data.addPoint("Ease of Implementation", 10.0);
data.addPoint("Ease of Training", 3.6);
data.addPoint("Reliability", 39.2);
data.addPoint("Scalability", 7.2);
for(int i=0; i<ChartStyle.MAX_BARS && i<data.getTotalValues(); i++)
{
style.setBarPaint(i, new GradientPaint(320, 315, Palette.brighten(style.getBarPaint(i), 3), 230, 75, (Color)style.getBarPaint(i)));
}
Image image = factory.createChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestPie02.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testPie03()
{
ChartStyle style = new ChartStyle();
style.setChartType(ChartStyle.CHART_TYPE_PIE);
style.setBorderEnabled(true);
ChartData data = new ChartData();
data.setTitle("Scottish Fishing Vessels by District, 1997");
data.addPoint("Aberdeen", 46);
data.addPoint("Arbroath", 72);
data.addPoint("Ayr", 181);
data.addPoint("Buckle", 151);
data.addPoint("Campbelltown", 190);
data.addPoint("Eyemouth", 125);
data.addPoint("Fraserburgh", 271);
data.addPoint("Kinlochbervie", 28);
data.addPoint("Lochinver", 32);
data.addPoint("Mallaig", 248);
data.addPoint("Oban", 175);
data.addPoint("Orkney", 206);
data.addPoint("Peterhead", 159);
data.addPoint("Pittenweem", 103);
data.addPoint("Shetland", 221);
data.addPoint("Stornoway", 353);
data.addPoint("Ullapool", 60);
data.addPoint("Wick", 142);
Image image = factory.createChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestPie03.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testPie04()
{
ChartStyle style = new ChartStyle();
style.setPaint(ChartStyle.COLOR_LABEL, new Color(0.5f, 0.0f, 0.0f));
style.setPaint(ChartStyle.COLOR_SHADOW, new Color(0.95f, 0.85f, 0.85f));
style.setPaint(ChartStyle.COLOR_EDGE, new Color(0.5f, 0.0f, 0.0f));
style.setLabelFont(new Font("TimesRoman", Font.PLAIN, 40));
style.setTitleFont(new Font("TimesRoman", Font.BOLD, 40));
ChartData data = new ChartData();
data.setTitle("Top SourceForge.net Downloads");
data.addPoint("eMule", 84619648);
data.addPoint("Azureus - BitTorrent Client", 36135722);
data.addPoint("BitTorrent", 31994567);
data.addPoint("CDex", 22181638);
data.addPoint("DC++", 20865622);
data.addPoint("VirtualDub", 17337162);
data.addPoint("ZSNES", 8339503);
data.addPoint("eMule Plus", 6031716);
data.addPoint("phpMyAdmin", 5953722);
data.addPoint("Dev-C++", 5617685);
data.addPoint("Gaim", 5425713);
data.addPoint("phpBB", 5318085);
data.addPoint("JBoss.org", 5118948);
data.addPoint("TightVNC", 4882808);
data.addPoint("ffdshow", 4585258);
data.addPoint("guliverkli", 4427596);
data.addPoint("Shareaza", 4231303);
data.addPoint("AFPL Ghostscript", 4064166);
data.addPoint("ABC [Yet Another Bittorrent Client", 3987273);
data.addPoint("Webmin", 3970738);
data.addPoint("Miranda", 3836720);
data.addPoint("FileZilla", 3686691);
data.addPoint("The CvsGui project", 3545563);
data.addPoint("7-Zip", 3523815);
data.addPoint("AC3Filter", 3251402);
data.addPoint("GnuWin32", 3080029);
data.addPoint("AMSN", 2974954);
data.addPoint("WinSCP", 2832310);
data.addPoint("FlasKMPEG", 2775972);
data.addPoint("VisualBoyAdvance", 2700694);
Image image = factory.createPieChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestPie04.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testPie05()
{
ChartStyle style = new ChartStyle();
style.setBarPaint(0, new GradientPaint(540, 240, new Color(1.0f, 1.0f, 0.5f), 240, 70, new Color(1.0f, 1.0f, 0.2f)));
style.setBarPaint(1, new Color(1.0f, 0.0f, 0.0f));
style.setBarPaint(2, new Color(0.1f, 0.0f, 1.0f));
style.setBarPaint(3, new Color(0.5f, 1.0f, 0.0f));
style.setBarPaint(4, new Color(0.8f, 0.8f, 0.3f));
style.setBarPaint(6, new Color(0.5f, 0.5f, 0.5f));
try
{
ImageLayer layer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage06.png").getPath()));
layer.setX(355);
layer.setY(110);
layer.setZ(ChartMetrics.Z_INDEX_SLICES + 1);
style.addLayer(layer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
ChartData data = new ChartData();
data.setTitle("Favored OS / Distribution of Free/Libre and Open Source Developers");
data.addPoint("Debian", 48.1);
data.addPoint("Red Hat", 13.8);
data.addPoint("Mandrake", 9.8);
data.addPoint("SuSE", 9.2);
data.addPoint("FreeBSD", 4.9);
data.addPoint("Slackware", 4.4);
data.addPoint("Windows", 2.2);
data.addPoint("OpenBSD", 1.3);
data.addPoint("MacOS", 1.0);
data.addPoint("BeOs", 0.9);
data.addPoint("Solaris", 0.5);
data.addPoint("NetBSD", 0.4);
data.addPoint("OS/2", 0.2);
data.addPoint("DOS", 0.1);
data.addPoint("Other", 3.2);
Image image = factory.createPieChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestPie05.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testPie06()
{
ChartStyle style = new ChartStyle();
style.setPaint(ChartStyle.COLOR_LABEL, new Color(1.0f, 1.0f, 0.2f));
style.setPaint(ChartStyle.COLOR_SHADOW, new Color(0.1f, 0.1f, 0.1f));
style.setPaint(ChartStyle.COLOR_BACKGROUND, new Color(0.0f, 0.0f, 0.0f));
style.setPaint(ChartStyle.COLOR_WALL, new Color(0.4f, 0.8f, 0.4f));
style.setPaint(ChartStyle.COLOR_EDGE, new Color(0.2f, 0.2f, 0.2f));
ChartData data = new ChartData();
data.setTitle("2004 distrowatch.com Average Page Hits per Day");
data.addPoint("Mandrake", 1457);
data.addPoint("Fedora", 1202);
data.addPoint("KNOPPIX", 910);
data.addPoint("SuSE", 858);
data.addPoint("Debian", 832);
data.addPoint("MEPIS", 694);
data.addPoint("Gentoo", 832);
data.addPoint("Slackware", 669);
data.addPoint("PCLinuxOS", 451);
data.addPoint("Damn Small", 416);
data.addPoint("Xandros", 367);
data.addPoint("Red Hat", 343);
data.addPoint("Ubuntu", 300);
data.addPoint("Vine", 290);
data.addPoint("FreeBSD", 290);
data.addPoint("SLAX", 263);
data.addPoint("Yoper", 242);
data.addPoint("Linspire", 226);
data.addPoint("Vector", 192);
data.addPoint("Gnoppix", 192);
data.addPoint("KANOTIX", 186);
data.addPoint("Arch", 180);
data.addPoint("Feather", 176);
data.addPoint("Lycoris", 175);
data.addPoint("Aurox", 162);
data.addPoint("Buffalo", 158);
data.addPoint("Turbolinux", 154);
data.addPoint("Libranet", 147);
data.addPoint("Mandows", 136);
data.addPoint("Onebase", 131);
Image image = factory.createPieChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestPie06.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public void testPie07()
{
ChartStyle style = new ChartStyle();
style.setChartType(ChartStyle.CHART_TYPE_PIE);
try
{
ImageLayer titleLayer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage02.png").getPath()));
titleLayer.setX(40);
titleLayer.setY(16);
titleLayer.setZ(ChartMetrics.Z_INDEX_BACKDROP - 1);
style.addLayer(titleLayer);
ImageLayer watermarkLayer = new ImageLayer(new URI("file://" + TestChartMetrics.class.getResource("/../test/TestImage01.png").getPath()));
watermarkLayer.setX(155);
watermarkLayer.setY(178);
watermarkLayer.setZ(ChartMetrics.Z_INDEX_BACKDROP - 1);
style.addLayer(watermarkLayer);
}
catch(URISyntaxException e)
{
e.printStackTrace(System.err);
fail("Unable to access the image URI: " + e);
}
TextLayer textLayer = new TextLayer("Updated " + new SimpleDateFormat("dd MMM yyyy").format(new Date()));
textLayer.setFont(new Font("SansSerif", Font.PLAIN, 10));
textLayer.setFontColor(new Color(0.0f, 0.0f, 0.7f));
textLayer.setX(510);
textLayer.setY(460);
textLayer.setZ(ChartMetrics.Z_INDEX_SLICES + 1);
style.addLayer(textLayer);
ChartData data = new ChartData();
data.addPoint("DCC Strategic Allocation Growth", 10000);
data.addPoint("Anderson Appreciation", 6000);
data.addPoint("Richards Small-Cap Value", 3700);
data.addPoint("Isokaze Pacific Rim Growth Fund", 2500);
data.addPoint("Genju Venture Fund", 2400);
style.setBarPaint(0, new GradientPaint(320, 315, new Color(0.4f, 1.0f, 0.4f, 0.6f), 230, 75, new Color(0.0f, 1.0f, 0.0f, 0.6f)));
style.setBarPaint(1, new GradientPaint(320, 315, new Color(0.4f, 0.4f, 1.0f, 0.6f), 230, 75, new Color(0.0f, 0.0f, 1.0f, 0.6f)));
style.setBarPaint(2, new GradientPaint(320, 315, new Color(1.0f, 0.4f, 0.4f, 0.6f), 230, 75, new Color(1.0f, 0.0f, 0.0f, 0.6f)));
style.setBarPaint(3, new GradientPaint(320, 315, new Color(1.0f, 1.0f, 0.4f, 0.6f), 230, 75, new Color(1.0f, 1.0f, 0.0f, 0.6f)));
style.setBarPaint(4, new GradientPaint(320, 315, new Color(0.9f, 0.4f, 1.0f, 0.6f), 230, 75, new Color(0.6f, 0.0f, 1.0f, 0.6f)));
ChartFactory factory = ChartFactory.getInstance();
Image image = factory.createChart(data, style);
try
{
factory.writeImage(image, "test/results/TestChartFactory_TestPie07.png");
}
catch(Exception e)
{
e.printStackTrace(System.err);
fail("Unable to write image");
}
}
public static void main(String[] args)
{
junit.textui.TestRunner.run(new TestSuite(TestChartFactory.class));
System.exit(0);
}
}
|