jfreechart各种图表生成源码练习

jfreechart版本:0.9.20

把下面三个类放一起就可以编译,可以查看各种图生成的效果。

ChartFrame.java有错
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.jfree.chart.JFreeChart;

/** */
/**
* @author xum @ 2006/09/14 neusoft * TODO To change the template for this
* generated type comment go to Window - Preferences - Java - Code Style
* - Code Templates
*/
public class ChartFrame extends JFrame {

/**
*
*/
public ChartFrame() {
this.setBounds((int) ((1024 - 800) / 2), (int) ((768 - 600) / 2), 800,
600);
this.setTitle("JFreeChart Demo");

JFreeChart Chart = null;

//Chart = ChartCreater.createCategoryChart();
// Chart = ChartCreater.createCategoryChart3D();
// Chart = ChartCreater.createBarChart();
// Chart = ChartCreater.createBarChart3D();
// Chart = ChartCreater.createAreaChart();
// Chart = ChartCreater.createHistogram();
// Chart = ChartCreater.createLintChart3D();
// Chart = ChartCreater.createMultiplePieChart();
//Chart = ChartCreater.createMultiplePieChart3D();
// Chart = ChartCreater.createPieChart();
//Chart = ChartCreater.createPieChart3D();
// Chart = ChartCreater.createRingChart();
Chart = ChartCreater.createScatterPlot();
// Chart = ChartCreater.createBubbleChart(); //youcuo
// Chart = ChartCreater.createCandlestickChart(); //youcuo
// Chart = ChartCreater.createCombinedChart();
// Chart = ChartCreater.createGanttChart();
// Chart = ChartCreater.createHighLowChart(); //youcuo
// Chart = ChartCreater.createStackedAreaChart();
// Chart = ChartCreater.createStackedBarChart();
// Chart = ChartCreater.createStackedBarChart3D();
// Chart = ChartCreater.createStackedCategoryChart();
// Chart = ChartCreater.createStackedCategoryChart3D();
// Chart = ChartCreater.createStackedXYAreaChart(); //youcuo
// Chart = ChartCreater.createWaterfallChart();
// Chart = ChartCreater.createXYAreaChart();
// Chart = ChartCreater.createXYBarChart();
// Chart = ChartCreater.createXYLineChart();
// Chart = ChartCreater.createXYStepAreaChart();
// Chart = ChartCreater.createXYStepChart();

Chart.getPlot().setBackgroundAlpha(1.0f);
Chart.getPlot().setNoDataMessage("当前没有有效的数据");

Image chart = Chart.createBufferedImage(700, 500);

JLabel label = new JLabel();

label.setIcon(new ImageIcon(chart));

this.getContentPane().add(label, BorderLayout.CENTER);

}

public static void main(String[] args) {
new ChartFrame().setVisible(true);
}
}
import java.util.Calendar;
import java.util.Date;
import org.jfree.chart.*;
import org.jfree.data.CategoryDataset;
import org.jfree.data.DefaultCategoryDataset;
import org.jfree.data.DefaultHighLowDataset;
import org.jfree.data.DefaultPieDataset;
import org.jfree.data.DefaultTableXYDataset;
import org.jfree.data.HighLowDataset;
import org.jfree.data.IntervalCategoryDataset;
import org.jfree.data.OHLCDataItem;
import org.jfree.data.PieDataset;
import org.jfree.data.XYSeries;
import org.jfree.data.XYSeriesCollection;
import org.jfree.data.gantt.Task;
import org.jfree.data.gantt.TaskSeries;
import org.jfree.data.gantt.TaskSeriesCollection;
import org.jfree.data.time.SimpleTimePeriod;

