📄 chartserver.jsp
字号:
<%@page contentType="image/jpeg"%>
<%@page import="org.jCharts.chartData.*" %>
<%@page import="org.jCharts.axisChart.*"%>
<%@page import="org.jCharts.properties.*"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="java.awt.*"%>
<%@page import="java.awt.image.*"%>
<%@page import="javax.servlet.*"%>
<%@page import="javax.servlet.http.*"%>
<%@page import="org.ofbiz.entity.*" %>
<%@page import="org.ofbiz.entity.condition.*" %>
<%@page import="org.ofbiz.entity.model.*" %>
<%@page import="com.sourcetap.sfa.util.UserInfo" %>
<%@page import="com.sourcetap.sfa.activity.CalendarUtil" %>
<% UserInfo userInfo = (UserInfo) session.getAttribute("userInfo"); %>
<%!
public void generateChart( HttpServletRequest req, HttpServletResponse res, BarChartProperties properties, AxisProperties axisProperties, int width, int height, SingleDataSet singleDataSet) throws ServletException, IOException {
try {
BarChart barChart = new BarChart( singleDataSet, false, properties, axisProperties, width, height );
BufferedImage bi = barChart.getBufferedImage();
Graphics2D graphics = barChart.getGraphics2D();
// graphics.scale(0.75, 0.75d);
//graphics.
res.reset();
res.setContentType("image/jpeg");
barChart.exportJPG( res.getOutputStream(), 1.0f);
res.getOutputStream().flush();
} catch( Throwable throwable ) { throwable.printStackTrace(); Debug.logError("error in generate chart", "ChartServer");
}
}
%>
<%
try {
String monthLabel[] = {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
GenericDelegator delegator = (GenericDelegator)application.getAttribute("delegator");
int fyStartMonth = CalendarUtil.getFiscalYearStartMonth( delegator, userInfo );
BarChartProperties properties = new BarChartProperties();
AxisProperties axisProperties = new AxisProperties();
axisProperties.setScaleFont( new Font( "Arial", Font.BOLD, 12 ) );
axisProperties.setAxisTitleFont( new Font( "Arial", Font.BOLD, 12 ) );
axisProperties.setYAxisUseDollarSigns(true);
LineChartProperties lineChartProperties = new LineChartProperties(new BasicStroke());
Paint[] paints= { new Color(100,150,100) };
int width = 330;
int height = 216;
String xAxisTitle = " ";
String yAxisTitle = " ";
ArrayList xAxisLabels = new ArrayList();
ArrayList legendLabels = new ArrayList();
if(request.getParameter("report").equals("salesForQuarter")){
double data[] = new double[3];
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
int quarterNumbers[] = CalendarUtil.getQuarterMonthNumbers(month, fyStartMonth);
ArrayList list = new ArrayList();
list.add(new EntityExpr("ownerId", EntityOperator.EQUALS, userInfo.getPartyId()));
list.add(new EntityExpr("dealStatusId", EntityOperator.EQUALS, "10"));
list.add(new EntityExpr("actualCloseDate", EntityOperator.LESS_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMaximumQuarterDate(cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR), fyStartMonth).getTime())));
list.add(new EntityExpr("actualCloseDate", EntityOperator.GREATER_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMinimumQuarterDate(cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR), fyStartMonth).getTime())));
ArrayList order = new ArrayList();
order.add("actualCloseDate");
java.util.List dealList = delegator.findByAnd("Deal", list, order);
GenericValue dealValues[] = (GenericValue[])dealList.toArray(new GenericValue[0]);
GenericValue dealValue = null;
String months[] = CalendarUtil.getQuarterMonthNames(cal.get(Calendar.MONTH) + 1, fyStartMonth);
for(int iz=0;iz<months.length;iz++){
xAxisLabels.add((String)months[iz]);
}
xAxisTitle = "Month";
yAxisTitle = "Sales";
legendLabels.add("Pipeline for Quarter");
for(int iz=0;iz<dealValues.length;iz++) {
dealValue = dealValues[iz];
Calendar calendar = Calendar.getInstance();
calendar.setTime(dealValue.getDate("actualCloseDate"));
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[0] && calendar.get(Calendar.YEAR)==year){
data[0] = data[0] + dealValue.getDouble("amount").doubleValue();
}
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[1] && calendar.get(Calendar.YEAR)==year){
data[1] = data[1] + dealValue.getDouble("amount").doubleValue();
}
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[2] && calendar.get(Calendar.YEAR)==year){
data[2] = data[2] + dealValue.getDouble("amount").doubleValue();
}
}
try {
BarChart barChart = new BarChart(
new SingleDataSet(
data,
(String[])legendLabels.toArray(new String[0]),
(String[])xAxisLabels.toArray(new String[0]),
paints,
xAxisTitle,
yAxisTitle ),
false, properties, axisProperties, width, height );
response.reset();
response.setContentType("image/jpeg");
barChart.exportJPG( response.getOutputStream(), 1.0f);
response.getOutputStream().flush();
} catch( Throwable throwable ) { throwable.printStackTrace();
}
}
if(request.getParameter("report").equals("leadsForQuarter")){
double data[] = new double[3];
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
int quarterNumbers[] = CalendarUtil.getQuarterMonthNumbers(month, fyStartMonth);
ArrayList list = new ArrayList();
list.add(new EntityExpr("leadOwnerId", EntityOperator.EQUALS, userInfo.getPartyId()));
list.add(new EntityExpr("statusId", EntityOperator.EQUALS, "50"));
list.add(new EntityExpr("convertedDate", EntityOperator.LESS_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMaximumQuarterDate(cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR), fyStartMonth).getTime())));
list.add(new EntityExpr("convertedDate", EntityOperator.GREATER_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMinimumQuarterDate(cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR),fyStartMonth).getTime())));
ArrayList order = new ArrayList();
order.add("convertedDate");
java.util.List dealList = delegator.findByAnd("Lead", list, order);
GenericValue leadValues[] = (GenericValue[])dealList.toArray(new GenericValue[0]);
GenericValue leadValue = null;
String months[] = CalendarUtil.getQuarterMonthNames(cal.get(Calendar.MONTH) + 1, fyStartMonth);
for(int iz=0;iz<months.length;iz++){
xAxisLabels.add((String)months[iz]);
}
xAxisTitle = "Month";
yAxisTitle = "Leads";
legendLabels.add("Leads for Quarter");
for(int iz=0;iz<leadValues.length;iz++) {
leadValue = leadValues[iz];
Calendar calendar = Calendar.getInstance();
calendar.setTime(leadValue.getTimestamp("convertedDate"));
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[0] && calendar.get(Calendar.YEAR)==year){
data[0] = data[0] + 1;
}
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[1] && calendar.get(Calendar.YEAR)==year){
data[1] = data[1] + 1;
}
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[2] && calendar.get(Calendar.YEAR)==year){
data[2] = data[2] + 1;
}
}
axisProperties.setYAxisUseDollarSigns(false);
axisProperties.setYAxisRoundValuesToNearest(0);
// axisProperties.setXAxisVerticalScaleFlag(true);
try {
BarChart barChart = new BarChart(
new SingleDataSet(
data,
(String[])legendLabels.toArray(new String[0]),
(String[])xAxisLabels.toArray(new String[0]),
paints,
xAxisTitle,
yAxisTitle ),
false, properties, axisProperties, width, height );
response.reset();
response.setContentType("image/jpeg");
barChart.exportJPG( response.getOutputStream(), 1.0f);
response.getOutputStream().flush();
} catch( Throwable throwable ) { throwable.printStackTrace();
}
}
if(request.getParameter("report").equals("forecastedForQuarter")){
double data[] = new double[3];
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
int quarterNumbers[] = CalendarUtil.getQuarterMonthNumbers(month, fyStartMonth);
ArrayList list = new ArrayList();
list.add(new EntityExpr("ownerId", EntityOperator.EQUALS, userInfo.getPartyId()));
list.add(new EntityExpr("projectedCloseDate", EntityOperator.LESS_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMaximumQuarterDate(cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR), fyStartMonth).getTime())));
list.add(new EntityExpr("projectedCloseDate", EntityOperator.GREATER_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMinimumQuarterDate(cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR), fyStartMonth).getTime())));
ArrayList order = new ArrayList();
order.add("projectedCloseDate");
java.util.List dealList = delegator.findByAnd("Deal", list, order);
GenericValue dealValues[] = (GenericValue[])dealList.toArray(new GenericValue[0]);
GenericValue dealValue = null;
String months[] = CalendarUtil.getQuarterMonthNames(cal.get(Calendar.MONTH) + 1, fyStartMonth);
for(int iz=0;iz<months.length;iz++){
xAxisLabels.add((String)months[iz]);
}
xAxisTitle = "month";
yAxisTitle = "sales";
legendLabels.add("Forecasted Sales for Quarter");
for(int iz=0;iz<dealValues.length;iz++) {
dealValue = dealValues[iz];
Calendar calendar = Calendar.getInstance();
calendar.setTime(dealValue.getDate("projectedCloseDate"));
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[0] && calendar.get(Calendar.YEAR)==year){
data[0] = data[0] + dealValue.getDouble("amount").doubleValue();
}
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[1] && calendar.get(Calendar.YEAR)==year){
data[1] = data[1] + dealValue.getDouble("amount").doubleValue();
}
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[2] && calendar.get(Calendar.YEAR)==year){
data[2] = data[2] + dealValue.getDouble("amount").doubleValue();
}
}
try {
BarChart barChart = new BarChart(
new SingleDataSet(
data,
(String[])legendLabels.toArray(new String[0]),
(String[])xAxisLabels.toArray(new String[0]),
paints,
xAxisTitle,
yAxisTitle ),
false, properties, axisProperties, width, height );
response.reset();
response.setContentType("image/jpeg");
barChart.exportJPG( response.getOutputStream(), 1.0f);
response.getOutputStream().flush();
} catch( Throwable throwable ) { Debug.logError("Error creating bar chart", "ChartServer");throwable.printStackTrace();
}
}
} catch ( Exception e2 ) { Debug.logError("error creating chart", "ChartServer"); }
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -