pie graph

Vertical Bar Graph API (Java Bean)

[ Bar Graph Home ] [ Buy Now ] [ Installing ] [ Using the Bar Graph API ] [ API Docs ] [ Demo's ]

Vertical Bar Graph API (Java Bean) v4.6
Using within an Application

The following is a guide to using the the Vertical Bar Graph library component within a Java Application.
( If you are using the IDE Borland JBuilder then please click here for more JBuilder specific instructions. )

 

Before beginning ensure that you have followed the instructions for installing ( see here ).

Adding the Vertical Bar Graph to an application involves the following steps:-

  1. Import the package
  2. Initialise the Vertical Bar Graph Java Bean
  3. Set the bean properties to provide the look and feel required
  4. Supply the data to be graphed to the java bean
  5. Add the bean object to a frame
  6. Make the frame visible

A complete Java Application performing all the above tasks can be found in the
./Demo-Applications/ directory ( see here ).


Import the package

Simply add the following statement at the beginning of the application:-

import com.jpowered.vbgraph.*;


Initialise the Vertical Bar Graph Java Bean

Creating an instance of the bean can be done in one of 2 ways:

Either instantiate a bean object with

vbargraph = (VerticalBarGraph)Beans.instantiate(null,"com.jpowered.vbgraph.VerticalBarGraph");

Or simply create an Object instance with

vbargraph = new VerticalBarGraph();


Set the bean properties to provide the look and feel required.

Almost every aspect of the graph can be defined and alterted by setting the properties of the Vertical Bar Graph Object. For the full range of functions and thier effect please see the
API Docs - VerticalBarGraph - set methods

The following is a sample piece of code which sets some of the properties:-
Setting these properties is entirely optional and if the any are not supplied the bean will
automatically calculate the values.

// Boolean
vbargraph.setThreed(true); // 3D
vbargraph.setGrid(true); // Grid
vbargraph.setAxis(true); // Axis
vbargraph.setYlabels(true); // Y Labels
vbargraph.setOutline(true); // Outline
vbargraph.setLegend(true); // Legend
vbargraph.setAutoscale(true); // Autoscale
vbargraph.setGradientfill(true); // Gradientfill


// Integer
vbargraph.setNrows(6); // Number of Rows
vbargraph.setNcols(6); // Number of Columns
vbargraph.setVspace(30); // Vertical Spacing
vbargraph.setBarwidth(15); // Bar Width
vbargraph.setDepth3d(15); // Depth of the 3D effect
vbargraph.setNdecplaces(0); // Number of decimal places to use when displaying number values
vbargraph.setLabelorientation("Up angle"); // Orientation of x-axis labels
vbargraph.setLabelsy(310); // Y position of x-axis labels
vbargraph.setLabelsy_offset(0); // Y offset of every 2nd x-axis label
vbargraph.setBar_spacing(5); // Gap between bars
vbargraph.setGridStyle("dotted"); // Grid Line Style

// Double
vbargraph.setChartscale(100); // Chart Scale
vbargraph.setChartstarty(0); // Chart Start Y value

// Font
vbargraph.setXlabel_font(new Font("Arial",Font.PLAIN,12)); // X Label font
vbargraph.setYlabel_font(new Font("Arial",Font.ITALIC,10)); // Y Label font
vbargraph.setPopupfont(new Font("Arial",Font.PLAIN,10)); // Popup font

// Colors
vbargraph.setGridcolor(new Color(50,50,50)); // Grid color
vbargraph.setAxiscolor(new Color(30,30,175)); // Axis color
vbargraph.setFloorcolor(new Color(100,100,100)); // Floor color
vbargraph.setBaroutlinecolor(new Color(0,0,0)); // Bar outline color
vbargraph.setLabelcolor(new Color(75,75,125)); // label color
vbargraph.setBackgroundcolor(new Color(255,255,255)); // Background color
vbargraph.setLegendbackground(new Color(240,240,240)); // Legend background color
vbargraph.setLegendborder(new Color(125,125,125)); // legend border color
vbargraph.setLegendtextcolor(new Color(50,50,50)); // legend text color
vbargraph.setPopupbgcolor(new Color(255,255,200)); // Popup bgcolor

// String
vbargraph.setPopup_pre("$"); // popup prefix symbol
vbargraph.setPopup_post(""); // popup post symbol
vbargraph.setYlabel_pre("$"); // y label prefix symbol
vbargraph.setYlabel_post(""); // y label post symbol
vbargraph.setThousandseparator(","); // thousand seperator

// Grid Properties
vbargraph.setGridbgcolor(new Color(238,238,255)); // Grid background color
vbargraph.setGridposition(new Point(60,300)); // Grid Position


// Legend
vbargraph.setLegendtitle("Product Range"); // Legend Title
vbargraph.setLegendposition(new Point(300,10)); // Legend Position
vbargraph.setLegendfont(new Font("Arial",Font.PLAIN,10)); // Legend font

// Main Title
vbargraph.setTitletext("Sales by Quarter"); // Title text
vbargraph.setTitlefont(new Font("Arial",Font.BOLD,18)); // Title font
vbargraph.setTitlecolor(new Color(130,130,180)); // Title color
vbargraph.setTitleposition(new Point(50,25)); // Title position

// X axis Title
vbargraph.setXtitletext("Year 2005"); // X axis Title text
vbargraph.setXtitlefont(new Font("Arial",Font.BOLD,16)); // X axis Title font
vbargraph.setXtitlecolor(new Color(130,130,180)); // X axis Title color
vbargraph.setXtitleposition(new Point(180,370)); // X axis Title position

// Y axis Title
vbargraph.setYtitletext("Sales Value"); // Y axis Title text
vbargraph.setYtitlefont(new Font("Arial",Font.BOLD,16)); // Y axis Title font
vbargraph.setYtitlecolor(new Color(130,130,180)); // Y axis Title color
vbargraph.setYtitleposition(new Point(2,130)); // Y axis Title position

// Other
vbargraph.setPopupcursor("Hand"); // Link / click cursor

// Series Data (see APIdocs - Seriesobject)
Seriesobject series_object = new Seriesobject();

series_object.setSeries1("#0A77A4,Product X,left");
series_object.setSeries2("#20B358,Product Y,left");
series_object.setSeries3("#F09004,Product Z,left");

vbargraph.setSeriesobj(series_object);

// X Axis Labels (see APIdocs - Xlabelobject)
Xlabelobject xaxislabels_object = new Xlabelobject();
xaxislabels_object.setXlabels("January,February,March,April,May,June");
vbargraph.setXlabelobj(xaxislabels_object);


// Add some Custom Text to the chart
// see APIdocs - Textobject
Textobject text_object = new Textobject();

text_object.setText1("Note:|70,80|Arial,B,12|#0000FF");
text_object.setText2("Product X launched in December 2004|70,95|Arial,N,12|#0088FF");
vbargraph.setTextobj(text_object);


Supply the data to be graphed to the java bean

Data is added to the Vertical Bar Graph by way of a data object -
see API Docs - Dataobject

First create a data object with the following statement:-

Dataobject data_object = new Dataobject();

Data is then added to the data object on a series by series basis. For each series the data values should be supplied as a comma seperated string. For example if there are 2 series of data each with 6 data values then the code would be:-

data_object.setSeries1("1000.0,2000.0,3000.0,4000.0,5000.0,6000.0");
data_object.setSeries2("1500.7,2500.3,3000.0,3200.0,2600.3,1700.2");

In practice the data values would be previously acquired from another data source or object
(eg. database).

Once the data object has been created the data is simply added to the Vertical Bar object with the following statement:-

vbargraph.setDataobj(data_object);

Each time this method is called the graph will be re-drawn with the new data supplied.

 


Add the bean object to a frame

If not previously done then create a frame on which the graph is to be displayed. This can be done like this:-

Frame f = new Frame();
f.setSize(505,425);
f.addWindowListener(new ApplicationWindowAdapter());
f.setLayout(null);

Next set the size of the vertical bar graph and add to the frame:-

vbargraph.setSize(480,400);
Dimension d = vbargraph.getSize();
vbargraph.setBounds(25,25,d.width, d.height);
f.add(vbargraph);


Make the frame visible

The final step is to make the frame (and hence the graph) visible. This is done with:-

f.setVisible(true);

 

A complete Java Application with all the above code can be found in the
./Demo-Applications/Application/ directory ( see here ).

 

Using the Vertical Bar Component within other Java apps (eg. JSP, Servlets, Applets etc) is a similar process to the above. Full working demo's (with source code) can be found in the ./Demo-Applications/ directory, see:-

./Demo-Applications/Applet/

./Demo-Applications/Application/

./Demo-Applications/JSP/

./Demo-Applications/Servlet/

 

 

 

 

 

 

 
[ Bar Graph Home ] [ Buy Now ] [ Installing ] [ Using the Bar Graph API ] [ API Docs ] [ Demo's ]

Bar Graph Home

Installing

Using the Bar Graph API

API Docs

Demo's