The examples presented so far and built on top of a Graph object display series plotted against only one scale.
A GraphSet is an object held by an instance of the Graph class, and is used to group series separately and display
them against multiple scales. These groups can have the start and end points of respective scales configured to stack series
one above the other. PieGraph and ScatterGraph do not support GraphSet objects.
GraphSet objects are classified as 'primary' and 'secondary'. Secondary GraphSet objects are those that have to be explicitily created and
are used for the purpose of displaying additional scales and grouping series separately. The primary GraphSet is internally created by
the Graph class to hold all series that are not grouped into secondary GraphSet objects.
In addition to keeping independent scales, each GraphSet contains a horizontal axis, two vertical axis, a wall, a scrolling bar, a grid and a series
base, which is a line drawn across the chart area to help distinguish the positive and negative chart regions.
Each GraphSet object is assigned an index. The primary GraphSet is always assigned the index '0'.
The following application plots two series, each one against a different scale, positioned along the left and right vertical axis. This
example also demonstrates the use of Scale objects, to which a topic of this tutorial is dedicated.
import javax.swing.*; import java.awt.*; import com.jinsight.jetchart.*; public class Main extends JFrame { public Main() { Graph graph=new Graph(); graph.setTitle(new String[]{"The JetChart Library","Working with graphsets"}); // Enables tooltips graph.getToolTip().setEnabled(true); double[] values1={.55,.43,.60,.80,.90,.30}; double[] values2={20000,15000,10000,30000,35000,25000}; BarSerie bs=new BarSerie(values1,"Bar series"); bs.setColor(Color.red); // Sets the format of values displayed in tooltips if mouse is // moved over data points of the bar series. bs.setValueFormat("## %"); LineSerie ls=new LineSerie(values2,"Line series"); ls.setColor(Color.blue); // Creates a secondary GraphSet object. GraphSet secondaryGraphSet=new GraphSet(); // Adds the GraphSet to the chart context. graph.addGraphSet(secondaryGraphSet); // Adds the bar series to the secondary GraphSet. secondaryGraphSet.addSerie(bs); // Sets the properties of the primary GraphSet scale. GraphSet primaryGraphSet=graph.getGraphSet(0); Scale primaryScale=primaryGraphSet.getScale(); primaryScale.setValueFormat("#,###"); primaryScale.setColor(Color.blue); // Sets the properties of the secondary GraphSet scale. Scale secondaryScale=secondaryGraphSet.getScale(); secondaryScale.setValueFormat("## %"); secondaryScale.setColor(Color.red); secondaryScale.setPosition(Scale.RIGHT); // The secondary scale position is set to right. // Enables each GraphSet grid, configuring one of them to display colored bands, // instead of horizontal lines, to help distinguish between both grids. Grid primaryGrid=primaryGraphSet.getGrid(); primaryGrid.setEnabled(true); primaryGrid.setColoredBandsEnabled(true); Grid secondaryGrid=secondaryGraphSet.getGrid(); secondaryGrid.setEnabled(true); secondaryGrid.setColor(Color.gray); // It is also necessary to add all series to the chart context. graph.addSerie(ls); graph.addSerie(bs); Container ct=getContentPane(); ct.add(graph); setSize(450,350); setVisible(true); } public static void main(String[] args) { new Main(); } }