/** */
/**
* @author xum @ 2006/09/14 JFreeChart 数据集样例
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ChartDataSet {

private static final String series1 = "series1";
private static final String series2 = "series2";
private static final String series3 = "series3";

private static final String category1 = "category1";
private static final String category2 = "category2";
private static final String category3 = "category3";
private static final String category4 = "category4";
private static final String category5 = "category5";

/** */
/**
* CategoryDataset 支持图表类型 BarChart BarChart3D LineChart LintChart3D
* AreaChart WaterfallChart MultiplePieChart MultiplePieChart3D
* StackedBarChart StackedBarChart3D StackedAreaChart
*
* @return CategoryDataset
*/
public static CategoryDataset createCategoryDataset() {
DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset();

categoryDataset.addValue(2.0, series1, category1);
categoryDataset.addValue(4.0, series1, category2);
categoryDataset.addValue(3.0, series1, category3);
categoryDataset.addValue(7.0, series1, category4);
categoryDataset.addValue(5.0, series1, category5);

categoryDataset.addValue(5.0, series2, category1);
categoryDataset.addValue(9.0, series2, category2);
categoryDataset.addValue(6.0, series2, category3);
categoryDataset.addValue(5.0, series2, category4);
categoryDataset.addValue(2.0, series2, category5);

categoryDataset.addValue(6.5, series3, category1);
categoryDataset.addValue(7.5, series3, category2);
categoryDataset.addValue(4.0, series3, category3);
categoryDataset.addValue(8.0, series3, category4);
categoryDataset.addValue(9.0, series3, category5);

return categoryDataset;
}

/** */
/**
* XYSeriesCollection 支持图表类型 PolarChart XYBarChart XYLineChart
* XYStepAreaChart XYAreaChart XYStepChart Histogram ScatterPlot
*
* @return XYSeriesCollection
*/
public static XYSeriesCollection createXYSeriesCollection() {
XYSeriesCollection dataset = new XYSeriesCollection();

XYSeries xyseries1 = new XYSeries(series1);
XYSeries xyseries2 = new XYSeries(series2);
XYSeries xyseries3 = new XYSeries(series3);

xyseries1.add(2.5, 6.0);
xyseries1.add(4.0, 3.5);
xyseries1.add(7.5, 5.5);
xyseries1.add(12.0, 7.0);
xyseries1.add(9.5, 10.0);

xyseries2.add(4.5, 11.0);
xyseries2.add(6.0, 3.5);
xyseries2.add(2.5, 5.0);
xyseries2.add(3.5, 6.5);
xyseries2.add(5.0, 7.0);

xyseries3.add(7.0, 12.0);
xyseries3.add(4.5, 8.0);
xyseries3.add(6.0, 4.5);
xyseries3.add(9.5, 11.0);
xyseries3.add(3.0, 6.0);

dataset.addSeries(xyseries1);
dataset.addSeries(xyseries2);
dataset.addSeries(xyseries3);

return dataset;
}

/** */
/**
* DefaultTableXYDataset 支持图表类型 StackedXYAreaChart
*
* @return DefaultTableXYDataset
*/
public static DefaultTableXYDataset createDefaultTableXYDataset() {
DefaultTableXYDataset dataset = new DefaultTableXYDataset();

XYSeries xyseries1 = new XYSeries(series1);
XYSeries xyseries2 = new XYSeries(series2);
XYSeries xyseries3 = new XYSeries(series3);

xyseries1.add(2.5, 6.0);
xyseries1.add(4.0, 3.5);
xyseries1.add(7.5, 5.5);
xyseries1.add(12.0, 7.0);
xyseries1.add(9.5, 10.0);

xyseries2.add(4.5, 11.0);
xyseries2.add(6.0, 3.5);
xyseries2.add(2.5, 5.0);
xyseries2.add(3.5, 6.5);
xyseries2.add(5.0, 7.0);

xyseries3.add(7.0, 12.0);
xyseries3.add(4.5, 8.0);
xyseries3.add(6.0, 4.5);
xyseries3.add(9.5, 11.0);
xyseries3.add(3.0, 6.0);

dataset.addSeries(xyseries1);
dataset.addSeries(xyseries2);
dataset.addSeries(xyseries3);

return dataset;
}

