A chart size and position can be dynamically adjusted by using mouse to drag or resize. To enable chart dragging and resizing, set the method GenericGraph.setDraggingEnabled(boolean isDraggingEnabled) to true.
To drag chart, move mouse cursor to any location within the chart area, click left button and drag. A blue outlined rectangle is displayed
to help select the new area the chart will be dropped on. After moving the blue rectangle to the desired area, release mouse button,
and the chart is repainted at the new location.
To resize chart, it is necessary to toggle between dragging and resizing states. To toggle chart state, double click mouse button at any location
within the chart area, then proceed as explained above. While in resizing state, the lower left corner of the outlined rectangle remains fixed,
whereas its vertical and horizontal dimensions changes.
import javax.swing.*; import java.awt.*; import com.jinsight.jetchart.*; public class Main extends JFrame { public Main() { Graph graph=new Graph(); graph.setDraggingEnabled(true); 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","Dragging and resizing a chart"}; 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(); } }