日期:2014-05-17  浏览次数:20898 次

jfreechart柱状图中的数值怎么样横着显示?
我用jfreechart生成柱状图,在柱的顶端显示数值,怎么会显示竖起呢?比如123.就显示成
3
2
1

怎么样调成正常显示啊?

------解决方案--------------------
public class JFreeCharTest1 {

/**
* @param args
*/
public static CategoryDataset CreateCategory(){
DefaultCategoryDataset cds=new DefaultCategoryDataset();
cds.setValue(10,"开发人员","beyondsoft");
cds.setValue(18,"初级开发人员","beyondsoft");
cds.setValue(22,"高级开发人员","beyondsoft");
cds.setValue(26,"测试人员","hisoft");
cds.setValue(33,"黑盒测试人员","hisoft");
cds.setValue(44,"白盒测试人员","hisoft");
return cds;
}

public static JFreeChart getfreechart(){
JFreeChart chart=ChartFactory.createBarChart("IT市场形式分析","公司名","人数",CreateCategory(), PlotOrientation.VERTICAL, true, true, true);
CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
// 设置图表的纵轴和横轴org.jfree.chart.axis.CategoryAxis
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
CategoryAxis domainAxis = categoryplot.getDomainAxis();
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, 12));
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));
chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
return chart;
}

public static void main(String[] args) {

ChartFrame frame=new ChartFrame("IT市场形式分析",getfreechart());
frame.pack();
frame.setVisible(true);
}
}
参考下吧。
------解决方案--------------------

Java code

JFreeChart chart = ChartFactory.createBarChart("企业风险度等级统计图", // 图表标题
                "企业风险度等级", // 目录轴的显示标签
                "企业风险度等级个数", // 数值轴的显示标签
                getPillarDateSet(riskLevelList, sum), // 数据
                // PlotOrientation.HORIZONTAL, //图表方向水平
                PlotOrientation.VERTICAL, // 图表方向垂直
                true, // 是否显示图例
                false, // 是否显示工具提示
                false // 是否生成URL
                );
        // 设置标题及标题字体
        chart.setTitle(new TextTitle("企业风险度等级统计图",
                new Font("宋体", Font.BOLD, 18)));
        //设置图例文字
        chart.getLegend().setItemFont(new Font("宋体", Font.BOLD, 12));
        // 获取柱状图plot对象
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        // 设置柱型的颜色
        plot.getRenderer().setSeriesPaint(0, Color.blue);
        plot.setNoDataMessage("抱歉,没有查到相关的数据...");
        // 取得横轴
        CategoryAxis categoryAxis = plot.getDomainAxis();
        // 设置横轴的字体
        categoryAxis.setLabelFont(new Font("sans-serif", Font.BOLD, 18));
        // 设置分类标签以45度倾斜
        // categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
        // 设置分类标签字体
        categoryAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 15));
        // 取得纵轴
        NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
        // 设置纵轴的字体
        numberAxis.setLabelFont(new Font("宋体", Font.BOLD, 18));
        
        BarRenderer3D renderer = new BarRenderer3D();
        // 显示每个柱的数值,并修改该数值的字体属性
        renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(