Customizing scale labels

By default, the scale labels are numbers ranging between a minimum and maximum values, against which series data points are sequentially plotted. Scale labels can be customized using the method Scale.setLabels(String[] labels), in which case the numbers are fully replaced by the entries found in the 'labels' array.
The labels are passed as an array of strings, and they are placed from top to bottom or from left to right, if chart orientation is vertical or horizontal, respectively.

The example of the previous topic was modified to display customized labels, prefixing values with the US dollar sign. The method Scale.setValueFormat could be easily configured to insert a currency sign in the value pattern, however we are using the method Scale.setLabels for instructive purpose only.


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);
       
       String[] scaleLabels={"US$ 20010","US$ 20008","US$ 20006","US$ 20004",
                             "US$ 20002","US$ 20000"};

       scale.setLabels(scaleLabels);
       
       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();
  }

}