Scales are found in charts developed with either the Graph class or the ScatterGraph class. However, the way Scale objects are accessed
is a bit different. Graph applications access a Scale instance through a GraphSet object, whereas ScatterGraph
applications have direct access to the horizontal and vertical scales.
By default the minimum, maximum and increment values of a scale are automatically calculated. The minimum and maximum values are calculated with
respect to the minimum and maximum values of all series belonging to a GraphSet or a ScatterGraph object, and the increment is calculated in such
a way that a scale labels do not overlap each other. If all series values are larger than or equal to zero, the minimum value is always
zero.
An automatic scale might not be suitable in certain conditions. For instance, if a line series is assigned values of large magnitude, and these values
do not vary intensively, a vertical chart displays a horizontal line next to the scale top and slightly jagged, in which case it is not possible to
distinguish and analyze data evolution. So, it is necessary to manually set scale properties, adjusting the minimum, maximum and increment values
to make the scale range suitable for visualizing data variation.
The example below displays an area series with large values ranging between 20000 and 20010. The scale was configured to facilitate data
visualization.
import javax.swing.*; import java.awt.*; import com.jinsight.jetchart.*; public class Main extends JFrame { public Main() { Graph graph=new Graph(new String[]{"l1","l2","l3","l4","l5","l6","l7","l8","l9"}); graph.setTitle(new String[]{"The JetChart Library","Configuring scales"}); double[] values={20007,20005,20006,20004,20003,20005,20007,20009,20006}; AreaSerie as=new AreaSerie(values,"Area series"); as.setColor(new Color(00,99,00)); GraphSet graphSet=graph.getGraphSet(0); Scale scale=graphSet.getScale(); // The maximum, minimum and increment values only can be configured if the // automatic scale is disabled. scale.setAutoScaleEnabled(false); scale.setMaxValue(20010); scale.setMinValue(20000); scale.setIncrement(2); scale.setValueFormat("##,###"); graphSet.getGrid().setEnabled(true); graphSet.getGrid().setColor(Color.gray); graphSet.getGrid().setStyle(Grid.DASHED); graph.addSerie(as); Container ct=getContentPane(); ct.add(graph); setSize(450,350); setVisible(true); } public static void main(String[] args) { new Main(); } }