The position of each label along the x axis of charts generated with the Graph class
is indexed from left to right, starting with 0.
For instance, if 5 labels are displayed, the leftmost label has index 0, and the rightmost
label has index 4. The visibility of each label can be toggled on/off using the method
Graph.setLabelsStatus(int[] labelsStatus). This method takes an array of integer values as
a sequence of binary digits, following the same sequence of the labels arranged along the x axis.
An array entry of '0' means that the corresponding label must not be displayed, whereas an entry
of '1' keeps the label visible.
There is another method that can be used to control labels visibility using a step value,
Graph.setLabelsStep(int labelsStep). The step value is sequentially added to the index of each
label to find the index of the next label to be displayed, starting from 0. For instance,
a step value of 5 applied to a sequence of 20 labels toggles on the labels with indexes
0,5,10,15,20. Intermediary labels are not painted. This method only has effect if automatic
label spacing is disabled with the method Graph.setAutoLabelSpacingEnabled(boolean isAutoLabelSpacingEnabled).
The example below specifies 5 labels out of 10 to be displayed, using the method setLabelsStatus. Only
labels l1, l3, l5, l7,and l9 are displayed.
import javax.swing.*; import java.awt.*; import com.jinsight.jetchart.*; public class Main extends JFrame { public Main() { Graph graph=new Graph(); String[] labels={"l1","l2","l3","l4","l5","l6","l7","l8","l9","l10"}; graph.setLabels(labels); int[] labelsStatus={1,0,1,0,1,0,1,0,1,0}; graph.setLabelsStatus(labelsStatus); GraphSet graphSet=graph.getGraphSet(0); Grid grid=graphSet.getGrid(); grid.setEnabled(true); grid.setColor(Color.gray); String[] title={"The JetChart Library","Controlling labels visibility"}; graph.setTitle(title); Container ct=getContentPane(); ct.add("Center",graph); LineSerie ls=new LineSerie(); ls.setTitle("Line series"); ls.setColor(Color.red); double[] values1={100,80,90,110,55,60,73,83,110,120}; ls.setValues(values1); graph.addSerie(ls); setSize(400,300); setVisible(true); } public static void main(String[] args) { new Main(); } }