📄 charservlet.java
字号:
package com.web;
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.general.WaferMapDataset;
import org.jfree.util.TableOrder;
import com.domain.DatasetObj;
import com.service.CharService;
import com.service.impl.CharServiceImpl;
import com.util.ChartData;
public class CharServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private String reportpath;
private String imagepath;
private String type = "";
private String pagepath = "report.jsp";
private String image;
private DatasetObj datasetObj;
private CharService charimpl = new CharServiceImpl();
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
reportpath = request.getSession().getServletContext().getRealPath("/")
+ "report/";
imagepath = request.getContextPath() + "/report/";
isChartPathExist(reportpath);
type = request.getParameter("status");
if ("line2DChar".equals(type)) {
line2DChar(request, response);
} else if ("line3DChar".equals(type)) {
line3DChar(request, response);
} else if ("lineDataPointChar".equals(type)) {
lineDataPointChar(request, response);
} else if ("areaChar".equals(type)) {
areaChar(request, response);
} else if ("areaStackedChar".equals(type)) {
areaStackedChar(request, response);
} else if ("areaDataPointChar".equals(type)) {
areaDataPointChar(request, response);
} else if ("areaDataStepChar".equals(type)) {
areaDataStepChar(request, response);
} else if ("areaDataStackedChar".equals(type)) {
areaDataStackedChar(request, response);
} else if ("bar2DChar".equals(type)) {
bar2DChar(request, response);
} else if ("bar3DChar".equals(type)) {
bar3DChar(request, response);
} else if ("barLine2DChar".equals(type)) {
barLine2DChar(request, response);
} else if ("barLine3DChar".equals(type)) {
barLine3DChar(request, response);
} else if ("bar2DStackedChar".equals(type)) {
bar2DStackedChar(request, response);
} else if ("bar3DStackedChar".equals(type)) {
bar3DStackedChar(request, response);
} else if ("barDataPointChar".equals(type)) {
barDataPointChar(request, response);
} else if ("pie2DChar".equals(type)) {
pie2DChar(request, response);
} else if ("pie3DChar".equals(type)) {
pie3DChar(request, response);
} else if ("pie2DMultipleChar".equals(type)) {
pie2DMultipleChar(request, response);
} else if ("pie3DMultipleChar".equals(type)) {
pie3DMultipleChar(request, response);
} else if ("ringChar".equals(type)) {
ringChar(request, response);
} else if ("scatterChar".equals(type)) {
scatterChar(request, response);
} else if ("histogramChar".equals(type)) {
histogramChar(request, response);
} else if ("bubbleChar".equals(type)) {
bubbleChar(request, response);
} else if ("ganttChar".equals(type)) {
ganttChar(request, response);
} else if ("highLowChar".equals(type)) {
highLowChar(request, response);
} else if ("candlestickChar".equals(type)) {
candlestickChar(request, response);
} else if ("polarChar".equals(type)) {
polarChar(request, response);
} else if ("waterFallChar".equals(type)) {
waterFallChar(request, response);
} else if ("waferMapChar".equals(type)) {
waferMapChar(request, response);
} else if ("timeSeriesChar".equals(type)) {
timeSeriesChar(request, response);
} else if ("windPlotChar".equals(type)) {
windPlotChar(request, response);
}
}
// 2D折线图
public void line2DChar(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
datasetObj = new DatasetObj();
datasetObj.setTextTitle("2D折线图");
datasetObj.setXTitle("X轴标题");
datasetObj.setYTitle("Y轴标题");
datasetObj.setCategorydataset(ChartData.getCategoryDataset());
datasetObj.setPlotorientation(PlotOrientation.VERTICAL);// 条形设置datasetObj.setPlotorientation(PlotOrientation.HORIZONTAL);
datasetObj.setLegend(true);
datasetObj.setTooltip(false);
datasetObj.setUrl(false);
try {
image = this.charimpl.line2DChar(datasetObj, reportpath, "line2D",
"jpg", 800, 600);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("charname", imagepath + image);
forward(request, response, pagepath);
}
// 3D折线图
public void line3DChar(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
datasetObj = new DatasetObj();
datasetObj.setTextTitle("3D折线图");
datasetObj.setXTitle("X轴标题");
datasetObj.setYTitle("Y轴标题");
datasetObj.setCategorydataset(ChartData.getCategoryDataset());
datasetObj.setPlotorientation(PlotOrientation.VERTICAL);// 条形设置datasetObj.setPlotorientation(PlotOrientation.HORIZONTAL);
datasetObj.setLegend(true);
datasetObj.setTooltip(false);
datasetObj.setUrl(false);
try {
image = this.charimpl.line3DChar(datasetObj, reportpath, "line3D",
"jpg", 800, 600);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("charname", imagepath + image);
forward(request, response, pagepath);
}
// XY数据点折线图
public void lineDataPointChar(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
datasetObj = new DatasetObj();
datasetObj.setTextTitle("XY数据点折线图");
datasetObj.setXTitle("X轴标题");
datasetObj.setYTitle("Y轴标题");
datasetObj.setXyseriescollection(ChartData.getXYSeriesCollection());
datasetObj.setPlotorientation(PlotOrientation.VERTICAL);
datasetObj.setLegend(true);
datasetObj.setTooltip(false);
datasetObj.setUrl(false);
try {
image = this.charimpl.lineDataPointChar(datasetObj, reportpath,
"lineDataPoint", "jpg", 800, 600);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("charname", imagepath + image);
forward(request, response, pagepath);
}
// 面积图
public void areaChar(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
datasetObj = new DatasetObj();
datasetObj.setTextTitle("面积图");
datasetObj.setXTitle("X轴标题");
datasetObj.setYTitle("Y轴标题");
datasetObj.setCategorydataset(ChartData.getCategoryDataset());
datasetObj.setPlotorientation(PlotOrientation.VERTICAL);
datasetObj.setLegend(true);
datasetObj.setTooltip(false);
datasetObj.setUrl(false);
try {
image = this.charimpl.areaChar(datasetObj, reportpath, "area",
"jpg", 800, 600);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("charname", imagepath + image);
forward(request, response, pagepath);
}
// 堆积面积图
public void areaStackedChar(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
datasetObj = new DatasetObj();
datasetObj.setTextTitle("堆积面积图");
datasetObj.setXTitle("X轴标题");
datasetObj.setYTitle("Y轴标题");
datasetObj.setCategorydataset(ChartData.getCategoryDataset());
datasetObj.setPlotorientation(PlotOrientation.VERTICAL);
datasetObj.setLegend(true);
datasetObj.setTooltip(false);
datasetObj.setUrl(false);
try {
image = this.charimpl.areaStackedChar(datasetObj, reportpath,
"areaStacked", "jpg", 800, 600);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("charname", imagepath + image);
forward(request, response, pagepath);
}
// XY数据点面积图
public void areaDataPointChar(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
datasetObj = new DatasetObj();
datasetObj.setTextTitle("XY数据点面积图");
datasetObj.setXTitle("X轴标题");
datasetObj.setYTitle("Y轴标题");
datasetObj.setXyseriescollection(ChartData.getXYSeriesCollection());
datasetObj.setPlotorientation(PlotOrientation.VERTICAL);
datasetObj.setLegend(true);
datasetObj.setTooltip(false);
datasetObj.setUrl(false);
try {
image = this.charimpl.areaDataPointChar(datasetObj, reportpath,
"areaDataPoint", "jpg", 800, 600);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("charname", imagepath + image);
forward(request, response, pagepath);
}
// XY数据点阶梯面积图
public void areaDataStepChar(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
datasetObj = new DatasetObj();
datasetObj.setTextTitle("XY数据点阶梯面积图");
datasetObj.setXTitle("X轴标题");
datasetObj.setYTitle("Y轴标题");
datasetObj.setXyseriescollection(ChartData.getXYSeriesCollection());
datasetObj.setPlotorientation(PlotOrientation.VERTICAL);
datasetObj.setLegend(true);
datasetObj.setTooltip(false);
datasetObj.setUrl(false);
try {
image = this.charimpl.areaDataStepChar(datasetObj, reportpath,
"areaDataStep", "jpg", 800, 600);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("charname", imagepath + image);
forward(request, response, pagepath);
}
// 数据点堆积面积图*******************************************
public void areaDataStackedChar(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
datasetObj = new DatasetObj();
datasetObj.setTextTitle("数据点堆积面积图");
datasetObj.setXTitle("X轴标题");
datasetObj.setYTitle("Y轴标题");
datasetObj.setCategorydataset(ChartData.getCategoryDataset());
datasetObj.setPlotorientation(PlotOrientation.VERTICAL);
datasetObj.setLegend(true);
datasetObj.setTooltip(false);
datasetObj.setUrl(false);
try {
image = this.charimpl.areaDataStepChar(datasetObj, reportpath,
"areaDataStacked", "jpg", 800, 600);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("charname", imagepath + image);
forward(request, response, pagepath);
}
// 2D柱图
public void bar2DChar(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
datasetObj = new DatasetObj();
datasetObj.setTextTitle("2D柱图");
datasetObj.setXTitle("X轴标题");
datasetObj.setYTitle("Y轴标题");
datasetObj.setCategorydataset(ChartData.getCategoryDataset());
datasetObj.setPlotorientation(PlotOrientation.VERTICAL);
datasetObj.setLegend(true);
datasetObj.setTooltip(false);
datasetObj.setUrl(false);
try {
image = this.charimpl.bar2DChar(datasetObj, reportpath, "bar2D",
"jpg", 800, 600);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("charname", imagepath + image);
forward(request, response, pagepath);
}
// 3D柱图
public void bar3DChar(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
datasetObj = new DatasetObj();
datasetObj.setTextTitle("3D柱图");
datasetObj.setXTitle("X轴标题");
datasetObj.setYTitle("Y轴标题");
datasetObj.setCategorydataset(ChartData.getCategoryDataset());
datasetObj.setPlotorientation(PlotOrientation.VERTICAL);
datasetObj.setLegend(true);
datasetObj.setTooltip(false);
datasetObj.setUrl(false);
try {
image = this.charimpl.bar3DChar(datasetObj, reportpath, "bar3D",
"jpg", 800, 600);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("charname", imagepath + image);
forward(request, response, pagepath);
}
// 2D柱线图
public void barLine2DChar(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
datasetObj = new DatasetObj();
datasetObj.setTextTitle("2D柱线图");
datasetObj.setXTitle("X轴标题");
datasetObj.setYTitle("Y轴标题");
datasetObj.setCategorydataset(ChartData.getCategoryDataset());
datasetObj.setPlotorientation(PlotOrientation.VERTICAL);
datasetObj.setLegend(true);
datasetObj.setTooltip(false);
datasetObj.setUrl(false);
try {
image = this.charimpl.barLine2DChar(datasetObj, reportpath,
"barLine2D", "jpg", 800, 600);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("charname", imagepath + image);
forward(request, response, pagepath);
}
// 3D柱线图
public void barLine3DChar(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
datasetObj = new DatasetObj();
datasetObj.setTextTitle("3D柱线图");
datasetObj.setXTitle("X轴标题");
datasetObj.setYTitle("Y轴标题");
datasetObj.setCategorydataset(ChartData.getCategoryDataset());
datasetObj.setPlotorientation(PlotOrientation.VERTICAL);
datasetObj.setLegend(true);
datasetObj.setTooltip(false);
datasetObj.setUrl(false);
try {
image = this.charimpl.barLine3DChar(datasetObj, reportpath,
"barLine3D", "jpg", 800, 600);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("charname", imagepath + image);
forward(request, response, pagepath);
}
// 2D堆积柱图
public void bar2DStackedChar(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
datasetObj = new DatasetObj();
datasetObj.setTextTitle("2D堆积柱图");
datasetObj.setXTitle("X轴标题");
datasetObj.setYTitle("Y轴标题");
datasetObj.setCategorydataset(ChartData.getCategoryDataset());
datasetObj.setPlotorientation(PlotOrientation.VERTICAL);
datasetObj.setLegend(true);
datasetObj.setTooltip(false);
datasetObj.setUrl(false);
try {
image = this.charimpl.bar2DStackedChar(datasetObj, reportpath,
"bar2DStacked", "jpg", 800, 600);
} catch (Exception e) {
e.printStackTrace();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -