package test; import java.io.FileOutputStream; import java.io.IOException; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.CategoryDataset; import org.jfree.data.DefaultCategoryDataset; public class ChartTest { private static CategoryDataset getDataSet2() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(100, "北京", "苹果"); dataset.addValue(150, "上海", "苹果"); dataset.addValue(300, "广州", "苹果"); dataset.addValue(240, "北京", "梨子"); dataset.addValue(560, "上海", "梨子"); dataset.addValue(200, "广州", "梨子"); dataset.addValue(300, "北京", "葡萄"); dataset.addValue(980, "上海", "葡萄"); dataset.addValue(900, "广州", "葡萄"); dataset.addValue(400, "北京", "香蕉"); dataset.addValue(1560, "上海", "香蕉"); dataset.addValue(6000, "广州", "香蕉"); dataset.addValue(1000, "北京", "荔枝"); dataset.addValue(8890, "上海", "荔枝"); dataset.addValue(5770, "广州", "荔枝"); return dataset; } public static void main(String[] args) throws IOException { CategoryDataset dataset = getDataSet2(); JFreeChart chart = ChartFactory.createBarChart3D("水果产量图", "水果", "产量", dataset, PlotOrientation.VERTICAL, true, false, false); FileOutputStream fos_jpg = null; try { fos_jpg = new FileOutputStream("D:\\fruit.jpg"); ChartUtilities.writeChartAsJPEG(fos_jpg, 1.0f, chart, 400, 300, null); } finally { try { fos_jpg.close(); } catch (Exception e) { } } } }