package com.yong;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
/**
*
* @author 趙永恩
*
*/
public class Pie {
public static void main(String[] args) {
//數據
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("中文", 43.2);
dataset.setValue("Category 2", 27.9);
dataset.setValue("Category 3", 79.5);
dataset.setValue("Category 4", null);
dataset.setValue("Category 5", 0);
dataset.setValue("Category 6", -50.0f);
//創建 Jfreechart對象
JFreeChart jfreechart = ChartFactory.createPieChart("Simple Pie Chart", dataset, true, true, false);
PiePlot piePlot = (PiePlot) jfreechart.getPlot();
//指定分類餅的顏色
piePlot.setSectionPaint(33,Color.blue);
piePlot.setSectionPaint(2,Color.red);
piePlot.setSectionPaint(3,Color.yellow);
//設置Pie的邊框是否可見
piePlot.setSectionOutlinesVisible(true);
// 指定圖片的透明度(0.0-1.0)
piePlot.setForegroundAlpha(1.0f);
//設置邊框的顏色
piePlot.setBaseSectionOutlinePaint(Color.green);
//設置邊框的粗細,new BasicStroke(2.0f)
piePlot.setBaseSectionOutlineStroke(new BasicStroke(1));
//設置空值,0值,負值是否顯示出來,如果顯示的話就是false
piePlot.setIgnoreNullValues(true);
piePlot.setIgnoreZeroValues(true);
//設置上面的樣式,0表示KEY,1表示VALUE,2表示百分之幾,DecimalFormat用來顯示百分比的格式
piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}=>{1}({2})",NumberFormat.getNumberInstance(),new DecimalFormat("0.00%")));
//設置下面方框的樣式,0表示KEY,1表示VALUE,2表示百分之幾,DecimalFormat用來顯示百分比的格式
piePlot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}=>{1}({2})",NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
//爆炸模式,使Pie的一塊分離出去,不支持3D
piePlot.setExplodePercent(1, 0.10);
piePlot.setExplodePercent(2, 0.10);
piePlot.setExplodePercent(3, 0.10);
//定義字體格式
Font font = new Font("微軟雅黑", Font.CENTER_BASELINE, 12);
//定義圖片標題
TextTitle title = new TextTitle("Pie狀圖標題嘛");
//設置標題的格式
title.setFont(font);
//把標題設置到圖片裏面
jfreechart.setTitle(title);
//設置字體,非常關鍵不然會出現亂碼的,下方的字體
jfreechart.getLegend().setItemFont(font);
//Pie圖的字體
piePlot.setLabelFont(font);
//創建輸出流
FileOutputStream fos_jpg = null;
try {
fos_jpg = new FileOutputStream("c:\\Pie.jpg");
//用工具把圖象寫到硬盤,支持兩種格式,JPG,PNG,還支持MAP
ChartUtilities.writeChartAsJPEG(fos_jpg,0.99f,jfreechart,640,480,null);
fos_jpg.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.yong;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
/**
*
* @author 趙永恩
*
*/
public class Pie3D {
public static void main(String[] args) throws UnsupportedEncodingException {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("中文123", 43.2);
dataset.setValue("Category 2", 27.9);
dataset.setValue("Category 3", 27.9);
dataset.setValue("Category 4", null);
dataset.setValue("Category 5", 0);
dataset.setValue("Category 6", -50.0f);
JFreeChart jfreechart = ChartFactory.createPieChart3D("Simple Pie Chart", dataset, true, true, false);
PiePlot3D piePlot = (PiePlot3D) jfreechart.getPlot();
//指定分類餅的顏色
//piePlot.setSectionPaint("Category 1",Color.blue);
//piePlot.setSectionPaint("Category 2",Color.red);
//piePlot.setSectionPaint("Category 3",Color.yellow);
//設置Pie的邊框是否可見
piePlot.setSectionOutlinesVisible(true);
//設置邊框的顏色
piePlot.setBaseSectionOutlinePaint(Color.green);
//設置邊框的粗細,new BasicStroke(2.0f)
piePlot.setBaseSectionOutlineStroke(new BasicStroke(0));
//設置空值,0值,負值是否顯示出來,如果顯示的話就是false
piePlot.setIgnoreNullValues(true);
piePlot.setIgnoreZeroValues(true);
//設置上面的樣式,0表示KEY,1表示VALUE,2表示百分之幾,DecimalFormat用來顯示百分比的格式
piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}=>{1}({2})",NumberFormat.getNumberInstance(),new DecimalFormat("0.00%")));
//設置下面方框的樣式,0表示KEY,1表示VALUE,2表示百分之幾,DecimalFormat用來顯示百分比的格式
piePlot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}=>{1}({2})",NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
//爆炸模式,使Pie的一塊分離出去,不支持3D
piePlot.setExplodePercent(11, 0.10);
piePlot.setExplodePercent(2, 0.10);
piePlot.setExplodePercent(3, 0.10);
//定義字體格式
Font font = new Font("微軟雅黑", Font.CENTER_BASELINE, 12);
//定義圖片標題
TextTitle title = new TextTitle("Pie狀圖");
//設置標題的格式
title.setFont(font);
//把標題設置到圖片裏面
jfreechart.setTitle(title);
//設置字體,非常關鍵不然會出現亂碼的,下方的字體
jfreechart.getLegend().setItemFont(font);
//Pie圖的字體
piePlot.setLabelFont(font);
FileOutputStream fos_jpg = null;
try {
fos_jpg = new FileOutputStream("c:\\Pie3D.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg, 0.99f, jfreechart, 640, 480,null);
fos_jpg.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.yong;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;
/**
*
* @author 趙永恩
*
*/
public class Bar {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
//創建數據
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
//數據初始化
dataset.addValue(1.0, "北京", "蘋果");
dataset.addValue(7.0, "北京", "香蕉");
dataset.addValue(-3.0, "北京", "桔子");
dataset.addValue(2.0, "上海", "蘋果");
dataset.addValue(3.0, "上海", "香蕉");
dataset.addValue(2.0, "上海", "桔子");
//創建 JFreeChart 對象
JFreeChart chart = ChartFactory.createBarChart("Bar Chart 例子","水果(X)", "價格(Y)", dataset,PlotOrientation.VERTICAL,true,true,false);
//配置JFreeChart對象相關信息,如:字體大小,顏色,防止亂碼
Bar.configFont(chart);
//輸出
FileOutputStream fos_jpg = null;
try {
fos_jpg = new FileOutputStream("c:\\Bar11.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg,0.99f,chart,800,600, null);
fos_jpg.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void configFont(JFreeChart chart) {
//設置邊框寬度
chart.setBorderStroke(new BasicStroke(1));
//設置邊框是否可見
chart.setBorderVisible(true);
//設置邊框着色
chart.setBorderPaint(Color.cyan);
//設置背景顏色
//chart.setBackgroundPaint(Color.YELLOW);
// 配置字體
Font xfont = new Font("宋體", Font.CENTER_BASELINE, 20);// X軸
Font yfont = new Font("宋體", Font.CENTER_BASELINE, 20);// Y軸
Font kfont = new Font("宋體", Font.CENTER_BASELINE, 18);// 底部
Font titleFont = new Font("微軟雅黑", Font.CENTER_BASELINE, 25); // 圖片標題
CategoryPlot plot = chart.getCategoryPlot();// 圖形的繪製結構對象
//數據軸網格線條顏色
plot.setRangeGridlinePaint(Color.BLUE);
//數據軸網格線條筆觸
plot.setRangeGridlineStroke(new BasicStroke(1.0f));
// 圖片標題
chart.setTitle(new TextTitle(chart.getTitle().getText(),titleFont));
// 底部字體樣式,防止亂碼
chart.getLegend().setItemFont(kfont);
//X軸
CategoryAxis domainAxis = plot.getDomainAxis();
//設置X軸標題字體
domainAxis.setLabelFont(xfont);
//設置X軸字體
domainAxis.setTickLabelFont(xfont);
//設置字體顏色
domainAxis.setTickLabelPaint(Color.BLUE);
//橫軸上的label斜顯示
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
//domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
//分類軸邊距,同種類型之間的距離
//這是分類之間的距離,和BAR與BAR之間的距離有差別
//domainAxis.setCategoryMargin(0.2f);
//分類軸下(左)邊距,就是離左邊的距離
domainAxis.setLowerMargin(0.1);
//分類軸下(右)邊距,就是離最右邊的距離
domainAxis.setUpperMargin(0.1);
//Y 軸
ValueAxis rangeAxis = plot.getRangeAxis();
//設置Y軸標題字體
rangeAxis.setLabelFont(yfont);
//設置Y軸字體
rangeAxis.setTickLabelFont(yfont);
// 字體顏色
//rangeAxis.setLabelPaint(Color.RED); //包不同就這個屬性 yong
//設置Bar的顏色
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setSeriesPaint(0, Color.gray);
renderer.setSeriesPaint(1, Color.orange);
// 每個BAR之間的間隔
renderer.setItemMargin(0.0f);
//每個BAR的最大寬度
//renderer.setMaximumBarWidth(0.5f);
}
}
package com.yong;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.HorizontalAlignment;
import org.jfree.ui.RectangleEdge;
/**
*
* @author 趙永恩
*
*/
public class Line {
public static void main(String[] args) {
//數據
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(212, "Classes類", "JDK 1.0版本");
dataset.addValue(504, "Classes類", "JDK 1.1版本");
dataset.addValue(1520, "Classes類", "SDK 1.2版本");
dataset.addValue(1842, "Classes類", "SDK 1.3版本");
dataset.addValue(2991, "Classes類", "SDK 1.4版本");
JFreeChart chart = ChartFactory.createLineChart( "Java Standard Class Library","Release版本","Class數量",dataset,PlotOrientation.VERTICAL,false, true,false );
//配置chart
Line.configFont(chart);
//設置標題
TextTitle t = new TextTitle("Number of Classes By Release");
t.setFont(new Font("Comic Sans MS", Font.PLAIN, 15));
chart.addSubtitle(t);
//設置標題,並把標題放到最下面的右邊
TextTitle source = new TextTitle("Source: Java In A Nutshell (4th Edition) by David Flanagan (O’Reilly)");
source.setFont(new Font("Comic Sans MS", Font.PLAIN, 15));
//放到底部
source.setPosition(RectangleEdge.BOTTOM);
//放到右邊
source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
//添加
chart.addSubtitle(source);
//設置背影色
chart.setBackgroundPaint(Color.white);
CategoryPlot plot = (CategoryPlot)chart.getPlot();
//設置網格線
plot.setRangeGridlinePaint(Color.white);
// customise the range axis...(這個我不知道是啥子)
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
//設置線與線之間的連結點的樣式,比如說是否空心,顏色等
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot .getRenderer();
renderer.setShapesVisible(true);
renderer.setDrawOutlines(true);
renderer.setUseFillPaint(true);
renderer.setFillPaint(Color.yellow);
FileOutputStream fos_jpg = null;
try {
fos_jpg = new FileOutputStream("c:\\Line.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg,0.99f,chart,800,600, null);
fos_jpg.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 解決亂碼和樣式等問題
* @param chart
*/
private static void configFont(JFreeChart chart) {
// 配置字體
Font xfont = new Font("宋體", Font.CENTER_BASELINE, 12);// X軸
Font yfont = new Font("宋體", Font.CENTER_BASELINE, 20);// Y軸
Font kfont = new Font("宋體", Font.CENTER_BASELINE, 18);// 底部
Font titleFont = new Font("微軟雅黑", Font.CENTER_BASELINE, 25); // 圖片標題
CategoryPlot plot = chart.getCategoryPlot();// 圖形的繪製結構對象
//數據軸網格線條顏色
plot.setRangeGridlinePaint(Color.BLUE);
//數據軸網格線條筆觸
plot.setRangeGridlineStroke(new BasicStroke(1.0f));
// 圖片標題
chart.setTitle(new TextTitle(chart.getTitle().getText(),titleFont));
//X軸
CategoryAxis domainAxis = plot.getDomainAxis();
//設置X軸標題字體
domainAxis.setLabelFont(xfont);
//設置X軸字體
domainAxis.setTickLabelFont(xfont);
//設置字體顏色
domainAxis.setTickLabelPaint(Color.BLUE);
//橫軸上的label斜顯示
//domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
//domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
//分類軸邊距,同種類型之間的距離,比如說Row 1之間的
//domainAxis.setCategoryMargin(0.2f);
//分類軸下(左)邊距,就是離左邊的距離
domainAxis.setLowerMargin(0.1);
//分類軸下(右)邊距,就是離最右邊的距離
domainAxis.setUpperMargin(0.1);
//Y 軸
ValueAxis rangeAxis = plot.getRangeAxis();
//設置Y軸標題字體
rangeAxis.setLabelFont(yfont);
//設置Y軸字體
rangeAxis.setTickLabelFont(yfont);
// 字體顏色
rangeAxis.setLabelPaint(Color.RED);
}
}
package com.yong;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.RectangleInsets;
/**
*
* @author 趙永恩
*
*/
public class TimeSeriesTest {
public static void main(String[] args) {
//初始化數據
TimeSeries s1 = new TimeSeries("L&G European Index Trust中文", Month.class);
s1.add(new Month(2, 2001), 181.8);
s1.add(new Month(3, 2001), 167.3);
s1.add(new Month(4, 2001), 153.8);
s1.add(new Month(5, 2001), 167.6);
s1.add(new Month(6, 2001), 158.8);
s1.add(new Month(7, 2001), 148.3);
s1.add(new Month(8, 2001), 153.9);
s1.add(new Month(9, 2001), 142.7);
s1.add(new Month(10, 2001), 123.2);
s1.add(new Month(11, 2001), 131.8);
s1.add(new Month(12, 2001), 139.6);
s1.add(new Month(1, 2002), 142.9);
s1.add(new Month(2, 2002), 138.7);
s1.add(new Month(3, 2002), 137.3);
s1.add(new Month(4, 2002), 143.9);
s1.add(new Month(5, 2002), 139.8);
s1.add(new Month(6, 2002), 137.0);
s1.add(new Month(7, 2002), 132.8);
TimeSeries s2 = new TimeSeries("L&G UK Index Trust中文", Month.class);
s2.add(new Month(2, 2001), 129.6);
s2.add(new Month(3, 2001), 123.2);
s2.add(new Month(4, 2001), 117.2);
s2.add(new Month(5, 2001), 124.1);
s2.add(new Month(6, 2001), 122.6);
s2.add(new Month(7, 2001), 119.2);
s2.add(new Month(8, 2001), 116.5);
s2.add(new Month(9, 2001), 112.7);
s2.add(new Month(10, 2001), 101.5);
s2.add(new Month(11, 2001), 106.1);
s2.add(new Month(12, 2001), 110.3);
s2.add(new Month(1, 2002), 111.7);
s2.add(new Month(2, 2002), 111.0);
s2.add(new Month(3, 2002), 109.6);
s2.add(new Month(4, 2002), 113.2);
s2.add(new Month(5, 2002), 111.6);
s2.add(new Month(6, 2002), 108.8);
s2.add(new Month(7, 2002), 101.6);
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(s1);
dataset.addSeries(s2);
//創建 相應的對象
JFreeChart chart = ChartFactory.createTimeSeriesChart("日期","Date時間","Price價格",dataset,true, true, false );
//配置字體等格式
TimeSeriesTest.configFont(chart);
//設置背影色,由於這個例是COPY過來的,並沒有放到TimeSeriesTest.configFont(chart);這個方法裏面
chart.setBackgroundPaint(Color.white);
//獲得相當對象
XYPlot plot = (XYPlot) chart.getPlot();
//背影色
plot.setBackgroundPaint(Color.lightGray);
//X軸網格線和Y軸網格線顏色
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
//以下還不清楚
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
//以下也不清楚
XYItemRenderer r = plot.getRenderer();
if (r instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
renderer.setBaseShapesVisible(true);
renderer.setBaseShapesFilled(true);
}
//設置X座標上面的格式
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
FileOutputStream fos_jpg = null;
try {
fos_jpg = new FileOutputStream("c:\\TimeSeries.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg,0.99f,chart,800,600, null);
fos_jpg.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 配置字體等信息
* @param chart
*/
private static void configFont(JFreeChart chart) {
// 配置字體
Font xfont = new Font("宋體", Font.CENTER_BASELINE, 12);// X軸
Font yfont = new Font("宋體", Font.CENTER_BASELINE, 20);// Y軸
Font kfont = new Font("宋體", Font.CENTER_BASELINE, 18);// 底部
Font titleFont = new Font("微軟雅黑", Font.CENTER_BASELINE, 25); // 圖片標題
XYPlot plot = (XYPlot) chart.getPlot();// 圖形的繪製結構對象
//數據軸網格線條顏色
plot.setRangeGridlinePaint(Color.BLUE);
//數據軸網格線條筆觸
plot.setRangeGridlineStroke(new BasicStroke(1.0f));
// 圖片標題
chart.setTitle(new TextTitle(chart.getTitle().getText(),titleFont));
chart.getLegend().setItemFont(kfont);
//X軸
ValueAxis domainAxis = plot.getDomainAxis();
//設置X軸標題字體
domainAxis.setLabelFont(xfont);
//設置X軸字體
domainAxis.setTickLabelFont(xfont);
//設置字體顏色
domainAxis.setTickLabelPaint(Color.BLUE);
//橫軸上的label斜顯示
//domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
//domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
//分類軸邊距,同種類型之間的距離,比如說Row 1之間的
//domainAxis.setCategoryMargin(0.2f);
//分類軸下(左)邊距,就是離左邊的距離
domainAxis.setLowerMargin(0.1);
//分類軸下(右)邊距,就是離最右邊的距離
domainAxis.setUpperMargin(0.1);
//Y 軸
ValueAxis rangeAxis = plot.getRangeAxis();
//設置Y軸標題字體
rangeAxis.setLabelFont(yfont);
//設置Y軸字體
rangeAxis.setTickLabelFont(yfont);
// 字體顏色
rangeAxis.setLabelPaint(Color.RED);
}
}
JFreeChart jfreechart = null;
//獲得標題title.getText()
TextTitle title = jfreechart.getTitle();
//設置標題
jfreechart.setTitle("A Chart Title");
//設置標題的位置
jfreechart.getTitle().setPosition(RectangleEdge.BOTTOM);
//當然了還可以設置副標題
TextTitle subtitle1 = new TextTitle("A Subtitle");
jfreechart.addSubtitle(subtitle1);
//獲得副標題,可以有很多副標題,這是獲得第0個
Title subtitle = jfreechart.getSubtitle(0);
//設置背景顏色
jfreechart.setBackgroundPaint(Color.blue);
//當然還可以設置多種背影顏色
//表示在某個座標之後是什麼顏色
Paint p = new GradientPaint(0, 0, Color.white, 1000, 0, Color.green);
jfreechart.setBackgroundPaint(p);
//設置背景圖片LOG
jfreechart.setBackgroundImage(JFreeChart.INFO.getLogo());
//設置背景圖片的位置,這個沒有試過
jfreechart.setBackgroundImageAlignment(Align.TOP_LEFT);
//Plot Attributes(共有的)
//Plot(餅狀圖,)
Plot plot1 = jfreechart.getPlot();
//Plot(柱狀圖,)
CategoryPlot plot2 = jfreechart.getCategoryPlot();
//Plot(XY座標圖)
XYPlot plot3 = jfreechart.getXYPlot();
//設置背影顏色(是圖象的)(其它形狀同理)
plot1.setBackgroundPaint(Color.white);
//設置背景顏色
plot1.setBackgroundImage(JFreeChart.INFO.getLogo());
//Axis Attributes(X和Y上面的,軸對象,分爲X軸Y軸)
// get an axis reference...
CategoryPlot plot = jfreechart.getCategoryPlot();
//獲得X軸對象
CategoryAxis domainAxis = plot.getDomainAxis();
//獲得Y軸對象
ValueAxis rangeAxis = plot.getRangeAxis();
//change axis properties...改變屬性
domainAxis.setLabel("Categories");
domainAxis.setLabelFont(new Font("宋體", Font.CENTER_BASELINE, 20));
//設置X軸字體,Y軸同樣
domainAxis.setTickLabelFont(new Font("宋體", Font.CENTER_BASELINE, 20));
---------------------
作者:iteye_19819
來源:CSDN
原文:https://blog.csdn.net/iteye_19819/article/details/82067192
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!