/** */
/**
* PieDataset 支持图表类型 PieChart PieChart3D RingChart
*
* @return PieDataset
*/
public static PieDataset createPieDataset() {
DefaultPieDataset dataset = new DefaultPieDataset();

dataset.setValue(category1, 12.0);
dataset.setValue(category2, 2.0);
dataset.setValue(category3, 4.0);
dataset.setValue(category4, 20.0);
dataset.setValue(category5, 7.0);

return dataset;
}

/** */
/**
* IntervalCategoryDataset 支持图表类型 GanttChart
*
* @return IntervalCategoryDataset
*/
public static IntervalCategoryDataset createGanttDataset() {
TaskSeriesCollection taskSeriesCollection = new TaskSeriesCollection();

TaskSeries s1 = new TaskSeries("Scheduled");
s1.add(new Task("Write Proposal", new SimpleTimePeriod(date(1,
Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001))));
s1.add(new Task("Obtain Approval", new SimpleTimePeriod(date(9,
Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001))));
s1.add(new Task("Requirements Analysis", new SimpleTimePeriod(date(10,
Calendar.APRIL, 2001), date(5, Calendar.MAY, 2001))));
s1.add(new Task("Design Phase", new SimpleTimePeriod(date(6,
Calendar.MAY, 2001), date(30, Calendar.MAY, 2001))));
s1.add(new Task("Design Signoff", new SimpleTimePeriod(date(2,
Calendar.JUNE, 2001), date(2, Calendar.JUNE, 2001))));
s1.add(new Task("Alpha Implementation", new SimpleTimePeriod(date(3,
Calendar.JUNE, 2001), date(31, Calendar.JULY, 2001))));
s1.add(new Task("Design Review", new SimpleTimePeriod(date(1,
Calendar.AUGUST, 2001), date(8, Calendar.AUGUST, 2001))));
s1.add(new Task("Revised Design Signoff", new SimpleTimePeriod(date(10,
Calendar.AUGUST, 2001), date(10, Calendar.AUGUST, 2001))));
s1.add(new Task("Beta Implementation", new SimpleTimePeriod(date(12,
Calendar.AUGUST, 2001), date(12, Calendar.SEPTEMBER, 2001))));
s1.add(new Task("Testing", new SimpleTimePeriod(date(13,
Calendar.SEPTEMBER, 2001), date(31, Calendar.OCTOBER, 2001))));
s1.add(new Task("Final Implementation", new SimpleTimePeriod(date(1,
Calendar.NOVEMBER, 2001), date(15, Calendar.NOVEMBER, 2001))));
s1.add(new Task("Signoff", new SimpleTimePeriod(date(28,
Calendar.NOVEMBER, 2001), date(30, Calendar.NOVEMBER, 2001))));
TaskSeries s2 = new TaskSeries("Actual");
s2.add(new Task("Write Proposal", new SimpleTimePeriod(date(1,
Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001))));
s2.add(new Task("Obtain Approval", new SimpleTimePeriod(date(9,
Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001))));
s2.add(new Task("Requirements Analysis", new SimpleTimePeriod(date(10,
Calendar.APRIL, 2001), date(15, Calendar.MAY, 2001))));
s2.add(new Task("Design Phase", new SimpleTimePeriod(date(15,
Calendar.MAY, 2001), date(17, Calendar.JUNE, 2001))));
s2.add(new Task("Design Signoff", new SimpleTimePeriod(date(30,
Calendar.JUNE, 2001), date(30, Calendar.JUNE, 2001))));
s2.add(new Task("Alpha Implementation", new SimpleTimePeriod(date(1,
Calendar.JULY, 2001), date(12, Calendar.SEPTEMBER, 2001))));
s2
.add(new Task("Design Review", new SimpleTimePeriod(date(12,
Calendar.SEPTEMBER, 2001), date(22, Calendar.SEPTEMBER,
2001))));
s2
.add(new Task("Revised Design Signoff", new SimpleTimePeriod(
date(25, Calendar.SEPTEMBER, 2001), date(27,
Calendar.SEPTEMBER, 2001))));
s2.add(new Task("Beta Implementation", new SimpleTimePeriod(date(27,
Calendar.SEPTEMBER, 2001), date(30, Calendar.OCTOBER, 2001))));
s2.add(new Task("Testing", new SimpleTimePeriod(date(31,
Calendar.OCTOBER, 2001), date(17, Calendar.NOVEMBER, 2001))));
s2.add(new Task("Final Implementation", new SimpleTimePeriod(date(18,
Calendar.NOVEMBER, 2001), date(5, Calendar.DECEMBER, 2001))));
s2.add(new Task("Signoff", new SimpleTimePeriod(date(10,
Calendar.DECEMBER, 2001), date(11, Calendar.DECEMBER, 2001))));
taskSeriesCollection.add(s1);
taskSeriesCollection.add(s2);

return taskSeriesCollection;
}

