<%@page import="java.awt.Color"%> <%@page import="org.jfree.chart.axis.CategoryAxis"%> <%@page import="org.jfree.chart.title.TextTitle"%> <%@page import="java.awt.Font"%> <%@ page contentType="text/html;charset=utf-8"%> <%@ page import="org.jfree.data.general.DefaultPieDataset"%> <%@ page import="org.jfree.chart.*"%> <%@ page import="org.jfree.chart.plot.*"%> <%@ page import="org.jfree.chart.servlet.ServletUtilities"%> <%@ page import="org.jfree.chart.urls.StandardPieURLGenerator"%> <%@ page import="org.jfree.chart.entity.StandardEntityCollection"%> <%@ page import="java.io.*"%> <HTML> <HEAD> <META http-equiv=Content-Type content="text/html; charset=utf-8"> <TITLE></TITLE> </HEAD> <BODY> <% DefaultPieDataset data = new DefaultPieDataset(); data.setValue("张家港市",370); data.setValue("昆山市",1530); data.setValue("常熟市",5700); data.setValue("太仓市",8280); data.setValue("工业园区",4420); data.setValue("高新区",800); data.setValue("吴中区",8041); data.setValue("相城区",8023); data.setValue("吴江区",8065); data.setValue("姑苏区",8034); PiePlot3D plot = new PiePlot3D(data);//3D饼图 plot.setURLGenerator(new StandardPieURLGenerator("barview.jsp"));//设定链接 JFreeChart chart = new JFreeChart("",JFreeChart.DEFAULT_TITLE_FONT, plot, true); //chart.setBackgroundPaint(java.awt.Color.white);//可选,设置图片背景色 //chart.setTitle("程序员学历情况调查表");//可选,设置图片标题 //plot.setToolTipGenerator(new StandardPieItemLabelGenerator()); //设置字体 Font font = new Font("宋体",10,22); TextTitle tt = chart.getTitle(); //设置标题 tt.setFont(font); //chart.getTitle().setFont(new Font("黑体",Font.BOLD,20));//设置标题字体 //PiePlot piePlot= (PiePlot) jfreechart.getPlot();//获取图表区域对象 plot.setLabelFont(new Font("黑体",Font.BOLD,22)); chart.getLegend().setItemFont(new Font("黑体",Font.BOLD,22)); /*字体乱码异常解决代码*/ PiePlot pieplot = (PiePlot)chart.getPlot(); //设置网格背景颜色 pieplot.setBackgroundPaint(Color.white); //设置图表标签字体 pieplot.setLabelFont(new Font("宋体",Font.BOLD,22)); pieplot.setNoDataMessage("No data available"); //pieplot.setCircular(true); //pieplot.setLabelGap(0.01D);//间距 StandardEntityCollection sec = new StandardEntityCollection(); ChartRenderingInfo info = new ChartRenderingInfo(sec); PrintWriter w = new PrintWriter(out);//输出MAP信息 //500是图片长度,300是图片高度 String filename = ServletUtilities.saveChartAsPNG(chart, 800, 400, info, session); ChartUtilities.writeImageMap(w, "map0", info, false); String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename; %> <P ALIGN="CENTER"> <img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#map0"> </P> </BODY> </HTML>
|
|
来自: oospace > 《jFreeChart(图表插件)》