Chapter 4.
Developing a Chart in HTML
|
See TDGChartApplet.HTML for an example of using the charting applet. See TDGChartEditorApplet.HTML for an example of using the editor. |
|
At a minimum, your HTML file must use the applet instruction(s) to identify the Perspective for Java .CLASS file and .JAR file that will be used to develop your chart. Examples: |
|
<applet code="TDGChartEditorApplet.class" |
|
or |
|
<APPLET CODE="TDGChartApplet.class" |
|
or |
|
<param name="TDGSCRIPT" |
|
or |
|
<applet code="TDGChartApplet.class" archive="javaCHARTg.jar" |
|
You may use the UseSampleData property to display a simple bar chart using the sample data provided with Perspective for Java. The following example .HTML file displays a chart using this property: |
|
<html><head><title> |
|
Perspective for Java supports an HTML parameter (TDGSCRIPT) which allows any number of methods to be posted to the TDGChartApplet from HTML. HTML files may use any of the Properties described in Chapter 7 by using a "set" or "get" prefix in front of the property name. In addition to the Methods described in Chapter 8, these three methods ONLY work from within HTML (since they are not "true" Java methods): |
|
|
|
setDataSeries (list of numbers for series, separated by commas); |
|
|
setGroupLabelArray (list of strings for series labels, separated by commas); |
|
|
setSeriesLabelArray (list of strings for series labels, separated by commas); |
|
These methods are described in the following paragraphs: |
|
This method can be used to assign a list of numbers to one or more series in a chart. |
Syntax: |
setDataSeries (Value_1, Value_2, Value_3, ... Value_x ); |
|
Value_1,...Value_x : A list of values to be assign to sequential series in a chart |
Example: |
<html><head><title>TDGChartApplet Demonstration #1 |
|
This method can be used to assign a series of labels to one or more sequential groups in a chart. |
Syntax: |
setGroupLabelArray ("Label_1", "Label_2", "Label_3"... ); |
|
Label_1, Label_2, Label_3,...: A list of labels to be assigned to sequential groups in a chart |
Example: |
<html><head><title>TDGChartApplet Demonstration #1 |
|
This method can be used to assign a series of labels to one or more sequential series in a chart. |
Syntax: |
setSeriesLabelArray ("Label_1", "Label_2", "Label_3"... ); |
|
Label_1, Label_2, Label_3,...: A list of labels to be assigned to sequential series in a chart |
Example: |
<html><head><title>TDGChartApplet Demonstration #1</title> |
In addition to the setDataSeries(), setSeriesLabelArray(), setGroupLabelArray() methods described above, see Chapter 6 for additional information about including your data in a chart. |
How to Resize the Chart Frame?
|
The chart frame needs to be resized with the given object. The object can be obtained with the getFrame() method. The following example shows now to resize the chart frame: |
|
setRect (getFrame(),new Rectangle(-10391,-7422,20800,17600)); |
|
Note that the setBounds() method only works if you are using pure Java with a compiler and are placing the chart inside another element (like a window or a frame). From HTML, it would not have any affect at all. See Chapter 3 for details on the coordinate system that Perspective uses. Chapter 3 also includes examples of other rectangles that can be set. |
How to Size and Position the Legend Area?
|
Here is an example of setting the legend size and position: |
|
setRect (getLegendArea(),new Rectangle(-14180,-13600,25072,2063)); |
|
Note that the setBounds() method only works if you are using pure Java with a compiler and are placing the chart inside another element (like a window or a frame). From HTML, it would not have any affect at all. See Chapter 3 for details on the coordinate system that Perspective uses. Chapter 3 also includes examples of other rectangles that can be set. |
How to Set Font Size and Names?
|
Here are some examples of setting font size and name: |
|
setFontSizeVC (getDataText(),1000);setFontSizeVC(getFootnote(),1100); setFontSizeVC(getLegendText(),1100); setFontSizeVC(getO1Label(),1100); |
|
For each of these, however, you must turn the autofit parameter OFF, by inserting the appropriate autofit command before the size command, like this: |
|
setAutofit (getDataText(),false);setAutofit(getFootnote(),false); setAutofit(getLegendText(),false); setAutofit(getO1Label(),false); |
|
The following examples show how to set the font name: |
|
setFontName (getDataText(),"Helvetica");setFontName(getFootnote(),"Helvetica"); setFontName(getLegendText(),"Helvetica"); setFontName(getO1Label(),"Helvetica"); |
|
If you want examples of HTML, there is a very easy way! Run the TDGChartEditorApplet, move the chart around, etc. and then select "Save" from the menu item. The file that is saved is a text file; you can cut and paste anything from it into HTML (or, for that matter, into Java code). |