/**
*
*/
package com.ccit.csw.queryfee.action;
import java.awt.Color;
import java.awt.Font;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.TextAnchor;
import com.ccit.csw.common.action.base.BaseAction;
import com.ccit.csw.common.exception.AppCodeException;
import com.ccit.csw.common.exception.BaseException;
import com.ccit.csw.common.log.Logger;
import com.ccit.csw.common.outinterface.impl.MyNode;
import com.ccit.csw.common.service.ErrorMessageService;
import com.ccit.csw.common.util.BusinessUtil;
import com.ccit.csw.common.util.CommonConstant;
import com.ccit.csw.common.util.Util;
import com.ccit.csw.common.vo.SessionVo;
import com.ccit.csw.points.vo.PointsBalanceVo;
import com.ccit.csw.queryfee.service.QueryfeeCommonService;
import com.ccit.csw.queryfee.util.QueryfeeServiceUtil;
import com.ccit.csw.queryfee.vo.BalanceVo;
import com.ccit.csw.queryfee.vo.BlancePayQrVo;
import com.ccit.csw.queryfee.vo.CustBillIQrVo;
import com.ccit.csw.queryfee.vo.CustBillInfoVo;
import com.ccit.csw.queryfee.vo.NewBillSvrVo;
import com.ccit.csw.queryfee.vo.ProductBillVo;
import com.opensymphony.xwork2.ActionContext;
/**
* @author 陈立志 E-Mail:chenlizhi@ccit.com.cn
* @version 0.1
* @since Sep 15, 2009 10:42:04 AM
*/
public class ReckQueryNewAction extends BaseAction {
private static final long serialVersionUID = 1L;
private String productInfo; // 所选产品 产品类型:产品号码的形式
private String queryType; // 所选查询方式 1产品级 2账户级
private String period; // 账期 20090701-20090731 的形式 //新账期 为201006 的形式
// private PointsManagerService pointsManagerService; // 查询积分余额service
private QueryfeeCommonService queryfeeService; // 查询余额service
private ErrorMessageService messageService; // 查询平台错误信息
private CustBillIQrVo custBillQrVo; // 账户级账单返回信息
private ProductBillVo productBillVo; // 产品级账单返回信息
private BlancePayQrVo blancePayQrVo; //历史累积量返回信息
private PointsBalanceVo pointsBalanceVo; // 接口返回的积分余额信息
private String picName; //饼图路径
public String execute() throws BaseException {
// try {
Logger.getLogger().info(ReckQueryAction.class, "execute()",
"账单查询 用户选择的产品号码:"+productInfo+" 查询类型:"+queryType+" 账期:"+period, null);
// 得到SessionVo 中的信息
SessionVo sesionVo = (SessionVo) getSession(CommonConstant.USER_INFO);
BalanceVo balanceVo = new BalanceVo();
//检验选择产品是否在客户的产品列表中,防止被人篡改
if(!BusinessUtil.checkProdInList((List) ActionContext.getContext().getSession().get(
"userNewList"),productInfo)){
if("2".equals(queryType)){
productBillVo= new ProductBillVo();
balanceVo.setErrorCode(CommonConstant.NOLOGINUSER_ERRORCODE);
balanceVo.setErrorDesc(messageService.getErrorMessageByCode(CommonConstant.NOLOGINUSER_ERRORCODE).getErrdesc());
}else{
custBillQrVo= new CustBillIQrVo();
custBillQrVo.setErrorCode(CommonConstant.NOLOGINUSER_ERRORCODE);
custBillQrVo.setErrorDesc(messageService.getErrorMessageByCode(CommonConstant.NOLOGINUSER_ERRORCODE).getErrdesc());
}
}else{
try{
//调用余额查询接口
/** balanceVo = queryfeeService.acctBalanceQuery(sesionVo, productInfo);
//调用累积量查询接口
blancePayQrVo = queryfeeService.queryPackageUserInfo(sesionVo, productInfo, queryType,period);
}catch(Exception ex){
Logger.getLogger().error(ReckQueryAction.class, "excute()",
ex.getMessage(), ex);
}
//如果为产品级账单,则调用产品级账单查询接口
if("1".equals(queryType)){
productBillVo =queryfeeService.productBillQuery(sesionVo,productInfo, period);
if(productBillVo!=null && balanceVo!=null){
productBillVo.setBalance(balanceVo.getBalanceFullFee());
}
}else{
//否则调用账户级账单
custBillQrVo =queryfeeService.custBillQuery(sesionVo,productInfo, period);
if(custBillQrVo!=null && balanceVo!=null){
custBillQrVo.setOutBalance(balanceVo.getBalanceFullFee());
}
}
*/
//新账单查询,同一更改为查询客户级账单 edit by heavy 2010-08-20
String type=Util.getProductType(productInfo);
String number=Util.getProductNumber(productInfo);
if(String.valueOf(CommonConstant.PHONE_TYPE).equals(type)||String.valueOf(CommonConstant.PHS_TYPE).equals(type)||String.valueOf(CommonConstant.LAN_TYPE).equals(type)){
number=sesionVo.getOrgCode()+number;
}
NewBillSvrVo vo = queryfeeService.newBillSrv(sesionVo,
number, period,queryType,type);
Logger.getLogger().info(ReckQueryAction.class,"","查询账单xml:"+vo.getXml_out(),null);
custBillQrVo=queryfeeService.getCustBillFromNewBillSvr(vo);
//以下下用来生成饼图 只有产品级才生成
if("1".equals(queryType)){
picName=createPic(custBillQrVo.getCustBillInfoList(),"2",super.getRequest().getSession());
}
if("0".equals(queryType)){
picName=creat3Dpic(custBillQrVo.getStatisticalList(),period,super.getRequest().getSession());
}
// if(custBillQrVo.isResultFlag()){
// pointsBalanceVo = pointsManagerService.queryPointsBalance(sesionVo, productInfo);
// }
//Logger.getLogger().info(ReckQueryAction.class,"","积分信息:"+pointsBalanceVo.getViewList().size(),null);
} catch (BaseException e) {
Logger.getLogger().error(ReckQueryAction.class, "excute()",
e.getMessage(), e);
throw e;
}
catch (Exception ex) {
Logger.getLogger().error(ReckQueryAction.class, "execute()",
ex.getMessage(), ex);
throw new AppCodeException("账单查询失败", ex);
}}
return SUCCESS;
}
/**
* 生成图片流
* @param list
* @param level 级别
* @return
*/
private static String createPic(List list,String level,HttpSession session){
if(list==null||list.size()==0){
return null;
}
DefaultPieDataset dataset = new DefaultPieDataset();
String filename =null;
for(int i=0;i<list.size();i++){
CustBillInfoVo vo = (CustBillInfoVo)list.get(i);
if(vo!=null&&level.equals(vo.getItemLevel())){
dataset.setValue(" "+vo.getItemName(), Double.valueOf(vo.getItemCharge()).doubleValue()/100);
}
}
JFreeChart chart = ChartFactory.createPieChart3D(" 账单消费分布(单位:元)", // chart
// title
dataset,// data
true,// include legend
true, false);
PiePlot3D plot = (PiePlot3D) chart.getPlot();
// 图片中显示百分比:默认方式
// plot.setLabelGenerator(new
// StandardPieSectionLabelGenerator(StandardPieToolTipGenerator.DEFAULT_TOOLTIP_FORMAT));
// 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位
plot.setLabelGenerator(new StandardPieSectionLabelGenerator(
"{0}={1}({2})", NumberFormat.getNumberInstance(),
new DecimalFormat("0.00%")));
// 图例显示百分比:自定义方式, {0} 表示选项, {1} 表示数值, {2} 表示所占比例
plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(
"{0}={1}({2})", NumberFormat.getNumberInstance(),
new DecimalFormat("0.00%")));
// 设置背景色为白色
chart.setBackgroundPaint(Color.white);
// 指定图片的透明度(0.0-1.0)
plot.setForegroundAlpha(1.0f);
// 指定显示的饼图上圆形(false)还椭圆形(true)
plot.setCircular(true);
// 设置图标题的字体
Font font = new Font(" 黑体", Font.CENTER_BASELINE, 20);
TextTitle title = new TextTitle(" 账单消费分布(单位:元)");
title.setFont(font);
chart.setTitle(title);
// PrintWriter pw=null;
// try {
// pw =ServletActionContext.getResponse().getWriter();
// }catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
try {
filename = ServletUtilities.saveChartAsPNG(chart, 540, 280, session);
// ChartUtilities.writeImageMap(pw, "map0", new ChartRenderingInfo(new StandardEntityCollection()), false);
} catch (Exception e) {
Logger.getLogger().error(ReckQueryAction.class, "账单查询生成饼图出错!",
e.getMessage(), e);
}
return filename;
}
private static String creat3Dpic(List list,String period,HttpSession session){
if(list==null||list.size()==0){
return null;
}
period=((MyNode)QueryfeeServiceUtil.getFeeMonthList("-3").get(0)).getValue();
List newList=list;
for(int i=0;i<newList.size();i++){
CustBillInfoVo vo = (CustBillInfoVo)list.get(i);
if(vo!=null){
if(vo.getItemId().indexOf("57255")<0){
newList.remove(i);
i--;
}
}
}
DefaultCategoryDataset dataset=new DefaultCategoryDataset();
for(int j=0;j<6;j++){
for(int i=0;i<list.size();i++){
CustBillInfoVo vo = (CustBillInfoVo)list.get(i);
if(vo!=null&&Integer.parseInt(vo.getItemId().substring(vo.getItemId().length()-1))==j){
dataset.addValue(Double.valueOf(vo.getItemCharge()),"1", vo.getItemName());
break;
}else{
if(i==list.size()-1){
dataset.addValue(0,"1", getPeriod(period,j));
break;
}
}
}
}
JFreeChart chart=ChartFactory.createBarChart3D(
"近六个月总费用支出图",
"月份",//目录轴的显示标签
"费用(元)",//数值轴的显示标签
dataset,
PlotOrientation.VERTICAL,//设置图表方向
false,
false,
false
);
//设置标题
chart.setTitle(new TextTitle("近六个月总费用支出图",new Font("黑体",Font.CENTER_BASELINE,22)));
chart.setBackgroundPaint(Color.white);
//设置图表部分
CategoryPlot plot=(CategoryPlot)chart.getPlot();
plot.setBackgroundAlpha(0.1f);
plot.setDataAreaRatio(0.00);
CategoryAxis categoryAxis=plot.getDomainAxis();//取得横轴
categoryAxis.setLabelFont(new Font("宋体",Font.BOLD,18));//设置横轴显示标签的字体
//categoryAxis.setLabelPaint(Color.decode("#F8D661"));
categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);//分类标签以45度倾斜
categoryAxis.setTickLabelFont(new Font("宋体",Font.LAYOUT_LEFT_TO_RIGHT,10));//分类标签字体
NumberAxis numberAxis=(NumberAxis)plot.getRangeAxis();//取得纵轴
numberAxis.setLabelFont(new Font("宋体",Font.BOLD,18));//设置纵轴显示标签字体
BarRenderer3D customBarRenderer = (BarRenderer3D) plot.getRenderer();
customBarRenderer.setPositiveItemLabelPosition(new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE12,TextAnchor.BASELINE_LEFT));
customBarRenderer.setMaxBarWidth(0.05);
customBarRenderer.setItemMargin(0.000000005);
customBarRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());//显示每个柱的数值
customBarRenderer.setBaseItemLabelsVisible(true);
//注意:此句很关键,若无此句,那数字的显示会被覆盖,给人数字没有显示出来的问题
customBarRenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
customBarRenderer.setItemLabelAnchorOffset(8D);// 设置柱形图上的文字偏离值
customBarRenderer.setItemLabelFont(new Font("宋体",Font.ITALIC,12));
customBarRenderer.setSeriesPaint(0, Color.decode("#24F4DB")); // 给series1 Bar
// customBarRenderer.setSeriesPaint(1, Color.decode("#7979FF")); // 给series2 Bar
// customBarRenderer.setSeriesPaint(2, Color.decode("#FF5555")); // 给series3 Bar
// customBarRenderer.setSeriesPaint(3, Color.decode("#F8D661")); // 给series4 Bar
// customBarRenderer.setSeriesPaint(4, Color.decode("#F284DC")); // 给series5 Bar
// customBarRenderer.setSeriesPaint(5, Color.decode("#00BF00")); // 给series6 Bar
// customBarRenderer.setSeriesOutlinePaint(0,Color.BLACK);//边框为黑色
// customBarRenderer.setSeriesOutlinePaint(1,Color.BLACK);//边框为黑色
// customBarRenderer.setSeriesOutlinePaint(2,Color.BLACK); //边框为黑色
// customBarRenderer.setSeriesOutlinePaint(3,Color.BLACK);//边框为黑色
// customBarRenderer.setSeriesOutlinePaint(4,Color.BLACK);//边框为黑色
// customBarRenderer.setSeriesOutlinePaint(5,Color.BLACK); //边框为黑色
customBarRenderer.setItemLabelsVisible(true);
// customBarRenderer.setMinimumBarLength(0.9D);
// FileOutputStream fos=null;
// fos=new FileOutputStream("D://book1.jpg");
// ChartUtilities.writeChartAsJPEG(
// fos,
// 1,
// chart,
// 540,
// 330,
// null
//
// );
// fos.close();
String filename=null;
try {
filename = ServletUtilities.saveChartAsPNG(chart, 540, 280, session);
// ChartUtilities.writeImageMap(pw, "map0", new ChartRenderingInfo(new StandardEntityCollection()), false);
} catch (Exception e) {
Logger.getLogger().error(ReckQueryAction.class, "账单查询生成柱状图出错!",
e.getMessage(), e);
}
return filename;
}
private static String getPeriod(String currPeriod,int latter){
String result="";
int year=Integer.valueOf(currPeriod.substring(0, 4)).intValue();
int month=Integer.valueOf(currPeriod.substring(4, 6)).intValue();
if(month>latter){
month=month-latter;
}else{
month=month+12-latter;
year=year-1;
}
if(month<10){
result=String.valueOf(year)+"0"+String.valueOf(month);
}else{
result=String.valueOf(year)+String.valueOf(month);
}
return result;
}
/**
* @return the productInfo
*/
public String getProductInfo() {
return productInfo;
}
/**
* @param productInfo the productInfo to set
*/
public void setProductInfo(String productInfo) {
this.productInfo = productInfo;
}
/**
* @return the queryType
*/
public String getQueryType() {
return queryType;
}
/**
* @param queryType the queryType to set
*/
public void setQueryType(String queryType) {
this.queryType = queryType;
}
/**
* @return the period
*/
public String getPeriod() {
return period;
}
/**
* @param period the period to set
*/
public void setPeriod(String period) {
this.period = period;
}
/**
* @return the serialVersionUID
*/
public static long getSerialVersionUID() {
return serialVersionUID;
}
/**
* @param queryfeeService the queryfeeService to set
*/
public void setQueryfeeService(QueryfeeCommonService queryfeeService) {
this.queryfeeService = queryfeeService;
}
/**
* @param messageService the messageService to set
*/
public void setMessageService(ErrorMessageService messageService) {
this.messageService = messageService;
}
/**
* @return the custBillQrVo
*/
public CustBillIQrVo getCustBillQrVo() {
return custBillQrVo;
}
/**
* @param custBillQrVo the custBillQrVo to set
*/
public void setCustBillQrVo(CustBillIQrVo custBillQrVo) {
this.custBillQrVo = custBillQrVo;
}
/**
* @return the productBillVo
*/
public ProductBillVo getProductBillVo() {
return productBillVo;
}
/**
* @param productBillVo the productBillVo to set
*/
public void setProductBillVo(ProductBillVo productBillVo) {
this.productBillVo = productBillVo;
}
public BlancePayQrVo getBlancePayQrVo() {
return blancePayQrVo;
}
public void setBlancePayQrVo(BlancePayQrVo blancePayQrVo) {
this.blancePayQrVo = blancePayQrVo;
}
public PointsBalanceVo getPointsBalanceVo() {
return pointsBalanceVo;
}
public void setPointsBalanceVo(PointsBalanceVo pointsBalanceVo) {
this.pointsBalanceVo = pointsBalanceVo;
}
// public void setPointsManagerService(PointsManagerService pointsManagerService) {
// this.pointsManagerService = pointsManagerService;
// }
public String getPicName() {
return picName;
}
public void setPicName(String picName) {
this.picName = picName;
}
}
ajax里取图片时 用servlet的形式,向取验证码一样,需要在web.xml里配置一个servlet,jfreechart组件中的。
一下两个单独的例子
package test;
import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
public class TestJFreeTree {
public static void main(String[] args) {
PieDataset dataset = getDataSet();
JFreeChart chart = ChartFactory.createPieChart3D(" 项目进度分布", // chart
// title
dataset,// data
true,// include legend
true, false);
PiePlot3D plot = (PiePlot3D) chart.getPlot();
// 图片中显示百分比:默认方式
// plot.setLabelGenerator(new
// StandardPieSectionLabelGenerator(StandardPieToolTipGenerator.DEFAULT_TOOLTIP_FORMAT));
// 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位
plot.setLabelGenerator(new StandardPieSectionLabelGenerator(
"{0}={1}({2})", NumberFormat.getNumberInstance(),
new DecimalFormat("0.00%")));
// 图例显示百分比:自定义方式, {0} 表示选项, {1} 表示数值, {2} 表示所占比例
plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(
"{0}={1}({2})",NumberFormat.getNumberInstance(),
new DecimalFormat("0.00%")));
// 设置背景色为白色
chart.setBackgroundPaint(Color.white);
// 指定图片的透明度(0.0-1.0)
plot.setForegroundAlpha(1.0f);
// 指定显示的饼图上圆形(false)还椭圆形(true)
plot.setCircular(true);
// 设置图标题的字体
Font font = new Font(" 黑体", Font.CENTER_BASELINE, 20);
TextTitle title = new TextTitle(" 项目状态分布");
title.setFont(font);
chart.setTitle(title);
FileOutputStream fos_jpg = null;
try {
fos_jpg = new FileOutputStream("D:// 项目状态分布.jpg");
ChartUtilities
.writeChartAsJPEG(fos_jpg, 100, chart, 540, 280, null);
fos_jpg.close();
} catch (Exception e) {
}
}
private static PieDataset getDataSet() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue(" 市场前期", new Double(10.5));
dataset.setValue(" 立项", new Double(15.99));
dataset.setValue(" 计划", new Double(10));
dataset.setValue(" 需求与设计", new Double(10));
dataset.setValue(" 执行控制", new Double(35.8));
dataset.setValue(" 收尾", new Double(10));
dataset.setValue(" 运维", new Double(10));
return dataset;
}
}
package test;
import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.TextAnchor;
public class BarChart3DDemo {
/**
* @param args
*/
public static void main(String[] args) throws IOException{
JFreeChart chart=ChartFactory.createBarChart3D(
"近六个月总费用支出图",
"月份",//目录轴的显示标签
"费用(元)",//数值轴的显示标签
getDataSet(),
PlotOrientation.VERTICAL,//设置图表方向
false,
false,
false
);
//设置标题
chart.setTitle(new TextTitle("近六个月总费用支出图",new Font("黑体",Font.CENTER_BASELINE,22)));
chart.setBackgroundPaint(Color.white);
//设置图表部分
CategoryPlot plot=(CategoryPlot)chart.getPlot();
plot.setBackgroundAlpha(0.1f);
plot.setDataAreaRatio(0.00);
CategoryAxis categoryAxis=plot.getDomainAxis();//取得横轴
categoryAxis.setLabelFont(new Font("宋体",Font.BOLD,18));//设置横轴显示标签的字体
//categoryAxis.setLabelPaint(Color.decode("#F8D661"));
categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);//分类标签以45度倾斜
categoryAxis.setTickLabelFont(new Font("宋体",Font.LAYOUT_LEFT_TO_RIGHT,10));//分类标签字体
NumberAxis numberAxis=(NumberAxis)plot.getRangeAxis();//取得纵轴
numberAxis.setLabelFont(new Font("宋体",Font.BOLD,18));//设置纵轴显示标签字体
BarRenderer3D customBarRenderer = (BarRenderer3D) plot.getRenderer();
customBarRenderer.setPositiveItemLabelPosition(new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE12,TextAnchor.BASELINE_LEFT));
customBarRenderer.setMaxBarWidth(0.05);
customBarRenderer.setItemMargin(0.000000005);
customBarRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());//显示每个柱的数值
customBarRenderer.setBaseItemLabelsVisible(true);
//注意:此句很关键,若无此句,那数字的显示会被覆盖,给人数字没有显示出来的问题
customBarRenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
customBarRenderer.setItemLabelAnchorOffset(8D);// 设置柱形图上的文字偏离值
customBarRenderer.setItemLabelFont(new Font("宋体",Font.ITALIC,12));
customBarRenderer.setSeriesPaint(0, Color.decode("#24F4DB")); // 给series1 Bar
// customBarRenderer.setSeriesPaint(1, Color.decode("#7979FF")); // 给series2 Bar
// customBarRenderer.setSeriesPaint(2, Color.decode("#FF5555")); // 给series3 Bar
// customBarRenderer.setSeriesPaint(3, Color.decode("#F8D661")); // 给series4 Bar
// customBarRenderer.setSeriesPaint(4, Color.decode("#F284DC")); // 给series5 Bar
// customBarRenderer.setSeriesPaint(5, Color.decode("#00BF00")); // 给series6 Bar
// customBarRenderer.setSeriesOutlinePaint(0,Color.BLACK);//边框为黑色
// customBarRenderer.setSeriesOutlinePaint(1,Color.BLACK);//边框为黑色
// customBarRenderer.setSeriesOutlinePaint(2,Color.BLACK); //边框为黑色
// customBarRenderer.setSeriesOutlinePaint(3,Color.BLACK);//边框为黑色
// customBarRenderer.setSeriesOutlinePaint(4,Color.BLACK);//边框为黑色
// customBarRenderer.setSeriesOutlinePaint(5,Color.BLACK); //边框为黑色
customBarRenderer.setItemLabelsVisible(true);
// customBarRenderer.setMinimumBarLength(0.9D);
FileOutputStream fos=null;
fos=new FileOutputStream("D://book1.jpg");
ChartUtilities.writeChartAsJPEG(
fos,
1,
chart,
540,
330,
null
);
fos.close();
}
private static CategoryDataset getDataSet(){
DefaultCategoryDataset dataset=new DefaultCategoryDataset();
dataset.addValue(43.5,"1", "201010");
dataset.addValue(180,"1","201009");
dataset.addValue(92.8, "1", "201008");
dataset.addValue(25.3, "1", "201007");
dataset.addValue(25.3, "1", "201006");
dataset.addValue(25.3, "1", "201005");
return dataset;
}
}