急求解决JfreeChart柱状图数值显示在柱子顶端的问题!!!
我控制显示柱状图的代码如下,但是却不能得到想要的结果(将柱状图中柱子的数值显示在柱子外面的顶端)。
package com.trustel.gd12580.datamanagement.service;
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Paint;
import java.io.PrintWriter;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.TextAnchor;
/**
* @author Liucl
*
*/
public class KpiCityCompanyChart {
/**
* 图片长度, 默认为650
*/
public static int IMAGE_WIDTH = 760;
/**
* 图片高度, 默认为350
*/
public static int IMAGE_HEIGHT = 350;
/**
* 设置图片显示大小,默认为450*350
*/
public static void setImageRange(int width, int height) {
IMAGE_WIDTH = width;
IMAGE_HEIGHT = height;
}
/**
* 用于生成柱状图
*
* @param title
* 图形标题
* @param domain
* 横坐标名称
* @param range
* 纵坐标名称
* @param session
* 图片生命周期
* @param pw
* printWriter
* @param dataset
* 数据源
* @param length
* 分类数
* @return
*/
public static String createBarChartChart(String title, String domain,
String range, HttpSession session, PrintWriter pw,
DefaultCategoryDataset dataset) {
String filename = null;
try {
JFreeChart chart = createChart(title, domain, range, dataset);
// 把生成的图片放到临时目录
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
// 设置图片名称前缀
ServletUtilities.setTempFilePrefix("chart-");
// 生成图片
filename = ServletUtilities.saveChartAsPNG(chart, IMAGE_WIDTH,
IMAGE_HEIGHT, info, session);
// ChartUtilities.writeImageMap(pw, filename, info, false);
pw.flush();
} catch (Exception e) {
e.printStackTrace(System.out);
filename = "error_warning.gif";
}
return filename;
}
/**
* Creates a sample chart.
*
* @param title
* 图形标题
* @param domain
* 横坐标名称
* @param range
* 纵坐标名称
* @param dataset
* 数据源
*
* @return The chart.
*/
private static JFreeChart createChart(String title, String domain,
String range, CategoryDataset dataset) {
// create the chart...
JFreeChart chart = ChartFactory.createBarChart3D(title, // title