The Column Chart Application example.
This example produces a chart of fictitious Market indices for the 12 months of the year 2000. This example demonstrates many of the features of the Column Chart Bean including, multiple series, automatic legend generation, bespoke chart notes and the 3D effects.
The full source code for this example can be found in the ColumnchartApplication directory,
./ColumnchartApplication/ColumnchartApp.java
( Note : In order to run the application you will need to have at least the Java 2 runtime environment installed and the relevant classpath variables configured on your machine. Further information on this can be found at http://java.sun.com )
To run the application open up a command line window in the ./ColumnchartApplication directory and enter the following command,
> java ColumnchartApp
You should now see the application window open similar to the following,
Step 1 - Create the Basic Application Framework.
The first thing to do is to create a basic application framework which imports all the necessary classes and create a Window and Frame.
import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.beans.*; import java.util.*; import Sirius.columnchart.*; public class ColumnchartApp { public static void main(String args[]) { new ColumnchartApp(); } public ColumnchartApp() { Frame f = new Frame(); f.setSize(758,435); f.addWindowListener(new ApplicationWindowAdapter()); try { f.setLayout(null); } catch (Exception ex) { ex.printStackTrace(); } f.setVisible(true); } //----------------------------------------------------------------------------- class ApplicationWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } } //----------------------------------------------------------------------------- } // End application class
Step 2 - Add in and initialise the Columnchart Bean. In this step we declare the Columnchart object ( columnchart ) and create and instance of the Columnchart Bean. Following this the columnchart canvas is resized and then added to the frame f. import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.beans.*; import java.util.*; import Sirius.columnchart.*; public class ColumnchartApp { // Bean Object private Columnchart columnchart; public static void main(String args[]) { new ColumnchartApp(); } public ColumnchartApp() { Frame f = new Frame(); f.setSize(758,435); f.addWindowListener(new ApplicationWindowAdapter()); try { columnchart = (Columnchart)Beans.instantiate(null,"Sirius/columnchart/Columnchart"); f.setLayout(null); columnchart.setSize(750,420); Dimension d = columnchart.getSize(); columnchart.setBounds(5,22,d.width, d.height); f.add(columnchart); } catch (Exception ex) { ex.printStackTrace(); } f.setVisible(true); } //----------------------------------------------------------------------------- class ApplicationWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } } //----------------------------------------------------------------------------- } // End application class Step 3 - Create the Text data object and set this property of the Line Chart Bean. Pay particular attention to the set_textdata method. This is where the three elements of text are created and added to the text data object. Finally in this method the Textdata property of the Columnchart bean is set with the line, columnchart.setTextdata(textdata); import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.beans.*; import java.util.*; import Sirius.columnchart.*; public class ColumnchartApp { // Bean Object private Columnchart columnchart; // Data Objects private Vector textdata; // Text Objects public static void main(String args[]) { new ColumnchartApp(); } public ColumnchartApp() { Frame f = new Frame(); f.setSize(758,435); f.addWindowListener(new ApplicationWindowAdapter()); try { columnchart = (Columnchart)Beans.instantiate(null,"Sirius/columnchart/Columnchart"); set_textdata(); f.setLayout(null); columnchart.setSize(750,420); Dimension d = columnchart.getSize(); columnchart.setBounds(5,22,d.width, d.height); f.add(columnchart); } catch (Exception ex) { ex.printStackTrace(); } f.setVisible(true); } //----------------------------------------------------------------------------- // Create the text object // private void set_textdata() { textdata = new Vector(); textdata.addElement(new Textdata("Notes:", // Text line 1 new Color(255,255,255), // text color new Font("Courier",Font.BOLD,12), // text font new Point(45,60) // text position (x,y) )); textdata.addElement(new Textdata("Fictitious market indices", // Text line 2 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,72) // text position (x,y) )); textdata.addElement(new Textdata("for the year 2000.", // Text line 3 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,84) // text position (x,y) )); columnchart.setTextdata(textdata); } //----------------------------------------------------------------------------- class ApplicationWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } } //----------------------------------------------------------------------------- } // End application class Step 4 - Create the Title data object and set this property of the Line Chart Bean. Pay particular attention to the set_titledata method. This is where the three elements representing the titles are created and added to the title data object. Finally in this method the Titledata property of the Columnchart bean is set with the line, columnchart.setTitledata(textdata); import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.beans.*; import java.util.*; import Sirius.columnchart.*; public class ColumnchartApp { // Bean Object private Columnchart columnchart; // Data Objects private Vector textdata; // Text Objects private Vector titledata; // Title Objects public static void main(String args[]) { new ColumnchartApp(); } public ColumnchartApp() { Frame f = new Frame(); f.setSize(758,435); f.addWindowListener(new ApplicationWindowAdapter()); try { columnchart = (Columnchart)Beans.instantiate(null,"Sirius/columnchart/Columnchart"); set_textdata(); set_titledata(); f.setLayout(null); columnchart.setSize(750,420); Dimension d = columnchart.getSize(); columnchart.setBounds(5,22,d.width, d.height); f.add(columnchart); } catch (Exception ex) { ex.printStackTrace(); } f.setVisible(true); } //----------------------------------------------------------------------------- // Create the text object // private void set_textdata() { textdata = new Vector(); textdata.addElement(new Textdata("Notes:", // Text line 1 new Color(255,255,255), // text color new Font("Courier",Font.BOLD,12), // text font new Point(45,60) // text position (x,y) )); textdata.addElement(new Textdata("Fictitious market indices", // Text line 2 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,72) // text position (x,y) )); textdata.addElement(new Textdata("for the year 2000.", // Text line 3 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,84) // text position (x,y) )); columnchart.setTextdata(textdata); } //----------------------------------------------------------------------------- // Create the titledata object // private void set_titledata() { titledata = new Vector(); titledata = new Vector(); titledata.addElement(new Titledata("Market Indices",new Color(255,255,100),new Font("TimesRoman",Font.BOLD + Font.ITALIC,24),new Point(100,30))); titledata.addElement(new Titledata("Year 2000",new Color(0,255,255),new Font("TimesRoman",Font.ITALIC,18),new Point(200,405))); titledata.addElement(new Titledata("Index Value",new Color(0,255,255),new Font("TimesRoman",Font.ITALIC,18),new Point(5,375))); columnchart.setTitledata(titledata); } //----------------------------------------------------------------------------- class ApplicationWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } } //----------------------------------------------------------------------------- } // End application class Step 5 - Create the X axis Labels data object and set this property of the Line Chart Bean. Pay particular attention to the set_xlabelsdata method. Here the twelve labels representing the months of the year are created. Finally in this method the Xlabelsdata property of the Columnchart bean is set with the line, columnchart.setXlabelsdata(xlabelsdata); import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.beans.*; import java.util.*; import Sirius.columnchart.*; public class ColumnchartApp { // Bean Object private Columnchart columnchart; // Data Objects private Vector textdata; // Text Objects private Vector titledata; // Title Objects private Vector xlabelsdata; // X labels Objects public static void main(String args[]) { new ColumnchartApp(); } public ColumnchartApp() { Frame f = new Frame(); f.setSize(758,435); f.addWindowListener(new ApplicationWindowAdapter()); try { columnchart = (Columnchart)Beans.instantiate(null,"Sirius/columnchart/Columnchart"); set_textdata(); set_titledata(); set_xlabelsdata(); f.setLayout(null); columnchart.setSize(750,420); Dimension d = columnchart.getSize(); columnchart.setBounds(5,22,d.width, d.height); f.add(columnchart); } catch (Exception ex) { ex.printStackTrace(); } f.setVisible(true); } //----------------------------------------------------------------------------- // Create the text object // private void set_textdata() { textdata = new Vector(); textdata.addElement(new Textdata("Notes:", // Text line 1 new Color(255,255,255), // text color new Font("Courier",Font.BOLD,12), // text font new Point(45,60) // text position (x,y) )); textdata.addElement(new Textdata("Fictitious market indices", // Text line 2 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,72) // text position (x,y) )); textdata.addElement(new Textdata("for the year 2000.", // Text line 3 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,84) // text position (x,y) )); columnchart.setTextdata(textdata); } //----------------------------------------------------------------------------- // Create the titledata object // private void set_titledata() { titledata = new Vector(); titledata = new Vector(); titledata.addElement(new Titledata("Market Indices",new Color(255,255,100),new Font("TimesRoman",Font.BOLD + Font.ITALIC,24),new Point(100,30))); titledata.addElement(new Titledata("Year 2000",new Color(0,255,255),new Font("TimesRoman",Font.ITALIC,18),new Point(200,405))); titledata.addElement(new Titledata("Index Value",new Color(0,255,255),new Font("TimesRoman",Font.ITALIC,18),new Point(5,375))); columnchart.setTitledata(titledata); } //----------------------------------------------------------------------------- // Create the xlabels object // private void set_xlabelsdata() { xlabelsdata = new Vector(); xlabelsdata.addElement(new Xlabelsdata("January",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("February",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("March",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("April",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("May",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("June",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("July",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("August",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("September",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("October",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("November",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("December",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); columnchart.setXlabelsdata(xlabelsdata); } //----------------------------------------------------------------------------- class ApplicationWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } } //----------------------------------------------------------------------------- } // End application class Step 6 - Create the Y axis Labels data object and set this property of the Line Chart Bean. Pay particular attention to the set_ylabelsdata method. Only one element is added to this object and the bean will only ever use the first element. Finally in this method the Ylabelsdata property of the Columnchart bean is set with the line, columnchart.setYlabelsdata(ylabelsdata); import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.beans.*; import java.util.*; import Sirius.columnchart.*; public class ColumnchartApp { // Bean Object private Columnchart columnchart; // Data Objects private Vector textdata; // Text Objects private Vector titledata; // Title Objects private Vector xlabelsdata; // X labels Objects private Vector ylabelsdata; // Y labels Objects public static void main(String args[]) { new ColumnchartApp(); } public ColumnchartApp() { Frame f = new Frame(); f.setSize(758,435); f.addWindowListener(new ApplicationWindowAdapter()); try { columnchart = (Columnchart)Beans.instantiate(null,"Sirius/columnchart/Columnchart"); set_textdata(); set_titledata(); set_xlabelsdata(); set_ylabelsdata(); f.setLayout(null); columnchart.setSize(750,420); Dimension d = columnchart.getSize(); columnchart.setBounds(5,22,d.width, d.height); f.add(columnchart); } catch (Exception ex) { ex.printStackTrace(); } f.setVisible(true); } //----------------------------------------------------------------------------- // Create the text object // private void set_textdata() { textdata = new Vector(); textdata.addElement(new Textdata("Notes:", // Text line 1 new Color(255,255,255), // text color new Font("Courier",Font.BOLD,12), // text font new Point(45,60) // text position (x,y) )); textdata.addElement(new Textdata("Fictitious market indices", // Text line 2 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,72) // text position (x,y) )); textdata.addElement(new Textdata("for the year 2000.", // Text line 3 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,84) // text position (x,y) )); columnchart.setTextdata(textdata); } //----------------------------------------------------------------------------- // Create the titledata object // private void set_titledata() { titledata = new Vector(); titledata = new Vector(); titledata.addElement(new Titledata("Market Indices",new Color(255,255,100),new Font("TimesRoman",Font.BOLD + Font.ITALIC,24),new Point(100,30))); titledata.addElement(new Titledata("Year 2000",new Color(0,255,255),new Font("TimesRoman",Font.ITALIC,18),new Point(200,405))); titledata.addElement(new Titledata("Index Value",new Color(0,255,255),new Font("TimesRoman",Font.ITALIC,18),new Point(5,375))); columnchart.setTitledata(titledata); } //----------------------------------------------------------------------------- // Create the xlabels object // private void set_xlabelsdata() { xlabelsdata = new Vector(); xlabelsdata.addElement(new Xlabelsdata("January",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("February",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("March",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("April",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("May",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("June",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("July",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("August",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("September",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("October",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("November",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("December",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); columnchart.setXlabelsdata(xlabelsdata); } //----------------------------------------------------------------------------- // Create the ylabels data object // private void set_ylabelsdata() { ylabelsdata = new Vector(); ylabelsdata.addElement(new Ylabelsdata(new Color(100,255,255),new Font("Courier",Font.PLAIN,10))); columnchart.setYlabelsdata(ylabelsdata); } //----------------------------------------------------------------------------- class ApplicationWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } } //----------------------------------------------------------------------------- } // End application class Step 7 - Create the Column and Series data objects and set this property of the Column Chart Bean. Here we create the Column and Series data objects, notice how the Column data object becomes part of the series data object. Finally in this method the Seriesdata property of the Columnchart bean is set with the line, columnchart.setSeriesdata(seriesdata); import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.beans.*; import java.util.*; import Sirius.columnchart.*; public class ColumnchartApp { // Bean Object private Columnchart columnchart; // Data Objects private Vector textdata; // Text Objects private Vector titledata; // Title Objects private Vector xlabelsdata; // X labels Objects private Vector ylabelsdata; // Y labels Objects private Vector columndata; // Column data Objects private Vector seriesdata; // Series data Objects public static void main(String args[]) { new ColumnchartApp(); } public ColumnchartApp() { Frame f = new Frame(); f.setSize(758,435); f.addWindowListener(new ApplicationWindowAdapter()); try { columnchart = (Columnchart)Beans.instantiate(null,"Sirius/columnchart/Columnchart"); set_textdata(); set_titledata(); set_xlabelsdata(); set_ylabelsdata(); set_seriescolumndata(); f.setLayout(null); columnchart.setSize(750,420); Dimension d = columnchart.getSize(); columnchart.setBounds(5,22,d.width, d.height); f.add(columnchart); } catch (Exception ex) { ex.printStackTrace(); } f.setVisible(true); } //----------------------------------------------------------------------------- // Create the text object // private void set_textdata() { textdata = new Vector(); textdata.addElement(new Textdata("Notes:", // Text line 1 new Color(255,255,255), // text color new Font("Courier",Font.BOLD,12), // text font new Point(45,60) // text position (x,y) )); textdata.addElement(new Textdata("Fictitious market indices", // Text line 2 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,72) // text position (x,y) )); textdata.addElement(new Textdata("for the year 2000.", // Text line 3 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,84) // text position (x,y) )); columnchart.setTextdata(textdata); } //----------------------------------------------------------------------------- // Create the titledata object // private void set_titledata() { titledata = new Vector(); titledata = new Vector(); titledata.addElement(new Titledata("Market Indices",new Color(255,255,100),new Font("TimesRoman",Font.BOLD + Font.ITALIC,24),new Point(100,30))); titledata.addElement(new Titledata("Year 2000",new Color(0,255,255),new Font("TimesRoman",Font.ITALIC,18),new Point(200,405))); titledata.addElement(new Titledata("Index Value",new Color(0,255,255),new Font("TimesRoman",Font.ITALIC,18),new Point(5,375))); columnchart.setTitledata(titledata); } //----------------------------------------------------------------------------- // Create the xlabels object // private void set_xlabelsdata() { xlabelsdata = new Vector(); xlabelsdata.addElement(new Xlabelsdata("January",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("February",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("March",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("April",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("May",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("June",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("July",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("August",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("September",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("October",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("November",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("December",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); columnchart.setXlabelsdata(xlabelsdata); } //----------------------------------------------------------------------------- // Create the ylabels data object // private void set_ylabelsdata() { ylabelsdata = new Vector(); ylabelsdata.addElement(new Ylabelsdata(new Color(100,255,255),new Font("Courier",Font.PLAIN,10))); columnchart.setYlabelsdata(ylabelsdata); } //----------------------------------------------------------------------------- // Create the series and point objects // private void set_seriescolumndata() { seriesdata = new Vector(); // Series 1 columndata = new Vector(); columndata.addElement(new Pointdata(2420.45, false)); columndata.addElement(new Pointdata(2630.56, false)); columndata.addElement(new Pointdata(2700.90, true)); columndata.addElement(new Pointdata(2750.40, false)); columndata.addElement(new Pointdata(2450.20, false)); columndata.addElement(new Pointdata(2380.45, false)); columndata.addElement(new Pointdata(2230.56, true)); columndata.addElement(new Pointdata(2400.90, false)); columndata.addElement(new Pointdata(2450.45, false)); columndata.addElement(new Pointdata(2350.45, false)); columndata.addElement(new Pointdata(2320.56, false)); columndata.addElement(new Pointdata(2530.20, true)); seriesdata.addElement(new Seriesdata("Tech Sector", new Color(255,50,50), 1, columndata)); // Series 2 columndata = new Vector(); columndata.addElement(new Pointdata(2220.45, false)); columndata.addElement(new Pointdata(2180.56, false)); columndata.addElement(new Pointdata(2160.56, true)); columndata.addElement(new Pointdata(2165.40, false)); columndata.addElement(new Pointdata(2230.20, false)); columndata.addElement(new Pointdata(2250.87, false)); columndata.addElement(new Pointdata(2267.15, false)); columndata.addElement(new Pointdata(2305.91, false)); columndata.addElement(new Pointdata(2330.12, true)); columndata.addElement(new Pointdata(2300.63, false)); columndata.addElement(new Pointdata(2290.54, false)); columndata.addElement(new Pointdata(2250.74, false)); seriesdata.addElement(new Seriesdata("Banks", new Color(255,0,255), 2, columndata)); // Series 3 columndata = new Vector(); columndata.addElement(new Pointdata(2000.44, false)); columndata.addElement(new Pointdata(2050.51, false)); columndata.addElement(new Pointdata(2075.41, false)); columndata.addElement(new Pointdata(2040.32, false)); columndata.addElement(new Pointdata(2010.41, false)); columndata.addElement(new Pointdata(2085.11, true)); columndata.addElement(new Pointdata(2007.44, false)); columndata.addElement(new Pointdata(2020.22, false)); columndata.addElement(new Pointdata(2020.21, false)); columndata.addElement(new Pointdata(2040.65, false)); columndata.addElement(new Pointdata(2069.33, false)); columndata.addElement(new Pointdata(2210.51, true)); seriesdata.addElement(new Seriesdata("Oil", new Color(50,255,50), 0, columndata)); columnchart.setSeriesdata(seriesdata); } //----------------------------------------------------------------------------- class ApplicationWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } } //----------------------------------------------------------------------------- } // End application class Step 8 - Create the Legend data object and set this property of the Line Chart Bean. Here we create the Legend data object with the method set_legenddata(). Finally in this method the Seriesdata property of the Columnchart bean is set with the line, columnchart.setLegenddata(legenddata); import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.beans.*; import java.util.*; import Sirius.columnchart.*; public class ColumnchartApp { // Bean Object private Columnchart columnchart; // Data Objects private Vector textdata; // Text Objects private Vector titledata; // Title Objects private Vector xlabelsdata; // X labels Objects private Vector ylabelsdata; // Y labels Objects private Vector columndata; // Column data Objects private Vector seriesdata; // Series data Objects private Vector legenddata; // Legend Properties public static void main(String args[]) { new ColumnchartApp(); } public ColumnchartApp() { Frame f = new Frame(); f.setSize(758,435); f.addWindowListener(new ApplicationWindowAdapter()); try { columnchart = (Columnchart)Beans.instantiate(null,"Sirius/columnchart/Columnchart"); set_textdata(); set_titledata(); set_xlabelsdata(); set_ylabelsdata(); set_seriescolumndata(); set_legenddata(); f.setLayout(null); columnchart.setSize(750,420); Dimension d = columnchart.getSize(); columnchart.setBounds(5,22,d.width, d.height); f.add(columnchart); } catch (Exception ex) { ex.printStackTrace(); } f.setVisible(true); } //----------------------------------------------------------------------------- // Create the text object // private void set_textdata() { textdata = new Vector(); textdata.addElement(new Textdata("Notes:", // Text line 1 new Color(255,255,255), // text color new Font("Courier",Font.BOLD,12), // text font new Point(45,60) // text position (x,y) )); textdata.addElement(new Textdata("Fictitious market indices", // Text line 2 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,72) // text position (x,y) )); textdata.addElement(new Textdata("for the year 2000.", // Text line 3 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,84) // text position (x,y) )); columnchart.setTextdata(textdata); } //----------------------------------------------------------------------------- // Create the titledata object // private void set_titledata() { titledata = new Vector(); titledata = new Vector(); titledata.addElement(new Titledata("Market Indices",new Color(255,255,100),new Font("TimesRoman",Font.BOLD + Font.ITALIC,24),new Point(100,30))); titledata.addElement(new Titledata("Year 2000",new Color(0,255,255),new Font("TimesRoman",Font.ITALIC,18),new Point(200,405))); titledata.addElement(new Titledata("Index Value",new Color(0,255,255),new Font("TimesRoman",Font.ITALIC,18),new Point(5,375))); columnchart.setTitledata(titledata); } //----------------------------------------------------------------------------- // Create the xlabels object // private void set_xlabelsdata() { xlabelsdata = new Vector(); xlabelsdata.addElement(new Xlabelsdata("January",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("February",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("March",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("April",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("May",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("June",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("July",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("August",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("September",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("October",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("November",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("December",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); columnchart.setXlabelsdata(xlabelsdata); } //----------------------------------------------------------------------------- // Create the ylabels data object // private void set_ylabelsdata() { ylabelsdata = new Vector(); ylabelsdata.addElement(new Ylabelsdata(new Color(100,255,255),new Font("Courier",Font.PLAIN,10))); columnchart.setYlabelsdata(ylabelsdata); } //----------------------------------------------------------------------------- // Create the series and point objects // private void set_seriescolumndata() { seriesdata = new Vector(); // Series 1 columndata = new Vector(); columndata.addElement(new Pointdata(2420.45, false)); columndata.addElement(new Pointdata(2630.56, false)); columndata.addElement(new Pointdata(2700.90, true)); columndata.addElement(new Pointdata(2750.40, false)); columndata.addElement(new Pointdata(2450.20, false)); columndata.addElement(new Pointdata(2380.45, false)); columndata.addElement(new Pointdata(2230.56, true)); columndata.addElement(new Pointdata(2400.90, false)); columndata.addElement(new Pointdata(2450.45, false)); columndata.addElement(new Pointdata(2350.45, false)); columndata.addElement(new Pointdata(2320.56, false)); columndata.addElement(new Pointdata(2530.20, true)); seriesdata.addElement(new Seriesdata("Tech Sector", new Color(255,50,50), 1, columndata)); // Series 2 columndata = new Vector(); columndata.addElement(new Pointdata(2220.45, false)); columndata.addElement(new Pointdata(2180.56, false)); columndata.addElement(new Pointdata(2160.56, true)); columndata.addElement(new Pointdata(2165.40, false)); columndata.addElement(new Pointdata(2230.20, false)); columndata.addElement(new Pointdata(2250.87, false)); columndata.addElement(new Pointdata(2267.15, false)); columndata.addElement(new Pointdata(2305.91, false)); columndata.addElement(new Pointdata(2330.12, true)); columndata.addElement(new Pointdata(2300.63, false)); columndata.addElement(new Pointdata(2290.54, false)); columndata.addElement(new Pointdata(2250.74, false)); seriesdata.addElement(new Seriesdata("Banks", new Color(255,0,255), 2, columndata)); // Series 3 columndata = new Vector(); columndata.addElement(new Pointdata(2000.44, false)); columndata.addElement(new Pointdata(2050.51, false)); columndata.addElement(new Pointdata(2075.41, false)); columndata.addElement(new Pointdata(2040.32, false)); columndata.addElement(new Pointdata(2010.41, false)); columndata.addElement(new Pointdata(2085.11, true)); columndata.addElement(new Pointdata(2007.44, false)); columndata.addElement(new Pointdata(2020.22, false)); columndata.addElement(new Pointdata(2020.21, false)); columndata.addElement(new Pointdata(2040.65, false)); columndata.addElement(new Pointdata(2069.33, false)); columndata.addElement(new Pointdata(2210.51, true)); seriesdata.addElement(new Seriesdata("Oil", new Color(50,255,50), 0, columndata)); columnchart.setSeriesdata(seriesdata); } //----------------------------------------------------------------------------- // Create the legenddata object // private void set_legenddata() { legenddata = new Vector(); legenddata.addElement(new Legenddata("Indices", // Legend title new Color(200,200,200), // Legend text color new Font("Courier",Font.PLAIN,12), // Legend text font new Point(300,60) // Legend top-left position (x,y) )); columnchart.setLegenddata(legenddata); } //----------------------------------------------------------------------------- class ApplicationWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } } //----------------------------------------------------------------------------- } // End application class Step 9 - Create the Chart data object and set this property of the Line Chart Bean. Here we create Chart data object with the method set_chartdata(). Finally in this method the Seriesdata property of the Columnchart bean is set with the line, columnchart.setChartdata(chartdata); import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.beans.*; import java.util.*; import Sirius.columnchart.*; public class ColumnchartApp { // Bean Object private Columnchart columnchart; // Data Objects private Vector textdata; // Text Objects private Vector titledata; // Title Objects private Vector xlabelsdata; // X labels Objects private Vector ylabelsdata; // Y labels Objects private Vector columndata; // Column data Objects private Vector seriesdata; // Series data Objects private Vector legenddata; // Legend Properties private Vector chartdata; // Chart Properties Object public static void main(String args[]) { new ColumnchartApp(); } public ColumnchartApp() { Frame f = new Frame(); f.setSize(758,435); f.addWindowListener(new ApplicationWindowAdapter()); try { columnchart = (Columnchart)Beans.instantiate(null,"Sirius/columnchart/Columnchart"); set_textdata(); set_titledata(); set_xlabelsdata(); set_ylabelsdata(); set_seriescolumndata(); set_legenddata(); set_chartdata(); f.setLayout(null); columnchart.setSize(750,420); Dimension d = columnchart.getSize(); columnchart.setBounds(5,22,d.width, d.height); f.add(columnchart); } catch (Exception ex) { ex.printStackTrace(); } f.setVisible(true); } //----------------------------------------------------------------------------- // Create the text object // private void set_textdata() { textdata = new Vector(); textdata.addElement(new Textdata("Notes:", // Text line 1 new Color(255,255,255), // text color new Font("Courier",Font.BOLD,12), // text font new Point(45,60) // text position (x,y) )); textdata.addElement(new Textdata("Fictitious market indices", // Text line 2 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,72) // text position (x,y) )); textdata.addElement(new Textdata("for the year 2000.", // Text line 3 new Color(255,255,255), // text color new Font("Courier",Font.PLAIN,12), // text font new Point(50,84) // text position (x,y) )); columnchart.setTextdata(textdata); } //----------------------------------------------------------------------------- // Create the titledata object // private void set_titledata() { titledata = new Vector(); titledata = new Vector(); titledata.addElement(new Titledata("Market Indices",new Color(255,255,100),new Font("TimesRoman",Font.BOLD + Font.ITALIC,24),new Point(100,30))); titledata.addElement(new Titledata("Year 2000",new Color(0,255,255),new Font("TimesRoman",Font.ITALIC,18),new Point(200,405))); titledata.addElement(new Titledata("Index Value",new Color(0,255,255),new Font("TimesRoman",Font.ITALIC,18),new Point(5,375))); columnchart.setTitledata(titledata); } //----------------------------------------------------------------------------- // Create the xlabels object // private void set_xlabelsdata() { xlabelsdata = new Vector(); xlabelsdata.addElement(new Xlabelsdata("January",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("February",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("March",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("April",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("May",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("June",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("July",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("August",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("September",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("October",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); xlabelsdata.addElement(new Xlabelsdata("November",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 365, 0)); xlabelsdata.addElement(new Xlabelsdata("December",new Color(0,255,255),new Font("Courier",Font.PLAIN,10), 375, 0)); columnchart.setXlabelsdata(xlabelsdata); } //----------------------------------------------------------------------------- // Create the ylabels data object // private void set_ylabelsdata() { ylabelsdata = new Vector(); ylabelsdata.addElement(new Ylabelsdata(new Color(100,255,255),new Font("Courier",Font.PLAIN,10))); columnchart.setYlabelsdata(ylabelsdata); } //----------------------------------------------------------------------------- // Create the series and point objects // private void set_seriescolumndata() { seriesdata = new Vector(); // Series 1 columndata = new Vector(); columndata.addElement(new Pointdata(2420.45, false)); columndata.addElement(new Pointdata(2630.56, false)); columndata.addElement(new Pointdata(2700.90, true)); columndata.addElement(new Pointdata(2750.40, false)); columndata.addElement(new Pointdata(2450.20, false)); columndata.addElement(new Pointdata(2380.45, false)); columndata.addElement(new Pointdata(2230.56, true)); columndata.addElement(new Pointdata(2400.90, false)); columndata.addElement(new Pointdata(2450.45, false)); columndata.addElement(new Pointdata(2350.45, false)); columndata.addElement(new Pointdata(2320.56, false)); columndata.addElement(new Pointdata(2530.20, true)); seriesdata.addElement(new Seriesdata("Tech Sector", new Color(255,50,50), 1, columndata)); // Series 2 columndata = new Vector(); columndata.addElement(new Pointdata(2220.45, false)); columndata.addElement(new Pointdata(2180.56, false)); columndata.addElement(new Pointdata(2160.56, true)); columndata.addElement(new Pointdata(2165.40, false)); columndata.addElement(new Pointdata(2230.20, false)); columndata.addElement(new Pointdata(2250.87, false)); columndata.addElement(new Pointdata(2267.15, false)); columndata.addElement(new Pointdata(2305.91, false)); columndata.addElement(new Pointdata(2330.12, true)); columndata.addElement(new Pointdata(2300.63, false)); columndata.addElement(new Pointdata(2290.54, false)); columndata.addElement(new Pointdata(2250.74, false)); seriesdata.addElement(new Seriesdata("Banks", new Color(255,0,255), 2, columndata)); // Series 3 columndata = new Vector(); columndata.addElement(new Pointdata(2000.44, false)); columndata.addElement(new Pointdata(2050.51, false)); columndata.addElement(new Pointdata(2075.41, false)); columndata.addElement(new Pointdata(2040.32, false)); columndata.addElement(new Pointdata(2010.41, false)); columndata.addElement(new Pointdata(2085.11, true)); columndata.addElement(new Pointdata(2007.44, false)); columndata.addElement(new Pointdata(2020.22, false)); columndata.addElement(new Pointdata(2020.21, false)); columndata.addElement(new Pointdata(2040.65, false)); columndata.addElement(new Pointdata(2069.33, false)); columndata.addElement(new Pointdata(2210.51, true)); seriesdata.addElement(new Seriesdata("Oil", new Color(50,255,50), 0, columndata)); columnchart.setSeriesdata(seriesdata); } //----------------------------------------------------------------------------- // Create the legenddata object // private void set_legenddata() { legenddata = new Vector(); legenddata.addElement(new Legenddata("Indices", // Legend title new Color(200,200,200), // Legend text color new Font("Courier",Font.PLAIN,12), // Legend text font new Point(300,60) // Legend top-left position (x,y) )); columnchart.setLegenddata(legenddata); } //----------------------------------------------------------------------------- // Create the chartdata object // private void set_chartdata() { chartdata = new Vector(); chartdata.addElement(new Chartdata(true, // threeD true, // grid true, // axis true, // ylabels true, // outline true, // legend 750, // width 420, // height 12, // number of points, 7, // number of nrows, 30, // vertical spacing, 3, // number of series, 50, // horizontal spacing, 75, // gridxpos, 350, // gridypos, 15, // depth3D, 2, // ndecplaces, 10, // Column width 100, // chartScale, 2000, // chartStartY, new Color(175,175,175), // gridColor, new Color(255,255,255), // axisColor, new Color(100,100,100), // floorColor, new Color(255,255,255), // labelColor, new Color(0,0,0), // backgroundColor new Color(0,0,0) // Outline Color )); columnchart.setChartdata(chartdata); } //----------------------------------------------------------------------------- class ApplicationWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } } //----------------------------------------------------------------------------- } // End application class
Summary
In order to generate the line chart within an application a simple application
framework was created, an instance of the columnchart bean was created and finally
the data objects were created and the corresponding bean properties set.