⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statchart.java

📁 JFreechart 饼图源代码
💻 JAVA
字号:
package com.mwq.chart;

import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspWriter;

import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;

/**
 * @author mwq
 * 
 */
public class StatChart {

	protected int width = 540;// 图象宽度

	protected int height = 380; // 图象高度

	protected String chartTitle;// 图表标题

	protected String subtitle;// 副标题

	protected String mapName;// map名称

	protected String contextPath = "";// 容器路径

	protected String servletURI = "/servlet/DisplayChart";// 映射路径

	protected JspWriter out;// out实例

	protected HttpSession session;// Session实例

	protected JFreeChart chart;// 图表实例

	private String fileName;

	private String graphURL;

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

	// 定义图片
	protected void defineChart() {

		chart.setBackgroundPaint(new GradientPaint(0, 0, Color.YELLOW, 0,
				height, Color.GREEN, false));

		TextTitle title = chart.getTitle();
		title.setFont(new Font("汉真广标", Font.BOLD, 21));
		title.setPaint(Color.RED);

		if (subtitle.length() > 0) {
			chart.addSubtitle(new TextTitle("——" + subtitle));
		}

	}

	// 定义绘图区
	protected void definePlot() {

	}

	// 生成图片
	protected String draw() {
		return null;
	}

	// 绘制普通图表
	protected String drawCommon() {
		try {
			fileName = ServletUtilities.saveChartAsPNG(chart, width, height,
					info, session);
		} catch (IOException e) {
			System.out.println("------ 在绘制图片时抛出异常,内容如下:");
			e.printStackTrace();
		}
		graphURL = contextPath + servletURI + "?filename=" + fileName;
		return graphURL;
	}

	// 绘制热点图表
	protected String drawHotspot(boolean useOverLibForToolTips) {
		PrintWriter printWriter = new PrintWriter(out);
		try {
			fileName = ServletUtilities.saveChartAsPNG(chart, width, height,
					info, session);
			ChartUtilities.writeImageMap(printWriter, mapName, info,
					useOverLibForToolTips);
		} catch (IOException e) {
			System.out.println("------ 在绘制图片时抛出异常,内容如下:");
			e.printStackTrace();
		}
		graphURL = contextPath + servletURI + "?filename=" + fileName;
		return graphURL;
	}

	/**
	 * @param chartTitle
	 *            要设置的 chartTitle
	 */
	public void setChartTitle(String chartTitle) {
		this.chartTitle = chartTitle;
	}

	/**
	 * @param contextPath
	 *            要设置的 contextPath
	 */
	public void setContextPath(String contextPath) {
		this.contextPath = contextPath;
	}

	/**
	 * @param height
	 *            要设置的 height
	 */
	public void setHeight(int height) {
		this.height = height;
	}

	/**
	 * @param session
	 *            要设置的 session
	 */
	public void setSession(HttpSession session) {
		this.session = session;
	}

	/**
	 * @param subtitle
	 *            要设置的 subtitle
	 */
	public void setSubtitle(String subtitle) {
		this.subtitle = subtitle;
	}

	/**
	 * @param width
	 *            要设置的 width
	 */
	public void setWidth(int width) {
		this.width = width;
	}

	/**
	 * @param mapName
	 *            要设置的 mapName
	 */
	public void setMapName(String mapName) {
		this.mapName = mapName;
	}

	/**
	 * @param out
	 *            要设置的 out
	 */
	public void setOut(JspWriter out) {
		this.out = out;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -