此内容仅用于备份,如果您看不懂,敬请谅解!
jfreechart manager:
package cn.com.samsung.jfreechart;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.GeneralPath;
import java.io.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import javax.servlet.http.HttpSession;
import org.jfree.data.general.PieDataset;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.RectangleEdge;
import org.jfree.chart.*;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.DateTickUnit;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.servlet.ServletUtilities;
public class JFreeChartManager {
/**
* TimeseriesChart With "Member Index"
*/
public static String generateTimeseriesChartWithMemberIndex(TimeSeriesCollection dataset,
HttpSession session, PrintWriter pw, int w, int h) {
String filename = null;
JFreeChart chart = ChartFactory.createTimeSeriesChart("", // title
"", // x title
"", // y title
dataset, // dateset
true, // showLegend flag
false, //
false // show URL link flag
);
chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
/*------------configure chart properties--------------*/
// 1 set background and border
chart.setBackgroundPaint(Color.white);
chart.setBorderVisible(false);
/*------------configure Plot properties-------------*/
XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.black);
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinePaint(Color.black);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlineStroke(new BasicStroke(1.0F));
plot.setOutlineVisible(false);
DateAxis dateaxis = (DateAxis) plot.getDomainAxis();
int interval=1;
int dataSize=dataset.getSeries(0).getItemCount();
if(dataSize>10&&dataSize<=20) interval=2;
else if(dataSize>20) interval=4;
dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, interval),false,true);
dateaxis.setDateFormatOverride(new SimpleDateFormat("M/d"));
XYLineAndShapeRenderer lasp = (XYLineAndShapeRenderer)plot.getRenderer();
lasp.setBaseShapesVisible(true);
lasp.setDrawOutlines(true);
lasp.setSeriesStroke(0, new BasicStroke(3F));
lasp.setSeriesOutlineStroke(0, new BasicStroke(2.0F));
lasp.setSeriesPaint(0, new Color(0xe49694));
lasp.setSeriesShape(0, new Rectangle(-2,-2,5,5));
lasp.setSeriesStroke(1, new BasicStroke(3F));
lasp.setSeriesOutlineStroke(1, new BasicStroke(4.0F));
lasp.setSeriesPaint(1, new Color(0xc4d79b));
GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
path.moveTo(0, -2.5);
path.lineTo(2.5, 2.5);
path.lineTo(-2.5, 2.5);
path.lineTo(0, -2.5);
path.closePath();
lasp.setSeriesShape(1, path);
lasp.setSeriesStroke(2, new BasicStroke(3F));
lasp.setSeriesOutlineStroke(2, new BasicStroke(2.0F));
lasp.setSeriesPaint(2, new Color(0xb1a0c7));
lasp.setSeriesShape(2, new Rectangle(-2,-2,5,5));
chart.getLegend().setVisible(true);
chart.getLegend().setPosition(RectangleEdge.RIGHT);
chart.getLegend().setBorder(-1, -1, -1, -1);
try {
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(chart, w, h, info,
session);
ChartUtilities.writeImageMap(pw, filename, info, true);
pw.flush();
} catch (IOException e) {
e.printStackTrace();
}
return filename;
}
/**
* 时序图 Call Index
*/
public static String generateTimeseriesChartWithCallIndex(TimeSeriesCollection dataset,
HttpSession session, PrintWriter pw, int w, int h) {
String filename = null;
JFreeChart chart = ChartFactory.createTimeSeriesChart("",
"",
"",
dataset,
true,
false,
false
);
chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
chart.setBackgroundPaint(Color.white);
chart.setBorderVisible(false);
XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.black);
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinePaint(Color.black);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlineStroke(new BasicStroke(1.0F));
plot.setOutlineVisible(false);
DateAxis dateaxis = (DateAxis) plot.getDomainAxis();
int interval=1;
int dataSize=dataset.getSeries(0).getItemCount();
if(dataSize>10&&dataSize<=20) interval=2;
else if(dataSize>20) interval=4;
dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, interval));
dateaxis.setDateFormatOverride(new SimpleDateFormat("M/d"));
XYLineAndShapeRenderer lasp = (XYLineAndShapeRenderer)plot.getRenderer();
lasp.setBaseShapesVisible(true);
lasp.setDrawOutlines(true);
lasp.setSeriesStroke(0, new BasicStroke(3F));
lasp.setSeriesOutlineStroke(0, new BasicStroke(6.0F));
lasp.setSeriesPaint(0, new Color(0x8db4e2));
GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
path.moveTo(0, -3);
path.lineTo(3, 0);
path.lineTo(0, 3);
path.lineTo(3, 0);
path.lineTo(0, -3);
path.closePath();
lasp.setSeriesShape(0, path);
lasp.setSeriesStroke(1, new BasicStroke(3F));
lasp.setSeriesOutlineStroke(1, new BasicStroke(2.0F));
lasp.setSeriesPaint(1, new Color(0xe49694));
lasp.setSeriesShape(1, new Rectangle(-2,-2,5,5));
chart.getLegend().setVisible(true);
chart.getLegend().setPosition(RectangleEdge.RIGHT);
chart.getLegend().setBorder(-1, -1, -1, -1);
try {
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(chart, w, h, info,
session);
ChartUtilities.writeImageMap(pw, filename, info, true);
pw.flush();
} catch (IOException e) {
e.printStackTrace();
}
return filename;
}
/**
* 饼状图 memberDetail
*/
public static String generatePieChartWithMemberDetail(PieDataset dataset ,HttpSession session, PrintWriter pw,
int w, int h) {
String filename = null;
StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
standardChartTheme.setExtraLargeFont(new Font("宋书", Font.BOLD, 20));
standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 12));
standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 15));
ChartFactory.setChartTheme(standardChartTheme);
JFreeChart chart = ChartFactory.createPieChart3D("Member Portion by Top 5 Regions",
dataset,
true,
false,
false
);
chart.setBackgroundPaint(Color.white);
chart.setBorderVisible(false);
PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setBackgroundPaint(new Color(0, 0, 0, 0));
chart.getLegend().setPosition(RectangleEdge.RIGHT);
chart.getLegend().setBackgroundPaint(Color.white);
chart.getLegend().setBorder(-1,-1,-1,-1);
plot.setSectionOutlinesVisible(false);
plot.setDepthFactor(0.0d);
plot.setCircular(true);
plot.setLegendItemShape(new Rectangle(-2,-2,4,4));
/*
* 1st row -> #8db4e2
* 2nd row -> #e49694
* 3rd row -> #c4d79b
* 4th row -> #b1a0c7
* 5th row -> #8dcadb
*/
plot.setSectionPaint(dataset.getKey(0), new Color(0x8db4e2));
plot.setSectionPaint(dataset.getKey(1), new Color(0xe49694));
plot.setSectionPaint(dataset.getKey(2), new Color(0xc4d79b));
plot.setSectionPaint(dataset.getKey(3), new Color(0xb1a0c7));
plot.setSectionPaint(dataset.getKey(4), new Color(0x8dcadb));
plot.setLabelGenerator(new StandardPieSectionLabelGenerator(("{2}"),
NumberFormat.getNumberInstance(), new DecimalFormat("0.0%")));
plot.setLabelBackgroundPaint(Color.white);
plot.setLabelLinksVisible(false);
plot.setOutlineVisible(false);
plot.setSimpleLabels(true);
plot.setMaximumLabelWidth(0.0);
plot.setLabelBackgroundPaint(new Color(0, 0, 0, 0));
plot.setLabelShadowPaint(new Color(0, 0, 0, 0));
plot.setLabelOutlinePaint(new Color(0, 0, 0, 0));
try {
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(chart, w, h, info,
session);
ChartUtilities.writeImageMap(pw, filename, info, true);
pw.flush();
} catch (IOException e) {
e.printStackTrace();
}
return filename;
}
/**
* 饼状图 callDetail
*/
public static String generatePieChartWithCallDetail(PieDataset dataset ,HttpSession session, PrintWriter pw,
int w, int h) {
String filename = null;
StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
standardChartTheme.setExtraLargeFont(new Font("宋书", Font.BOLD, 20));
standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 12));
standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 15));
ChartFactory.setChartTheme(standardChartTheme);
JFreeChart chart = ChartFactory.createPieChart3D("Call Portion by Top 5 Regions",
dataset,
true,
false,
false
);
chart.setBackgroundPaint(Color.white);
chart.setBorderVisible(false);
PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setBackgroundPaint(new Color(0, 0, 0, 0));
chart.getLegend().setPosition(RectangleEdge.RIGHT);
chart.getLegend().setBackgroundPaint(Color.white);
chart.getLegend().setBorder(-1,-1,-1,-1);
plot.setSectionOutlinesVisible(false);
plot.setDepthFactor(0.0d);
plot.setCircular(true);
plot.setLegendItemShape(new Rectangle(-2,-2,4,4));
/* 1st: North America : #8db4e2
2nd: MENA : #e49694
3rd: Europe : #c4d79b
4th: S.E.Asia : #b1a0c7
5th: LATAM : #8dcadb*/
plot.setSectionPaint(dataset.getKey(0), new Color(0x8db4e2));
plot.setSectionPaint(dataset.getKey(1), new Color(0xe49694));
plot.setSectionPaint(dataset.getKey(2), new Color(0xc4d79b));
plot.setSectionPaint(dataset.getKey(3), new Color(0xb1a0c7));
plot.setSectionPaint(dataset.getKey(4), new Color(0x8dcadb));
plot.setLabelGenerator(new StandardPieSectionLabelGenerator(("{2}"),
NumberFormat.getNumberInstance(), new DecimalFormat("0.0%")));
plot.setLabelBackgroundPaint(Color.white);
plot.setLabelLinksVisible(false);
plot.setOutlineVisible(false);
plot.setSimpleLabels(true);
plot.setMaximumLabelWidth(0.0);
plot.setLabelBackgroundPaint(new Color(0, 0, 0, 0));
plot.setLabelShadowPaint(new Color(0, 0, 0, 0));
plot.setLabelOutlinePaint(new Color(0, 0, 0, 0));
try {
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(chart, w, h, info,
session);
ChartUtilities.writeImageMap(pw, filename, info, true);
pw.flush();
} catch (IOException e) {
e.printStackTrace();
}
return filename;
}
/**
* 饼状图CallDistribution
*/
public static String generatePieChartWithCallDistribution(PieDataset dataset ,HttpSession session, PrintWriter pw,
int w, int h) {
String filename = null;
StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
standardChartTheme.setExtraLargeFont(new Font("宋书", Font.BOLD, 20));
standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 12));
standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 15));
ChartFactory.setChartTheme(standardChartTheme);
JFreeChart chart = ChartFactory.createPieChart3D("Call Portion by Call Activities",
dataset,
true,
false,
false
);
chart.setBackgroundPaint(Color.white);
chart.setBorderVisible(false);
PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setBackgroundPaint(new Color(0, 0, 0, 0));
chart.getLegend().setPosition(RectangleEdge.RIGHT);
chart.getLegend().setBackgroundPaint(Color.white);
chart.getLegend().setBorder(-1,-1,-1,-1);
plot.setSectionOutlinesVisible(false);
plot.setDepthFactor(0.0d);
plot.setCircular(true);
plot.setLegendItemShape(new Rectangle(-2,-2,4,4));
/*
* 1:1 Voice : #8db4e2
1:1 Video : #e49694
Group Video : #b1a0c7
Group Voice : #c4d79b
* */
plot.setSectionPaint(dataset.getKey(0), new Color(0x8db4e2));
plot.setSectionPaint(dataset.getKey(1), new Color(0xe49694));
plot.setSectionPaint(dataset.getKey(2), new Color(0xb1a0c7));
plot.setSectionPaint(dataset.getKey(3), new Color(0xc4d79b));
plot.setLabelGenerator(new StandardPieSectionLabelGenerator(("{2}"),
NumberFormat.getNumberInstance(), new DecimalFormat("0.0%")));
plot.setLabelBackgroundPaint(Color.white);
plot.setLabelLinksVisible(false);
plot.setOutlineVisible(false);
plot.setSimpleLabels(true);
plot.setMaximumLabelWidth(0.0);
plot.setLabelBackgroundPaint(new Color(0, 0, 0, 0));
plot.setLabelShadowPaint(new Color(0, 0, 0, 0));
plot.setLabelOutlinePaint(new Color(0, 0, 0, 0));
try {
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(chart, w, h, info,
session);
ChartUtilities.writeImageMap(pw, filename, info, true);
pw.flush();
} catch (IOException e) {
e.printStackTrace();
}
return filename;
}
}
------------------------------------------------------------
Action:
package cn.com.samsung.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import cn.com.samsung.common.util.DateFormatUtil;
import cn.com.samsung.common.util.NumberFormatUtil;
import cn.com.samsung.jfreechart.JFreeChartManager;
import cn.com.samsung.service.ExportDatasForSDSService;
import cn.com.samsung.service.SummaryService;
import cn.com.samsung.vo.CallDetail;
import cn.com.samsung.vo.CallDetailShow;
import cn.com.samsung.vo.CallDistribution;
import cn.com.samsung.vo.CallIndex;
import cn.com.samsung.vo.MemberDetail;
import cn.com.samsung.vo.MemberDetailShow;
import cn.com.samsung.vo.SummaryIndex;
import cn.com.samsung.vo.SummaryIndexShow;
import com.opensymphony.xwork2.ActionSupport;
public class QueryAction extends ActionSupport{
private static final long serialVersionUID = -4607825750752176326L;
private SummaryService summaryService;
private String fileName;
private String graphURL;
private String graphTitle;
private ExportDatasForSDSService exportSdsService;
private static Logger log = Logger.getLogger(LoginAction.class);
private String startDt;
private String endDt;
private String week;
private List<SummaryIndexShow> summaryIndexList;
private List<MemberDetailShow> memberDetailList;
private List<CallIndex> callIndexList;
private List<CallDetailShow> callDetailList;
private List<CallDetailShow> voiceList;
private List<CallDetailShow> voiceGroupList;
private List<CallDetailShow> videoList;
private List<CallDetailShow> videoGroupList;
private List<CallDistribution> callDistributionList;
private CallDistribution callTotalDistributionBean = new CallDistribution();
public CallDistribution getCallTotalDistributionBean() {
return callTotalDistributionBean;
}
public void setCallTotalDistributionBean(
CallDistribution callTotalDistributionBean) {
this.callTotalDistributionBean = callTotalDistributionBean;
}
public List<CallDistribution> getCallDistributionList() {
return callDistributionList;
}
public void setCallDistributionList(
List<CallDistribution> callDistributionList) {
this.callDistributionList = callDistributionList;
}
public List<CallDetailShow> getVoiceList() {
return voiceList;
}
public void setVoiceList(List<CallDetailShow> voiceList) {
this.voiceList = voiceList;
}
public List<CallDetailShow> getVoiceGroupList() {
return voiceGroupList;
}
public void setVoiceGroupList(List<CallDetailShow> voiceGroupList) {
this.voiceGroupList = voiceGroupList;
}
public List<CallDetailShow> getVideoList() {
return videoList;
}
public void setVideoList(List<CallDetailShow> videoList) {
this.videoList = videoList;
}
public List<CallDetailShow> getVideoGroupList() {
return videoGroupList;
}
public void setVideoGroupList(List<CallDetailShow> videoGroupList) {
this.videoGroupList = videoGroupList;
}
public List<CallDetailShow> getCallDetailList() {
return callDetailList;
}
public void setCallDetailList(List<CallDetailShow> callDetailList) {
this.callDetailList = callDetailList;
}
public List<CallIndex> getCallIndexList() {
return callIndexList;
}
public void setCallIndexList(List<CallIndex> callIndexList) {
this.callIndexList = callIndexList;
}
public List<MemberDetailShow> getMemberDetailList() {
return memberDetailList;
}
public void setMemberDetailList(List<MemberDetailShow> memberDetailList) {
this.memberDetailList = memberDetailList;
}
public String getWeek() {
return week;
}
public void setWeek(String week) {
this.week = week;
}
public String getGraphURL() {
return graphURL;
}
public void setGraphURL(String graphURL) {
this.graphURL = graphURL;
}
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public List<SummaryIndexShow> getSummaryIndexList() {
return summaryIndexList;
}
public void setSummaryIndexList(List<SummaryIndexShow> summaryIndexList) {
this.summaryIndexList = summaryIndexList;
}
public String getEndDt() {
return endDt;
}
public void setEndDt(String endDt) {
this.endDt = endDt;
}
public String getStartDt() {
return startDt;
}
public void setStartDt(String startDt) {
this.startDt = startDt;
}
public SummaryService getSummaryService() {
return summaryService;
}
public void setSummaryService(SummaryService summaryService) {
this.summaryService = summaryService;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getGraphTitle() {
return graphTitle;
}
public void setGraphTitle(String graphTitle) {
this.graphTitle = graphTitle;
}
/**
* Member Index action -zq.wu
* @return
*/
public String memberIndexChart()
{
// 时序图调用开始----------------------
List<SummaryIndex>list =summaryService.getMemberIndexChartList(startDt, endDt);
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
TimeSeries timeSeries1 = new TimeSeries("Total Member", Day.class);
TimeSeries timeSeries2 = new TimeSeries("New Member", Day.class);
TimeSeries timeSeries3 = new TimeSeries("Active User", Day.class);
SimpleDateFormat mdd = new SimpleDateFormat("yyyyMMdd");
for(SummaryIndex sib:list)
{
String x=sib.getDailyDate();
try {
timeSeries1.addOrUpdate(new Day(mdd.parse(x)), sib.getTotal_members());
timeSeries2.addOrUpdate(new Day(mdd.parse(x)), sib.getNew_members());
timeSeries3.addOrUpdate(new Day(mdd.parse(x)), sib.getActive_users());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
lineDataset.addSeries(timeSeries1);
lineDataset.addSeries(timeSeries2);
lineDataset.addSeries(timeSeries3);
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session=request.getSession();
Writer out=null;
try {
out = ServletActionContext.getResponse().getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fileName=JFreeChartManager.generateTimeseriesChartWithMemberIndex(lineDataset,session, new PrintWriter(out),686 ,245);
graphURL=request.getContextPath() + "/DisplayChart.do?filename=" + fileName;
return "success";
}
/**
* Member Detail action - by zq.wu
* @return
*/
public String memberDetailChart()
{
List<MemberDetail>list =summaryService.getMemberDetailTableList(startDt, endDt);
DefaultPieDataset dataset = new DefaultPieDataset();
int count=0;
for(MemberDetail mdb:list)
{
count++;
dataset.setValue(mdb.getRegion(), mdb.getTotalMembers());
if(count==5) break;
}
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session=request.getSession();
Writer out=null;
try {
out = ServletActionContext.getResponse().getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fileName=JFreeChartManager.generatePieChartWithMemberDetail(dataset,session,new PrintWriter(out),556,302);
graphURL = request.getContextPath() + "/DisplayChart.do?filename=" + fileName;
return "success";
}
/**
* Call Index action -zq.wu
* @return
*/
public String callIndexChart()
{
List<CallIndex>list =summaryService.getCallIndexTable(startDt, endDt);
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
TimeSeries timeSeries1 = new TimeSeries("Total Call", Day.class);
TimeSeries timeSeries2 = new TimeSeries("Active Caller", Day.class);
SimpleDateFormat mdd = new SimpleDateFormat("yyyyMMdd");
for(CallIndex sib:list)
{
String x=sib.getDailyDate();
try {
timeSeries1.addOrUpdate(new Day(mdd.parse(x)), sib.getTotalCall());
timeSeries2.addOrUpdate(new Day(mdd.parse(x)), sib.getActiveCaller());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
lineDataset.addSeries(timeSeries1);
lineDataset.addSeries(timeSeries2);
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session=request.getSession();
Writer out=null;
try {
out = ServletActionContext.getResponse().getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fileName=JFreeChartManager.generateTimeseriesChartWithCallIndex(lineDataset,session, new PrintWriter(out),657,250);
graphURL=request.getContextPath() + "/DisplayChart.do?filename=" + fileName;
return "success";
}
/**
* call Distribution action - by zq.wu
* @return
*/
public String callDistributionChart()
{
List<CallDistribution>list =summaryService.getCallDistributionByActivity(startDt, endDt);
DefaultPieDataset dataset = new DefaultPieDataset();
int count=0;
for(CallDistribution mdb:list)
{
count++;
dataset.setValue(mdb.getActivityShow(), mdb.getCallCase());
if(count==4) break;
}
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session=request.getSession();
Writer out=null;
try {
out = ServletActionContext.getResponse().getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fileName=JFreeChartManager.generatePieChartWithCallDistribution(dataset,session,new PrintWriter(out),558,301);
graphURL = request.getContextPath() + "/DisplayChart.do?filename=" + fileName;
return "success";
}
/**
* call Detail action - by zq.wu
* @return
*/
public String callDetailChart()
{
List<CallDetail>list =summaryService.getCallDetailTable(startDt, endDt);
DefaultPieDataset dataset = new DefaultPieDataset();
int count=0;
for(CallDetail mdb:list)
{
count++;
dataset.setValue(mdb.getRegion(), mdb.getTotalCall());
if(count==5) break;
}
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session=request.getSession();
Writer out=null;
try {
out = ServletActionContext.getResponse().getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fileName=JFreeChartManager.generatePieChartWithCallDetail(dataset,session,new PrintWriter(out),558,301);
graphURL = request.getContextPath() + "/DisplayChart.do?filename=" + fileName;
return "success";
}
public ExportDatasForSDSService getExportSdsService() {
return exportSdsService;
}
public void setExportSdsService(ExportDatasForSDSService exportSdsService) {
this.exportSdsService = exportSdsService;
}
public String search(){
try {
summaryIndexList = summaryService.getMemeberIndexTableList(startDt, endDt);
} catch (ParseException e1) {
log.error(e1.getMessage());
}
memberDetailList = summaryService.getMemberDetailTableShowList(startDt, endDt);
callIndexList = summaryService.getCallIndexTable(startDt, endDt);
callDetailList = summaryService.getCallDetailTableShowList(startDt, endDt);
videoGroupList = summaryService.getGroupVideoTableList(startDt, endDt);
videoList = summaryService.getVideoTableList(startDt, endDt);
voiceList = summaryService.getVoiceTableList(startDt, endDt);
voiceGroupList = summaryService.getGroupVoiceTableList(startDt, endDt);
callDistributionList = summaryService.getCallDistributionByActivity(startDt, endDt);
int sumTotal = 0;
int sumCase = 0;
double sumPortion = 0;
int sumSuccess = 0;
for(CallDistribution bean : callDistributionList){
sumTotal += bean.getTotal();
sumSuccess += bean.getSucceedCall();
sumCase += bean.getCallCase();
sumPortion += Double.parseDouble(bean.getPortion());
}
callTotalDistributionBean.setTotalShow(DateFormatUtil.converIntToTime(sumTotal));
callTotalDistributionBean.setAverageShow(DateFormatUtil.converIntToTime(Integer.parseInt(NumberFormatUtil.getDoubleFormat00(sumTotal/sumSuccess))));
callTotalDistributionBean.setCallCaseShow(NumberFormatUtil.getIntFormat(sumCase));
callTotalDistributionBean.setPortion(NumberFormatUtil.getDoubleFormat(sumPortion));
try {
week = DateFormatUtil.getWeekFormat(startDt, endDt);
startDt = DateFormatUtil.getDateFormatByFormat(DateFormatUtil.yyyyMMddToDate(startDt), "yyyy-MM-dd");
endDt = DateFormatUtil.getDateFormatByFormat(DateFormatUtil.yyyyMMddToDate(endDt), "yyyy-MM-dd");
} catch (ParseException e) {
log.error(e.getMessage());
}
return "success";
}
}
--------------------------------------------
web.xml
<servlet>
<servlet-name>DisplayChart</servlet-name>
<servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DisplayChart</servlet-name>
<url-pattern>/DisplayChart.do</url-pattern>
</servlet-mapping>
------------------------------------------------
jsp:
<%@ page contentType="text/html; charset=utf-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Graph</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/admin.css" />
</head>
<body>
<div>
<div style="height: 30px;min-width:657px; background-color: gray;margin-top: 10px;margin-left: 20px;margin-right: 20px;line-height: 30px">
<p style="color: white;font-size: medium;vertical-align: middle;margin-left: 10px">${graphTitle }</p>
</div>
<div style="border: 1px;;border-color: black;border-style: solid;margin-top: 10px;margin-left: 20px;margin-right: 20px">
<img src="${graphURL}" Width=657px Height=250px border=0 usemap="#jfreechart-210993337828561595.png" >
</div>
<div align="left" style="margin-top: 10px;margin-left: 20px;margin-right: 20px">
<a href="#" id="closeBtn" class="btn" onclick="window.close()"><span>Close</span></a>
</div>
</div>
</body>
</html>
相关推荐
JFreeChart的使用,需要导入的2个jar文件: jcommon-1.0.23.jar和jfreechart-1.0.19.jar。 可以去官网下载:http://sourceforge.net/projects/jfreechart/files/ 上传以作后续使用时备份.
至于"~jfreechart-1.0.9-demo.jar",这是一个可能的备份或临时文件,通常在编辑或处理原始jar文件时创建,以防止意外覆盖原始数据。 总的来说,这个压缩包提供了一套完整的工具和资源,帮助用户通过JAD反编译...
1. **备份原始文件**:在进行任何修改之前,请确保备份原始jar文件及其中的内容。 2. **兼容性问题**:在修改过程中,要注意保持与Struts2和其他依赖库的兼容性。 3. **版本控制**:建议使用版本控制系统(如Git)来...
这个压缩包文件“struts2+hibernate+spring+jfreechart+导出excel+导出pdf完美整合.zip”显然是一个整合了这些技术的示例项目,用于演示如何在实际开发中实现数据处理、视图展示以及文件导出功能。 首先,Struts2 ...
2. **JXL库**: JXL是Java Excel的简称,是一个开源库,用于读写Microsoft Excel文件。在人力资源管理系统中,JXL库被用来导入和导出员工信息,便于数据的存储和备份。它可以方便地处理Excel工作簿、工作表和单元格,...
2. `questionnaire.sql`:这是一个SQL脚本文件,可能包含了创建数据库表结构、初始化数据或者备份恢复的命令。用户可以通过执行这个文件来设置或恢复投票系统的数据库。 3. `webvote`:这很可能是项目的Web应用根...
这种命名方式常见于备份或项目文件归档,方便追踪文件的时间线。 【描述】提到这个压缩包是“几套前端可视化模板”,这意味着它可能包含了一系列用于构建用户界面的图形和图表模板,这些模板专门设计用于数据可视化...
6. **license-rhino.txt, license-jgraph.txt, license-jfreechart.txt, license-batik.txt**: 这些文件分别对应于SQL Developer中使用的第三方库的许可证信息,如Rhino JavaScript引擎、JGraph图形库、JFreeChart...
- **JFreeChart组件在基于JSP的Web统计图表中的应用与实现.doc**:JFreeChart是Java的一个图表库,可用于创建动态的Web统计图表。 - **J2EE中文全面简介.doc**:J2EE(现在称为Java EE)是企业级Java应用的标准...
4. **文件I/O**: 读写数据到本地文件,例如备份或导出财务报告。 5. **异常处理**: 编程中对可能出现错误的预防和处理,确保系统稳定运行。 6. **多线程**: 收入和支出的并发处理,保证数据一致性。 7. **数据验证**...
复制`.gpscoffee`文件的操作可能是为了备份数据、传输到其他设备或进行数据分析。 在Java环境中处理这类文件,我们需要了解几个关键点: 1. **文件读取**:使用Java的`java.io`包中的`FileInputStream`和`...
Struts2.0的核心优势在于其灵活性和扩展性,它支持拦截器、类型转换、文件上传/下载等功能,使得开发者可以更加专注于业务逻辑的实现而非框架本身。 ##### Hibernate3.3 Hibernate是一种面向对象的持久化框架,它...
Java的JavaFX和JFreeChart库提供了丰富的图表绘制功能,包括3D效果的饼图、柱图和甘特图。这些工具在数据可视化和报告制作中不可或缺,帮助用户直观理解复杂的数据信息。 6. 图像处理: Java的Java Advanced ...
如果使用JFreeChart图形功能,则需要jfreechart-1.0.13-swt.jar、jfreechart-1.0.13.jar、jfreechart-1.0.13-experimental.jar和jcommon-1.0.0.jar等jar包。 iReport的使用可以分为入门篇和提高篇。入门篇主要介绍...
6. 数据备份与恢复:为防止数据丢失,系统需有定期备份和恢复机制。Java的文件操作API和数据库连接池可以帮助实现这一功能。 总的来说,“snowy-layui-master.zip”压缩包中的代码文件展示了如何利用Java和LayUI...
【fantasyCrm.dmp】:这是一个Oracle数据库的导出文件,可能包含了CRM系统的初始数据或备份数据,方便系统部署和数据恢复。 【用户文档.doc】:这个文档应该是系统用户手册,详细介绍了系统的使用方法、功能特性,...
“统计图”功能通常需要利用图形库,例如JFreeChart或JFXGraph,这些库能够生成各种类型的图表,如柱状图、饼图、线图等,用于直观地展示数据。在Swing应用中,这些图表可以嵌入到JFrame或JPanel中,以提供丰富的...
- **数据备份与移植**:掌握数据库的备份策略和数据迁移技巧。 4. **中间件与框架**: - **JDBC基础**:学习数据库连接,执行SQL语句,以及数据处理。 - **连接池技术**:理解数据库连接池的作用,如C3P0、DBCP...
在统计分析方面,系统可能运用了Apache POI库来处理Excel文件,用户可以导出收支报表以便于进一步分析或备份。此外,系统也可能利用JFreeChart或ECharts等图表库,生成周、月度的收支对比图,帮助用户追踪财务变化...