Displaying the x axis labels and the grid

The labels are displayed along the x axis of charts created with the Graph class. They can be passed to the chart context as a parameter of the Graph class constructor or by using the Graph.setLabels(String[] labels) method.

The grid is made up of lines crossing the graph area, each line starting at a scale tick. The grid lines bring a better perception of data points positioning against respective scales.

The grid is an instance of the class com.jinsight.jetchart.Grid. A Grid object is only found in graphs created with Graph and ScatterGraph. When developing graphs with Graph, the grid can only be accessed through a GraphSet object, whereas ScatterGraph offers direct acess to the Grid object. There is one topic of this tutorial dedicated to explaining what GraphSet objects are. The example below sets the chart labels, gets a reference to the Grid object and sets its color to gray.

import javax.swing.*;
import java.awt.*;
import com.jinsight.jetchart.*;

public class Main extends JFrame {

   public Main() { 

        Graph graph=new Graph();
	
        String[] labels={"label1","label2","label3","label4"};
        graph.setLabels(labels);
		
        GraphSet graphSet=graph.getGraphSet(0);

        Grid grid=graphSet.getGrid();

        grid.setEnabled(true);
        grid.setColor(Color.gray);
	
        String[] title={"The JetChart Library","Displaying the x axis labels and the grid"};

        graph.setTitle(title);

        LeftTitle lt=graph.getLeftTitle();
        lt.setText("Left title");

        RightTitle rt=graph.getRightTitle();
        rt.setText("Right title");

        BottomTitle bt=graph.getBottomTitle();
        bt.setText("Bottom 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};
        ls.setValues(values1);

        BarSerie bs=new BarSerie();
        bs.setTitle("Bar series");
        bs.setColor(Color.blue);
        double[] values2={50,70,85,130};
        bs.setValues(values2);

        graph.addSerie(ls);
        graph.addSerie(bs);

        setSize(400,300);

        setVisible(true);


  }

  public static void main(String[] args) {
        new Main();
  }

}