JFreeChart Bubble Chart Example

Chapter: JFreeChart Last Updated: 03-08-2016 19:39:37 UTC

Program:

            /* ............... START ............... */
                
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.xy.DefaultXYZDataset;
import org.jfree.data.xy.XYZDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class JavaJFreeChartBubbleChart extends ApplicationFrame {

	public JavaJFreeChartBubbleChart(String s) {
		super(s);
		JPanel jpanel = createDemoPanel();
		jpanel.setPreferredSize(new Dimension(560, 370));
		setContentPane(jpanel);
	}

	private static JFreeChart createChart(XYZDataset xyzdataset) {
		JFreeChart jfreechart = ChartFactory.createBubbleChart("AGE vs WEIGHT vs WORK", "Weight", "AGE", xyzdataset,
				PlotOrientation.HORIZONTAL, true, true, false);

		XYPlot xyplot = (XYPlot) jfreechart.getPlot();
		xyplot.setForegroundAlpha(0.65F);
		XYItemRenderer xyitemrenderer = xyplot.getRenderer();
		xyitemrenderer.setSeriesPaint(0, Color.blue);
		NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
		numberaxis.setLowerMargin(0.2);
		numberaxis.setUpperMargin(0.5);
		NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
		numberaxis1.setLowerMargin(0.8);
		numberaxis1.setUpperMargin(0.9);

		return jfreechart;
	}

	public static XYZDataset createDataset() {
		DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset();

		double ad[] = { 30, 40, 50, 60, 70, 80 };
		double ad1[] = { 10, 20, 30, 40, 50, 60 };
		double ad2[] = { 4, 5, 10, 8, 9, 6 };
		double ad3[][] = { ad, ad1, ad2 };
		defaultxyzdataset.addSeries("Series 1", ad3);

		return defaultxyzdataset;
	}

	public static JPanel createDemoPanel() {
		JFreeChart jfreechart = createChart(createDataset());
		ChartPanel chartpanel = new ChartPanel(jfreechart);

		chartpanel.setDomainZoomable(true);
		chartpanel.setRangeZoomable(true);

		return chartpanel;
	}

	public static void main(String args[]) {
		JavaJFreeChartBubbleChart bubblechart = new JavaJFreeChartBubbleChart("Bubble Chart_frame");

		bubblechart.pack();
		RefineryUtilities.centerFrameOnScreen(bubblechart);
		bubblechart.setVisible(true);
	}
}
                /* ............... END ............... */
        

Output


JFreeChart Bubble Chart Example

Notes:

  • A bubble chart displays information in three-dimensional way. A bubble is plotted at the place where (x, y) coordinate intersect. The size of the bubble is considered as range or quantity of X and Y axis.

Tags

JFreeChart Bubble Chart, Java, JFreeChart

Similar Programs Chapter Last Updated
JFreeChart Scatter Chart JFreeChart 20-10-2017
JFreeChart XY Step Chart JFreeChart 10-06-2017
JFreeChart Wafer Map Chart JFreeChart 10-06-2017
JFreeChart XY Step Area Chart JFreeChart 10-06-2017
JFreeChart BarChart Color Customise JFreeChart 14-10-2016
JFreeChart Bar Chart 3D Example JFreeChart 05-08-2016
JFreeChart Bar Chart 3D Horizontal JFreeChart 05-08-2016
JFreeChart Area Chart Example JFreeChart 05-08-2016
JFreeChart XY Chart Example JFreeChart 03-08-2016
JFreeChart Dynamic Data Demo Chart Example JFreeChart 08-07-2016
JFreeChart Background Paint Example JFreeChart 07-07-2016
JFreeChart Get Plot Example JFreeChart 07-07-2016
JFreeChart Background Color Example JFreeChart 06-07-2016
JFreeChart Subtitles Example JFreeChart 06-07-2016
JFreeChart Chart Title Example JFreeChart 06-07-2016
JFreeChart Chart Border Example JFreeChart 05-07-2016
JFreeChart Time Series Chart Example JFreeChart 23-06-2016
JFreeChart Pie Chart 3D Example JFreeChart 08-06-2016
JFreeChart Line Chart Example JFreeChart 04-06-2016
JFreeChart Bar Chart Example JFreeChart 22-09-2018
JFreeChart Pie Chart Example JFreeChart 04-06-2016

1