?? jfreechart.java
字號:
package cn.jsprun.utils;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
import cn.jsprun.service.system.DataBaseService;
public class Jfreechart extends HttpServlet {
private static final long serialVersionUID = -205545450335033053L;
public void destroy() {
super.destroy();
}
@SuppressWarnings("deprecation")
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String arear = request.getParameter("arears");
if(arear!=null && arear.equals("changjiang")){
DefaultPieDataset data = getDataSet(arear);
JFreeChart chart = ChartFactory.createPieChart3D("會員地區(qū)分布圖以長江為分界線", data, true, false, false);
try {
ChartUtilities.writeChartAsJPEG(response.getOutputStream(), 1.0f, chart, 400, 300, null);
} catch (IOException e) {
e.printStackTrace();
}
}else if(arear!=null && arear.equals("huanghe")){
DefaultPieDataset data = getDataSet(arear);
JFreeChart chart = ChartFactory.createPieChart3D("會員地區(qū)分布圖以黃河為分界線",data,true,false,false);
try {
ChartUtilities.writeChartAsJPEG(response.getOutputStream(), 1.0f, chart, 400, 300, null);
} catch (IOException e) {
e.printStackTrace();
}
}else{
DefaultPieDataset data = getDataSet(arear);
JFreeChart chart = ChartFactory.createPieChart3D("會員使用運(yùn)營商分布圖",data,true,false,false);
try {
ChartUtilities.writeChartAsJPEG(response.getOutputStream(), 1.0f, chart, 400, 300, null);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
public void init() throws ServletException {
}
private DefaultPieDataset getDataSet(String res) {
java.text.DecimalFormat df = new java.text.DecimalFormat("0.00");
DefaultPieDataset dataset = new DefaultPieDataset();
List<Map<String,String>> memberlist = ((DataBaseService)BeanFactory.getBean("dataBaseService")).executeQuery("select regip from jrun_members");
IPSeeker seeker = IPSeeker.getInstance();
if(memberlist!=null && memberlist.size()>0){
if(res.equals("changjiang")){
String north[]= {"遼寧","吉林","河南","河北","陜西","山西","黑龍江","甘肅","內(nèi)蒙古","北京市","天津市","山東"};
int northint = 0;
int southint = 0;
for(Map<String,String> members:memberlist){
String address = seeker.getAddress(members.get("regip"));
boolean flag = false;
for(int j=0;j<north.length;j++){
if(address.indexOf(north[j])!=-1){
northint++;
flag = true;
}
}
if(!flag){
southint++;
}
}
double percentnorth = (double)northint/(double)(northint+southint)*100;
double percentsouth = (double)southint/(double)(northint+southint)*100;
dataset.setValue("長江以北"+df.format(percentnorth)+"%", northint);
dataset.setValue("長江以南"+df.format(percentsouth)+"%", southint);
}else if(res.equals("huanghe")){
dataset.setValue("黃河還沒有數(shù)據(jù)",0);
}else{
String north[]= {"電信","網(wǎng)通","鐵通","手機(jī)","聯(lián)通","移動","其它"};
int telecom = 0;
int reticle = 0;
int tianton = 0;
int souji = 0;
int lianton = 0;
int yidong = 0;
int other = 0;
for(Map<String,String> members:memberlist){
String address = seeker.getAddress(members.get("regip"));
if(address.indexOf(north[0])!=-1){
telecom++;
}else if(address.indexOf(north[1])!=-1){
reticle++;
}else if(address.indexOf(north[2])!=-1){
tianton++;
}else if(address.indexOf(north[3])!=-1){
souji++;
}else if(address.indexOf(north[4])!=-1){
lianton++;
}else if(address.indexOf(north[5])!=-1){
yidong++;
}else{
other++;
}
}
double percenttele = (double)telecom/(double)(telecom+reticle+other+tianton+souji+lianton+yidong)*100;
double percentreticle = (double)reticle/(double)(telecom+reticle+other+tianton+souji+lianton+yidong)*100;
double percentother = (double)other/(double)(telecom+reticle+other+tianton+souji+lianton+yidong)*100;
double percenttianton = (double)tianton/(double)(telecom+reticle+other+tianton+souji+lianton+yidong)*100;
double percentsouji = (double)souji/(double)(telecom+reticle+other+tianton+souji+lianton+yidong)*100;
double percentlianton = (double)lianton/(double)(telecom+reticle+other+tianton+souji+lianton+yidong)*100;
double percentyidong = (double)yidong/(double)(telecom+reticle+other+tianton+souji+lianton+yidong)*100;
dataset.setValue("電信用戶"+df.format(percenttele)+"%", telecom);
dataset.setValue("網(wǎng)通用戶"+df.format(percentreticle)+"%", reticle);
dataset.setValue("鐵通用戶"+df.format(percenttianton)+"%", tianton);
dataset.setValue("手機(jī)用戶"+df.format(percentsouji)+"%", souji);
dataset.setValue("聯(lián)通用戶"+df.format(percentlianton)+"%", lianton);
dataset.setValue("移動用戶"+df.format(percentyidong)+"%", yidong);
dataset.setValue("其它用戶"+df.format(percentother)+"%", other);
}
}
memberlist = null;
return dataset;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -