MyException - 我的异常网
当前位置:我的异常网» J2EE » 用jsp怎的生成柱状图,饼状图,折线图

用jsp怎的生成柱状图,饼状图,折线图(2)

www.MyException.Cn  网友分享于:2013-12-22  浏览:982次

------解决方案--------------------
不用插件只能用纯脚本画了
------解决方案--------------------
补充,加载jfreechart-1.0.1.jar,我用过了,没冲突,可以用!
------解决方案--------------------
package cn.longhaul.zchart;

import java.awt.Color;
import java.awt.Font;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import javax.servlet.http.HttpSession;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.RectangleInsets;

/**
 * 曲线图的绘制
 */
public class LineXYChart {
/**
* 返回生成图片的文件名

* @param session
* @param pw
* @return 生成图片的文件名
*/
public String getLineXYChart(HttpSession session, PrintWriter pw,ArrayList data) {
XYDataset dataset = this.createDateSet(data);// 建立数据集
String fileName = null;
// 建立JFreeChart
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"销售时间曲线序列图", // title
"Date", // x-axis label
"Price", // y-axis label
dataset, // data
true, // create legend?
true, // generate tooltips?
false // generate URLs?
);
// 设置JFreeChart的显示属性,对图形外部部分进行调整
chart.setBackgroundPaint(Color.red);// 设置曲线图背景色
// 设置字体大小,形状
Font font = new Font("宋体", Font.BOLD, 12);
TextTitle title = new TextTitle("销售时间曲线序列图", font);
chart.setTitle(title);
// 副标题
//TextTitle subtitle = new TextTitle(deptname, new Font("黑体", Font.BOLD, 12));
//chart.addSubtitle(subtitle);
chart.setTitle(title); // 标题
// 设置图示标题字符
// TimeSeries s1 = new TimeSeries("历史曲线", Day.class);该中文字符
LegendTitle legengTitle = chart.getLegend();
legengTitle.setItemFont(font);
XYPlot plot = (XYPlot) chart.getPlot();// 获取图形的画布
plot.setBackgroundPaint(Color.lightGray);// 设置网格背景色
plot.setDomainGridlinePaint(Color.green);// 设置网格竖线(Domain轴)颜色
plot.setRangeGridlinePaint(Color.white);// 设置网格横线颜色
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));// 设置曲线图与xy轴的距离
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
XYItemRenderer r = plot.getRenderer();
if (r instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
renderer.setBaseShapesVisible(true);
renderer.setBaseShapesFilled(true);
renderer.setShapesVisible(true);// 设置曲线是否显示数据点
}
// 设置Y轴
NumberAxis numAxis = (NumberAxis) plot.getRangeAxis();
NumberFormat numFormater = NumberFormat.getNumberInstance();
numFormater.setMinimumFractionDigits(2);
numAxis.setNumberFormatOverride(numFormater);
// 设置提示信息
StandardXYToolTipGenerator tipGenerator = new StandardXYToolTipGenerator(

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有