jFreechart热点map功能

本文介绍如何利用jFreeChart库创建3D柱状图,并展示了具体实现代码,包括设置图表样式、添加数据及生成热点地图等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在研究jFreeChart,做了几个报表,也是通过别人的blog学习的。

public class HotMap{

private static DefaultCategoryDataset dataset = new DefaultCategoryDataset();

private DefaultCategoryDataset getDataset() {// 取数据

dataset.addValue(100,"北京", "苹果");

dataset.addValue(200,"上海", "橘子");

dataset.addValue(180,"南京", "西瓜");

dataset.addValue(230,"江西", "香蕉");

dataset.addValue(400,"深圳", "菠萝");

dataset.addValue(190,"珠海", "葡萄");

return dataset;

}

public String drawPic(HttpSession session, JspWriter out) {
String fileName = null;
JFreeChart chart = ChartFactory.createBarChart3D("各地水果价格", "类型",
"金额(单位:元)", getDataset(), PlotOrientation.VERTICAL, true, true,
true);
chart.setBackgroundPaint(Color.WHITE);

CategoryPlot plot = chart.getCategoryPlot();// 获取绘图区

plot.setBackgroundPaint(new Color(255, 255, 255)); // 设置绘图区背景色

plot.setRangeGridlinePaint(Color.gray); // 设置水平方向背景线颜色

plot.setRangeGridlinesVisible(true); // 设置是否显示水平方向背景线,默认值为True

plot.setDomainGridlinePaint(Color.black); // 设置垂直方向背景线颜色

// plot.setDomainGridlinesVisible(true); // 设置是否显示垂直方向背景线,默认值为False

CategoryAxis domainAxis = plot.getDomainAxis();// 获取统计种类轴标题(X轴)

plot.setDomainAxis(domainAxis);// 添加X轴

BarRenderer3D renderer = new BarRenderer3D();// 获得BarRenderer3D类的实例,目的是设置柱形的绘制属性

renderer
.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());//

//renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator(
// "index2.jsp"));// 生成热点,用于链接

renderer.setItemMargin(0.1);// 设置每个组所包含的平行柱的之间距离

renderer.setSeriesPaint(0, Color.GREEN);// 设置柱子的颜色
renderer.setSeriesPaint(1, Color.blue);// 设置柱子的颜色

renderer.setBaseOutlinePaint(Color.BLACK);

renderer.setWallPaint(Color.gray);// 设置 Wall 的颜色

renderer.setItemLabelAnchorOffset(10D);// 设置柱形图上的文字偏离值

renderer.setBaseItemLabelFont(new Font("arial", Font.PLAIN, 10), true);// 设置柱形图上的文字

renderer
.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());// //显示每个柱的数值,并修改该数值的字体属性

renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));

renderer.setBaseItemLabelsVisible(true);

renderer.setMaximumBarWidth(0.050000000000000003D);

plot.setRenderer(renderer);

plot.setForegroundAlpha(0.80f);// 设置柱的透明度

// plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);//设置显示位置

plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);// 设置显示位置

try {

PrintWriter pw = new PrintWriter(out);

StandardEntityCollection sec = new StandardEntityCollection();
ChartRenderingInfo info = new ChartRenderingInfo(sec);

fileName = ServletUtilities.saveChartAsPNG(chart, 640, 400, info,
session);
// ChartUtilities.writeChartAsPNG(op,chart, 640, 400, info,true,0);
ChartUtilities.writeImageMap(pw, fileName, info, true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return fileName;

}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值