首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

JFreeChart-柱状图容易实例

2012-11-01 
JFreeChart--柱状图简单实例?现在学习jfreeChart,所以在网上查找了一些实例,综合之后的结构public class H

JFreeChart--柱状图简单实例

?现在学习jfreeChart,所以在网上查找了一些实例,综合之后的结构
public class Histogram {public static void main(String[] args) {// 创建柱状图DefaultCategoryDataset dataset = new DefaultCategoryDataset();// 装载数据dataset.setValue(6, "Profit", "Jane");dataset.setValue(3, "Profit2", "Jane");dataset.setValue(7, "Profit", "Tom");dataset.setValue(6, "Profit2", "Tom");dataset.setValue(8, "Profit", "Jill");dataset.setValue(9, "Profit2", "Jill");dataset.setValue(5, "Profit", "Johh");dataset.setValue(8, "Profit2", "Johh");dataset.setValue(12, "Profit", "Fred");dataset.setValue(11, "Profit2", "Fred");// 产生柱状图// JFreeChart chart = ChartFactory.createBarChart("标题", "x轴标志", "y轴标志",// 设置数据, 设置图形显示方向, 是否显示图形, 是否进行提示, 是否配置报表存放地址);// 3D柱状图JFreeChart chart = ChartFactory.createBarChart("销售统计图", "销售员", "盈利",dataset, PlotOrientation.VERTICAL, true, true, false);// 解决中文乱码CategoryPlot plot = chart.getCategoryPlot();CategoryAxis domainAxis = plot.getDomainAxis();NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();TextTitle textTitle = chart.getTitle();textTitle.setFont(new Font("黑体", Font.PLAIN, 20));domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));numberAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));numberAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));try {// 创建图形显示面板ChartFrame cf = new ChartFrame("柱状图", chart);cf.pack();// 设置图片大小cf.setSize(800, 600);// 设置图形可见cf.setVisible(true);// 保存图片到指定位置// ChartUtilities.saveChartAsJPEG(new File("C:\\bar.png"), chart,// 500,// 300);} catch (Exception e) {System.err.println("Problem occurred creating chart.");}}}

?效果

?

JFreeChart-柱状图容易实例

热点排行