JFreeChart折れ線図、円グラフ、柱状図
JFreeChart java , , :
pie charts (2D and 3D): ( )
bar charts (regular and stacked, with an optional 3D effect):
line and area charts:
scatter plots and bubble charts
time series, high/low/open/close charts and candle stick charts:
combination charts:
Pareto charts
Gantt charts:
wind plots, meter charts and symbol charts
wafer map charts
( , ( ) , ( , ), , , , , , , , )
PNG JPEG , PDF EXCEL
JFreeChart :
:org.jfree.chart,org.jfree.data。
, 。 ,
。
:
org.jfree.chart.JFreeChart: , 。JFreeChart
org.jfree.data.category.XXXDataSet: , 。
org.jfree.chart.plot.XXXPlot: , , Axis、Renderer
org.jfree.chart.axis.XXXAxis: :
org.jfree.chart.render.XXXRender:
org.jfree.chart.urls.XXXURLGenerator: Web
XXXXXToolTipGenerator: ,
1: :
package test;
import java.awt.Font;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class PieCharts extends ApplicationFrame{
public PieCharts(String s){
super(s);
setContentPane(createDemoPanel());
}
//
public static JPanel createDemoPanel(){
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
//
public static PieDataset createDataset(){
DefaultPieDataset defaultpiedataset = new DefaultPieDataset();
defaultpiedataset.setValue(" ",10.02D);
defaultpiedataset.setValue(" ",20.23D);
defaultpiedataset.setValue(" ",60.02D);
defaultpiedataset.setValue("OEM ",10.02D);
defaultpiedataset.setValue(" ",5.11D);
return defaultpiedataset;
}
// JFreeChart
public static JFreeChart createChart(PieDataset piedataset){
//
JFreeChart jfreechart = ChartFactory.createPieChart("CityInfoPort ",piedataset,true,true,false);
//
PiePlot pieplot = (PiePlot)jfreechart.getPlot();
//
pieplot.setLabelFont(new Font("SansSerif",Font.BOLD,12));
pieplot.setNoDataMessage("No data available");
pieplot.setCircular(true);
pieplot.setLabelGap(0.01D);//
return jfreechart;
}
public static void main(String[] args){
PieCharts fjc = new PieCharts("CityInfoPort ");
fjc.pack();
RefineryUtilities.centerFrameOnScreen(fjc);
fjc.setVisible(true);
}
}
2:
package test;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class LineCharts extends ApplicationFrame {
public LineCharts(String s) {
super(s);
setContentPane(createDemoLine());
}
public static void main(String[] args) {
LineCharts fjc = new LineCharts(" ");
fjc.pack();
RefineryUtilities.centerFrameOnScreen(fjc);
fjc.setVisible(true);
}
//
public static JPanel createDemoLine() {
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
// JFreeChart
public static JFreeChart createChart(DefaultCategoryDataset linedataset) {
//
JFreeChart chart = ChartFactory.createLineChart(" ", // chart title
" ", // domain axis label
" ( )", // range axis label
linedataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
CategoryPlot plot = chart.getCategoryPlot();
// customise the range axis...
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setAutoRangeIncludesZero(true);
rangeAxis.setUpperMargin(0.20);
rangeAxis.setLabelAngle(Math.PI / 2.0);
return chart;
}
//
public static DefaultCategoryDataset createDataset() {
DefaultCategoryDataset linedataset = new DefaultCategoryDataset();
//
String series1 = " ";
String series2 = " ";
String series3 = " ";
// ( )
String type1 = "1 ";
String type2 = "2 ";
String type3 = "3 ";
linedataset.addValue(0.0, series1, type1);
linedataset.addValue(4.2, series1, type2);
linedataset.addValue(3.9, series1, type3);
linedataset.addValue(1.0, series2, type1);
linedataset.addValue(5.2, series2, type2);
linedataset.addValue(7.9, series2, type3);
linedataset.addValue(2.0, series3, type1);
linedataset.addValue(9.2, series3, type2);
linedataset.addValue(8.9, series3, type3);
return linedataset;
}
}
3: :
package test;
import java.awt.Color;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class BarCharts extends ApplicationFrame {
public BarCharts(String s) {
super(s);
setContentPane(createDemoBar());
}
//
public static JPanel createDemoBar() {
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
// JFreeChart
public static JFreeChart createChart(CategoryDataset dataset) {
JFreeChart chart = ChartFactory.createBarChart3D(" ", // 3D
" ",//
" ",//
dataset,//
PlotOrientation.VERTICAL,//
true,//
false, false);
CategoryPlot plot = chart.getCategoryPlot();//
BarRenderer3D renderer = new BarRenderer3D();//3D
renderer.setBaseOutlinePaint(Color.BLACK);// black
renderer.setWallPaint(Color.gray); // wall gray
renderer
.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());// ,API StandardCategoryItemLabelGenerator
//renderer.setItemLabelFont(new Font(" ",Font.PLAIN,12));//
renderer.setItemLabelsVisible(true);// ItemLabel
plot.setRenderer(renderer);//
plot.setForegroundAlpha(0.6f);//
return chart;
}
//
public static CategoryDataset createDataset() {
double[][] data = new double[][] { { 672, 766, 223, 540, 126 },
{ 325, 521, 210, 340, 106 }, { 332, 256, 523, 240, 526 } };//
String[] rowKeys = { " ", " ", " " };//
String[] columnKeys = { " ", " ", " ", " ", " " };//
CategoryDataset linedataset = DatasetUtilities.createCategoryDataset(
rowKeys, columnKeys, data); //
return linedataset;
}
public static void main(String[] args) {
BarCharts fjc = new BarCharts(" ");
fjc.pack();
RefineryUtilities.centerFrameOnScreen(fjc);
fjc.setVisible(true);
}
}
http://blog.csdn.net/Daemon_neu/article/details/1709498