<%
java.io.PrintWriter pw=new java.io.PrintWriter(out);
double[][] data = new double[][] {{500}, {200}, {100}, {400}, {600}, {300}};
String[] rowKeys = {"苹果", "梨子", "葡萄", "桔子",
"西瓜", "香蕉"};
String[] columnKeys = {""};
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
rowKeys,
columnKeys,
data);
JFreeChart chart = ChartFactory.createBarChart3D("水果销量图统计",
"水果", //横坐标名称
"销量", //纵坐标名称
dataset,//数据集合
PlotOrientation.VERTICAL,//图形位置,水平还是垂直
true,
false,
false);
chart.setBackgroundPaint(Color.WHITE);
//设定背景色为白色
CategoryPlot categoryPlot = chart.getCategoryPlot();
//获得 plot:3dBar为CategoryPlot
categoryPlot.setBackgroundPaint(Color.lightGray);
//设定图表数据显示部分背景色
categoryPlot.setDomainGridlinePaint(Color.white);
//横坐标网格线白色
categoryPlot.setDomainGridlinesVisible(true);
//设置网格线可见
categoryPlot.setRangeGridlinePaint(Color.white);
//纵坐标网格线白色
//获取横坐标
CategoryAxis domainAxis = categoryPlot.getDomainAxis();
//设置 横坐标 垂直显示
//domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.4));
//获取纵坐标
NumberAxis numberaxis = (NumberAxis)categoryPlot.getRangeAxis();
//将纵坐标间距设置为50
numberaxis.setTickUnit(new NumberTickUnit(50));
//设置横坐标的标题字体和大小,此处是“宋体13号”
domainAxis.setLabelFont(new Font("宋体",Font.PLAIN,13));
//设置距离图片左端距离,参数为图片的百分比
domainAxis.setLowerMargin(0.05);
//设置距离图片右端距离
domainAxis.setUpperMargin(0.05);
//设置横坐标的坐标值的字体
domainAxis.setTickLabelFont(new Font("宋体",Font.PLAIN,12));
//使横坐标设置生效
categoryPlot.setDomainAxis(domainAxis);