/** */
/**
* DefaultOHLCDataset 支持的图表类型 HighLowChart CandlestickChart
*
* @return DefaultOHLCDataset
*/
public static DefaultHighLowDataset createDefaultOHLCDataset() {

OHLCDataItem[] data = new OHLCDataItem[10];

data[0] = new OHLCDataItem(new Date(11L), 2.0, 4.0, 1.0, 3.0, 100.0);
data[1] = new OHLCDataItem(new Date(22L), 4.0, 9.0, 2.0, 5.0, 120.0);
data[2] = new OHLCDataItem(new Date(33L), 3.0, 7.0, 3.0, 6.0, 140.0);
data[3] = new OHLCDataItem(new Date(25L), 2.0, 4.0, 1.0, 3.0, 100.0);
data[4] = new OHLCDataItem(new Date(47L), 4.0, 9.0, 2.0, 5.0, 120.0);
data[5] = new OHLCDataItem(new Date(58L), 3.0, 7.0, 3.0, 6.0, 140.0);
data[6] = new OHLCDataItem(new Date(60L), 2.0, 4.0, 1.0, 3.0, 100.0);
data[7] = new OHLCDataItem(new Date(44L), 4.0, 9.0, 2.0, 5.0, 120.0);
data[8] = new OHLCDataItem(new Date(38L), 3.0, 7.0, 3.0, 6.0, 140.0);
data[9] = new OHLCDataItem(new Date(40L), 3.0, 7.0, 3.0, 6.0, 140.0);

HighLowDataset defaultHighLowDataset = new DefaultHighLowDataset(null, null, null, null, null, null, null);

return (DefaultHighLowDataset) defaultHighLowDataset;
}

/** */
/**
* DefaultXYZDataset 支持图表类型 BubbleChart
*
* @return DefaultXYZDataset
*/
public static DefaultCategoryDataset createDefaultXYZDataset() {
DefaultCategoryDataset defaultXYZDataset = new DefaultCategoryDataset();

double[] x1 = new double[] { 1.0, 2.0, 3.0 };
double[] y1 = new double[] { 4.0, 5.0, 6.0 };
double[] z1 = new double[] { 7.0, 8.0, 9.0 };
double[][] data1 = new double[][] { x1, y1, z1 };
//defaultXYZDataset.addSeries(series1, data1);

double[] x2 = new double[] { 1.0, 2.0, 3.0 };
double[] y2 = new double[] { 4.0, 5.0, 6.0 };
double[] z2 = new double[] { 7.0, 8.0, 9.0 };
double[][] data2 = new double[][] { x2, y2, z2 };
//defaultXYZDataset.addSeries(series1, data2);

return defaultXYZDataset;
}

private static Date date(int day, int month, int year) {
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day);
Date result = calendar.getTime();
return result;
}
}
 import java.awt.Color;
