关键就是用好Renderer这个类了,再贴个例子:
String sFont = "宋体";
chart.setBorderVisible(true);
chart.setBorderPaint(new Color(0xFF,0x66,0x00));
chart.setBackgroundPaint(new Color(0xFF,0xF3,0xDE));
chart.getTitle().setPaint(Color.red);
chart.getTitle().setFont(new Font(sFont,Font.BOLD,14));
//设置Plot,不显示所有网格
((CategoryPlot)chart.getPlot()).setOutlinePaint(null);
((CategoryPlot)chart.getPlot()).setDomainGridlinesVisible(false);
((CategoryPlot)chart.getPlot()).setRangeGridlinesVisible(false);
//设置横轴字体,设定横轴轴线不可见,隐藏纵轴
((CategoryPlot)chart.getPlot()).getDomainAxis().setTickLabelFont(new Font(sFont,Font.PLAIN,12));
((CategoryPlot)chart.getPlot()).getDomainAxis().setAxisLineVisible(false);
((CategoryPlot)chart.getPlot()).getRangeAxis().setVisible(false);
//采用BarRenderer作为表示器
BarRenderer renderer = new BarRenderer();
renderer.setPaint(new GradientPaint(0.0f,0.0f,Color.orange,0.0f,0.0f,Color.yellow));
renderer.setOutlinePaint(Color.orange);
renderer.setDrawBarOutline(true);
//在条中央显示投票数值
renderer.setItemLabelAnchorOffset(-20.0f);
renderer.setLabelGenerator(new StandardCategoryLabelGenerator("{2}",new DecimalFormat()));
renderer.setPositiveItemLabelPosition(new ItemLabelPosition());
renderer.setItemLabelsVisible(true);
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核心类库介绍:
研究jfreechart源码发现源码的主要由两个大的包组成:org.jfree.chart,org.jfree.data。其中前者主要与图形本身有关,后者与图形显示的数据有关。