Rather than displaying a single-colored background, a chart can display a gradient effect to enhance presentation. The gradient effect is a
smooth variation between two colors, across the chart background. A chart context extends GenericGraph, which in turn is a subclass of
the GradientPanel class, an extension of JPanel. The GradientPanel class implements the gradient colors effect.
The following example displays a gradient effect ranging from yellow to blue, starting from top to bottom. The direction of the gradient
effect can be customized with the GradientPanel.setGradientOrientation(int orientation) method.
The area where the gradient effect is displayed can be the entire chart area or just the area delimited by the vertical and
horizontal axis. Use the method Graph.setGradientColorsArea(int gradientColorsArea) to set the gradient effect area.
import javax.swing.*; import java.awt.*; import com.jinsight.jetchart.*; public class Main extends JFrame { public Main() { Graph graph=new Graph(); graph.setGradientColors(Color.yellow,Color.blue); 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 gradient colors on the background"}; 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(); } }