此内容仅用于备份,如果您看不懂,敬请谅解!
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>