import java.awt.Font;
import java.awt.Rectangle;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.PieToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.BarRenderer;
import org.jfree.chart.renderer.LineAndShapeRenderer;
import org.jfree.chart.renderer.XYItemRenderer;
import org.jfree.data.CombinedDataset;
import org.jfree.data.XYZDataset;
import org.jfree.util.TableOrder;

/** */
/**
* @author xum @ 2006/09/14 neusoft TODO To change the template for this
* generated type comment go to Window - Preferences - Java - Code Style
* - Code Templates
*/
public class ChartCreater {

/** */
/**
* 2D柱图
*
* @return
*/
public static JFreeChart createCategoryChart() {

JFreeChart chart = ChartFactory.createBarChart("Bar2D", // 图表名称
"Category", // X轴名称
"Value", // Y轴名称
ChartDataSet.createCategoryDataset(),
PlotOrientation.VERTICAL, // 图表方向
true, // 图例
true, // Tooltips
false); // URL

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

return chart;
}

/** */
/**
* 3D柱图
*
* @return
*/
public static JFreeChart createCategoryChart3D() {

JFreeChart chart = ChartFactory.createBarChart3D("Bar2D", "Category",
"Value", ChartDataSet.createCategoryDataset(),
PlotOrientation.VERTICAL, true, true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

return chart;
}

/** */
/**
* 2D条形图
*
* @return
*/
public static JFreeChart createBarChart() {

JFreeChart chart = ChartFactory.createBarChart("Bar2D", "Category",
"Value", ChartDataSet.createCategoryDataset(),
PlotOrientation.HORIZONTAL, true, true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

return chart;
}

/** */
/**
* 3D条形图
*
* @return
*/
public static JFreeChart createBarChart3D() {

JFreeChart chart = ChartFactory.createBarChart3D("Bar2D", "Category",
"Value", ChartDataSet.createCategoryDataset(),
PlotOrientation.HORIZONTAL, true, true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

return chart;
}

/** */
/**
* 2D线图
*
* @return
*/
public static JFreeChart createLintChart() {

JFreeChart chart = ChartFactory.createLineChart("Bar2D", "Category",
"Value", ChartDataSet.createCategoryDataset(),
PlotOrientation.VERTICAL, true, true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

LineAndShapeRenderer lineAndShapeRenderer = (LineAndShapeRenderer) plot
.getRenderer();
lineAndShapeRenderer.setItemLabelsVisible(true);
lineAndShapeRenderer.setShapesFilled(true);

return chart;
}

/** */
/**
* 3D线图
*
* @return
*/
public static JFreeChart createLintChart3D() {

JFreeChart chart = ChartFactory.createBarChart3D("Bar2D", "Category",
"Value", ChartDataSet.createCategoryDataset(),
PlotOrientation.VERTICAL, true, true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

return chart;
}

/** */
/**
* 面积图
*
* @return
*/
public static JFreeChart createAreaChart() {
JFreeChart chart = ChartFactory.createAreaChart("Area", "Category",
"Value", ChartDataSet.createCategoryDataset(),
PlotOrientation.VERTICAL, true, true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

return chart;
}

/** */
/**
* 瀑布图
*
* @return
*/
public static JFreeChart createWaterfallChart() {
JFreeChart chart = ChartFactory.createWaterfallChart("WaterfallChart",
"Category", "Value", ChartDataSet.createCategoryDataset(),
PlotOrientation.VERTICAL, true, true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

return chart;
}

/** */
/**
* 2D饼图
*
* @return
*/
public static JFreeChart createPieChart() {
JFreeChart chart = ChartFactory.createPieChart("PieChart", ChartDataSet
.createPieDataset(), true, true, false);

PiePlot piePlot = (PiePlot) chart.getPlot();

piePlot.setCircular(false);
piePlot.setLabelGap(0.02);

return chart;
}

/** */
/**
* 3D饼图
*
* @return
*/
public static JFreeChart createPieChart3D() {
JFreeChart chart = ChartFactory.createPieChart3D("PieChart3D",
ChartDataSet.createPieDataset(), true, true, false);

PiePlot piePlot = (PiePlot) chart.getPlot();

piePlot.setCircular(false);
piePlot.setLabelGap(0.02);

return chart;
}

/** */
/**
* 复合饼图 12
*/
public static JFreeChart createMultiplePieChart() {
TableOrder order = TableOrder.BY_ROW;
// TableOrder order = TableOrder.BY_COLUMN;

JFreeChart chart = ChartFactory.createMultiplePieChart(
"MultiplePieChart", ChartDataSet.createCategoryDataset(),
order, true, true, false);

return chart;
}

/** */
/**
* 复合饼图3D 12
*/
public static JFreeChart createMultiplePieChart3D() {
TableOrder order = TableOrder.BY_ROW;
// TableOrder order = TableOrder.BY_COLUMN;

JFreeChart chart = ChartFactory.createMultiplePieChart3D(
"MultiplePieChart3D", ChartDataSet.createCategoryDataset(),
order, true, true, false);

return chart;
}

/** */
/**
* 环形图
*/
public static JFreeChart createRingChart() {
JFreeChart chart = ChartFactory.createPieChart("RingChart",
ChartDataSet.createPieDataset(), true, true, false);

Plot ringPlot = (Plot) chart.getPlot();

ringPlot.setBackgroundAlpha(1.0f);
((PiePlot) ringPlot).setCircular(false);
((PiePlot) ringPlot).setLabelGap(0.02);

return chart;
}

/** */
/**
* 散点图 40
*/
public static JFreeChart createScatterPlot() {
JFreeChart chart = ChartFactory.createScatterPlot("ScatterPlot",
"Categary", "Value", ChartDataSet.createXYSeriesCollection(),
PlotOrientation.VERTICAL, true, true, false);

XYPlot xyPlot = chart.getXYPlot();

setXYSeriesPlot(xyPlot);

return chart;
}

/** */
/**
* 组织图
*/
public static JFreeChart createHistogram() {
JFreeChart chart = ChartFactory.createHistogram("Histogram",
"Categary", "Value", ChartDataSet.createXYSeriesCollection(),
PlotOrientation.VERTICAL, true, true, false);

XYPlot xyPlot = chart.getXYPlot();

setXYSeriesPlot(xyPlot);

return chart;
}

/** */
/**
* 数据点阶梯图 33
*/
public static JFreeChart createXYStepChart() {
JFreeChart chart = ChartFactory.createXYStepChart("XYStepChart",
"Categary", "Value", ChartDataSet.createXYSeriesCollection(),
PlotOrientation.VERTICAL, true, true, false);

XYPlot xyPlot = chart.getXYPlot();

setXYSeriesPlot(xyPlot);

return chart;
}

/**//*
* 堆积柱状图 01
*/
public static JFreeChart createStackedCategoryChart() {
JFreeChart chart = ChartFactory.createStackedBarChart(
"StackedCategoryChar", "Categary", "Value", ChartDataSet
.createCategoryDataset(), PlotOrientation.VERTICAL,
true, true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

return chart;
}

/**//*
* 堆积柱状图3D 04
*/
public static JFreeChart createStackedCategoryChart3D() {
JFreeChart chart = ChartFactory.createStackedBarChart3D(
"StackedCategoryChar3D", "Categary", "Value", ChartDataSet
.createCategoryDataset(), PlotOrientation.VERTICAL,
true, true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

return chart;
}

/**//*
* 堆积条形图 21
*/
public static JFreeChart createStackedBarChart() {
JFreeChart chart = ChartFactory.createStackedBarChart(
"StackedBarChart", "Categary", "Value", ChartDataSet
.createCategoryDataset(), PlotOrientation.HORIZONTAL,
true, true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

return chart;
}

/**//*
* 堆积条形图3D 23
*/
public static JFreeChart createStackedBarChart3D() {
JFreeChart chart = ChartFactory.createStackedBarChart3D(
"StackedBarChart3D", "Categary", "Value", ChartDataSet
.createCategoryDataset(), PlotOrientation.HORIZONTAL,
true, true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

return chart;
}

/**//*
* 堆积面积图 53
*/
public static JFreeChart createStackedAreaChart() {
JFreeChart chart = ChartFactory.createStackedAreaChart(
"StackedAreaChart", "Categary", "Value", ChartDataSet
.createCategoryDataset(), PlotOrientation.VERTICAL,
true, true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

return chart;
}

/**//*
* XY数据点面积图 52
*/
public static JFreeChart createXYAreaChart() {
JFreeChart chart = ChartFactory.createXYAreaChart("XYAreaChart",
"Categary", "Value", ChartDataSet.createXYSeriesCollection(),
PlotOrientation.VERTICAL, true, true, false);

XYPlot xyPlot = chart.getXYPlot();

setXYSeriesPlot(xyPlot);

return chart;
}

/**//*
* XY数据点阶梯面积图 51
*/
public static JFreeChart createXYStepAreaChart() {
JFreeChart chart = ChartFactory.createXYStepAreaChart(
"XYStepAreaChart", "Categary", "Value", ChartDataSet
.createXYSeriesCollection(), PlotOrientation.VERTICAL,
true, true, false);

XYPlot xyPlot = chart.getXYPlot();

setXYSeriesPlot(xyPlot);

return chart;
}

/**//*
* XY数据点折线图 32
*/
public static JFreeChart createXYLineChart() {
JFreeChart chart = ChartFactory.createXYLineChart("XYLineChart",
"Categary", "Value", ChartDataSet.createXYSeriesCollection(),
PlotOrientation.VERTICAL, true, true, false);

XYPlot xyPlot = chart.getXYPlot();

setXYSeriesPlot(xyPlot);

XYItemRenderer lineAndShapeRenderer = (XYItemRenderer) xyPlot
.getRenderer();

return chart;
}

/**//*
* XY数据点柱状图 05
*/
public static JFreeChart createXYBarChart() {
JFreeChart chart = ChartFactory.createXYBarChart("XYBarChart",
"Categary", true, "Value", ChartDataSet
.createXYSeriesCollection(), PlotOrientation.VERTICAL,
true, true, false);

XYPlot xyPlot = chart.getXYPlot();

setXYSeriesPlot(xyPlot);

return chart;
}

/**//*
* 气泡图
*/
public static JFreeChart createBubbleChart() {
JFreeChart chart = ChartFactory.createBubbleChart("BubbleChart",
"Categary", "Value", (XYZDataset) ChartDataSet.createDefaultXYZDataset(),
PlotOrientation.VERTICAL, true, true, false);

return chart;
}

/**//*
* 数据点堆积面积图
*/
public static JFreeChart createStackedXYAreaChart() {
JFreeChart chart = ChartFactory.createStackedXYAreaChart(
"StackedXYAreaChart", "Categary", "Value", ChartDataSet
.createDefaultTableXYDataset(),
PlotOrientation.VERTICAL, true, true, false);

XYPlot xyPlot = chart.getXYPlot();

setXYSeriesPlot(xyPlot);

return chart;
}

/**//*
* 甘特图
*/
public static JFreeChart createGanttChart() {
JFreeChart chart = ChartFactory.createGanttChart("GanttChart",
"Categary", "Value", ChartDataSet.createGanttDataset(), true,
true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

return chart;
}

/**//*
* 股价图
*/
public static JFreeChart createHighLowChart() {
JFreeChart chart = ChartFactory.createHighLowChart("HighLowChart",
"Categary", "Value", ChartDataSet.createDefaultOHLCDataset(),
false);

return chart;
}

/**//*
* 烛台图
*/
public static JFreeChart createCandlestickChart() {
JFreeChart chart = ChartFactory.createCandlestickChart(
"CandlestickChart", "Categary", "Value", ChartDataSet
.createDefaultOHLCDataset(), false);
return chart;
}

/**//*
* 雷达图
*/
private JFreeChart createPolarChart() {
JFreeChart chart = ChartFactory.createPolarChart("PolarChart",
ChartDataSet.createXYSeriesCollection(), true, true, false);

return chart;
}

/**//*
* 2D柱线图
*/
public static JFreeChart createCombinedChart() {
JFreeChart chart = ChartFactory.createBarChart("CombinedChart",
"Categary", "Value", ChartDataSet.createCategoryDataset(),
PlotOrientation.VERTICAL, true, true, false);

CategoryPlot plot = (CategoryPlot) chart.getPlot();

setCategoryPlot(plot);

BarRenderer barRenderer = (BarRenderer) plot.getRenderer();
barRenderer.setMaxBarWidth(0.10D);
barRenderer.setItemMargin(0.10D);

NumberAxis numberAxis = new NumberAxis("");
plot.setRangeAxis(1, numberAxis);
plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
plot.setDataset(1, ChartDataSet.createCategoryDataset());
plot.setRenderer(1, new LineAndShapeRenderer());
plot.mapDatasetToDomainAxis(1, 0);
plot.mapDatasetToRangeAxis(1, 1);

return chart;
}

/** */
/**
* 设置CategoryPlot 坐标轴及网格属性设置
*
* @param plot
*/
private static void setCategoryPlot(CategoryPlot plot) {
plot.getDomainAxis().setVisible(true);
plot.getDomainAxis().setLabelFont(new Font("宋体", Font.PLAIN, 12));
plot.getDomainAxis().setLabelPaint(Color.BLACK);
plot.getDomainAxis().setTickLabelFont(new Font("宋体", Font.PLAIN, 12));
plot.getDomainAxis().setTickLabelPaint(Color.BLACK);
plot.getDomainAxis().setTickLabelsVisible(true);

plot.getRangeAxis().setVisible(true);
plot.getRangeAxis().setLabelFont(new Font("宋体", Font.PLAIN, 12));
plot.getRangeAxis().setLabelPaint(Color.BLACK);
plot.getRangeAxis().setTickLabelFont(new Font("宋体", Font.PLAIN, 12));
plot.getRangeAxis().setTickLabelPaint(Color.BLACK);
plot.getRangeAxis().setVerticalTickLabels(false);
plot.getRangeAxis().setLabelAngle(0.0D);

plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinesVisible(true);
}

/** */
/**
* 设置 XYPlot
*
* @param plot
*/
private static void setXYSeriesPlot(XYPlot plot) {
plot.getDomainAxis().setVisible(true);
plot.getDomainAxis().setLabelFont(new Font("宋体", Font.PLAIN, 12));
plot.getDomainAxis().setLabelPaint(Color.BLACK);
plot.getDomainAxis().setTickLabelFont(new Font("宋体", Font.PLAIN, 12));
plot.getDomainAxis().setTickLabelPaint(Color.BLACK);
plot.getDomainAxis().setTickLabelsVisible(true);

plot.getRangeAxis().setVisible(true);
plot.getRangeAxis().setLabelFont(new Font("宋体", Font.PLAIN, 12));
plot.getRangeAxis().setLabelPaint(Color.BLACK);
plot.getRangeAxis().setTickLabelFont(new Font("宋体", Font.PLAIN, 12));
plot.getRangeAxis().setTickLabelPaint(Color.BLACK);
plot.getRangeAxis().setVerticalTickLabels(false);
plot.getRangeAxis().setLabelAngle(0.0D);

plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinesVisible(true);
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值