By default, the number of grid lines is always equal to the number of visible scale labels,
no matter whether a scale is automatic or not.
To specify what grid lines are visible or not, use the method
Grid.setVisibleLinesIndexes(int[] visibleLinesIndexes). This method takes an array of
integer number, each entry corresponding to an index ranging from 0 to the maximum number
of lines displayed minus 1.
If chart is vertical the indexes increase from top to bottom,
and if chart is horizontal, from left to right. For instance, if a vertical chart is displaying
a scale with 10 tick marks, and only the first, fifth and tenth grid lines from top to bottom
must be displayed, an array containing values 0, 4 and 9 has to be passed to the method above.
The following example only displays the second and third grid lines:
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); GraphSet graphSet=graph.getGraphSet(0); Grid grid=graphSet.getGrid(); grid.setEnabled(true); grid.setColor(Color.gray); int[] visibleLinesIndexes={1,2}; grid.setVisibleLinesIndexes(visibleLinesIndexes); String[] title={"The JetChart Library","Controlling grid lines 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(); } }