📄 jfreechart.txt
字号:
vCategoryPlot.setDomainGridlinesVisible(true);
}
}
catch(Exception e)
{}
break;
case 13:
vFreeChart=ChartFactory.createLineChart3D(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getCategoryDataset(),PlotOrientation.VERTICAL,true,false,false);
try
{
vCategoryPlot=vFreeChart.getCategoryPlot();
if(vCategoryPlot!=null)
{
vLineRenderer3D=new LineRenderer3D();
vLineRenderer3D.setBaseOutlinePaint(Color.GRAY);
if(bRender)
{
//设置线面颜色
if(strCategoryArray.length>0)
{
for(int iIndex=0;iIndex<strCategoryArray.length;iIndex++)
{
vLineRenderer3D.setSeriesPaint(iIndex,new Color(0,0+iIndex*(255/strCategoryArray.length),255));
vLineRenderer3D.setSeriesFillPaint(iIndex,new Color(0,0+iIndex*(255/strCategoryArray.length),255));
vLineRenderer3D.setSeriesOutlinePaint(0,Color.BLACK);
}
}
//设置X轴、Y轴的显示位置
vCategoryPlot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
vCategoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
}
vCategoryPlot.setRenderer(vLineRenderer3D);
//背景表格线
vCategoryPlot.setDomainGridlinesVisible(true);
}
}
catch(Exception e)
{}
break;
case 14:
vFreeChart=ChartFactory.createGanttChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getIntervalCategoryDataset(),true,false,false);
break;
case 15:
vFreeChart=ChartFactory.createWaterfallChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getCategoryDataset(),PlotOrientation.VERTICAL,true,false,false);
try
{
vCategoryPlot=vFreeChart.getCategoryPlot();
if(vCategoryPlot!=null)
{
vWaterfallBarRenderer=new WaterfallBarRenderer();
vWaterfallBarRenderer.setBaseOutlinePaint(Color.GRAY);
if(bRender)
{
//设置柱颜色
if(strCategoryArray.length>0)
{
for(int iIndex=0;iIndex<strCategoryArray.length;iIndex++)
{
vWaterfallBarRenderer.setSeriesPaint(iIndex,new Color(0,0+iIndex*(255/strCategoryArray.length),255));
vWaterfallBarRenderer.setSeriesFillPaint(iIndex,new Color(0,0+iIndex*(255/strCategoryArray.length),255));
vWaterfallBarRenderer.setSeriesOutlinePaint(0,Color.BLACK);
}
}
//设置X轴、Y轴的显示位置
vCategoryPlot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
vCategoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
}
vCategoryPlot.setRenderer(vWaterfallBarRenderer);
//背景表格线
vCategoryPlot.setDomainGridlinesVisible(true);
//设置区域透明度
vCategoryPlot.setForegroundAlpha(0.5f);
}
}
catch(Exception e)
{}
break;
case 16:
vFreeChart=ChartFactory.createPolarChart(strFreeChartInfo,this.getXYDataset(),true,false,false);
break;
case 17:
vFreeChart=ChartFactory.createScatterPlot(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getXYDataset(),PlotOrientation.VERTICAL,true,false,false);
break;
case 18:
vFreeChart=ChartFactory.createXYBarChart(strFreeChartInfo,strFreeChartXInfo,false,strFreeChartYInfo,this.getIntervalXYDataset(),PlotOrientation.VERTICAL,true,false,false);
break;
case 19:
vFreeChart=ChartFactory.createXYAreaChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getXYDataset(),PlotOrientation.VERTICAL,true,false,false);
break;
case 20:
vFreeChart=ChartFactory.createStackedXYAreaChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getTableXYDataset(),PlotOrientation.VERTICAL,true,false,false);
break;
case 21:
vFreeChart=ChartFactory.createXYLineChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getXYDataset(),PlotOrientation.VERTICAL,true,false,false);
try
{
vXYPlot=(XYPlot)vFreeChart.getXYPlot();
if(vXYPlot!=null)
{
vXYItemRenderer=vXYPlot.getRenderer();
vXYItemRenderer.setBaseOutlinePaint(Color.GRAY);
if(bRender)
{
//设置线面颜色
if(strItemArray.length>0)
{
for(int iIndex=0;iIndex<strItemArray.length;iIndex++)
{
vXYItemRenderer.setSeriesPaint(iIndex,new Color(0,0+iIndex*(255/strItemArray.length),255));
vXYItemRenderer.setSeriesOutlinePaint(0,Color.BLACK);
}
}
//设置X轴、Y轴的显示位置
vXYPlot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
vXYPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
}
//设置线条颜色
vXYItemRenderer.setPaint(new Color(0,100,255));
vXYPlot.setRenderer(vXYItemRenderer);
//背景表格线
vXYPlot.setDomainGridlinesVisible(true);
}
}
catch(Exception e)
{}
break;
case 22:
vFreeChart=ChartFactory.createXYStepChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getXYDataset(),PlotOrientation.VERTICAL,true,false,false);
break;
case 23:
vFreeChart=ChartFactory.createXYStepAreaChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getXYDataset(),PlotOrientation.VERTICAL,true,false,false);
break;
case 24:
vFreeChart=ChartFactory.createTimeSeriesChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getXYDataset(),true,false,false);
try
{
vXYPlot=(XYPlot)vFreeChart.getXYPlot();
if(vXYPlot!=null)
{
vXYItemRenderer=vXYPlot.getRenderer();
vXYItemRenderer.setBaseOutlinePaint(Color.GRAY);
if(bRender)
{
//设置线面颜色
if(strItemArray.length>0)
{
for(int iIndex=0;iIndex<strItemArray.length;iIndex++)
{
vXYItemRenderer.setSeriesPaint(iIndex,new Color(0,0+iIndex*(255/strItemArray.length),255));
vXYItemRenderer.setSeriesOutlinePaint(0,Color.BLACK);
}
}
//设置X轴、Y轴的显示位置
vXYPlot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
vXYPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
//设置线条颜色
vXYItemRenderer.setPaint(new Color(0,100,255));
vXYPlot.setRenderer(vXYItemRenderer);
}
//背景表格线
vXYPlot.setDomainGridlinesVisible(true);
SimpleDateFormat vSimpleDateFormat=null;
if(strTimeAxis.equals("Hour"))
{
vSimpleDateFormat=new SimpleDateFormat("dd日HH点");
}
else
{
vSimpleDateFormat=new SimpleDateFormat("MM月dd日");
}
vDateAxis=(DateAxis)vXYPlot.getDomainAxis();
vDateAxis.setDateFormatOverride(vSimpleDateFormat);
}
}
catch(Exception e)
{}
break;
case 25:
vFreeChart=ChartFactory.createCandlestickChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getOHLCDataset(),true);
break;
case 26:
vFreeChart=ChartFactory.createHighLowChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getOHLCDataset(),true);
break;
case 27:
vFreeChart=ChartFactory.createHighLowChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getOHLCDataset(),true);
break;
case 28:
vFreeChart=ChartFactory.createSignalChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getSignalsDataset(),true);
break;
case 29:
vFreeChart=ChartFactory.createBubbleChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getXYZDataset(),PlotOrientation.VERTICAL,true,false,false);
break;
case 30:
vFreeChart=ChartFactory.createHistogram(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getIntervalXYDataset(),PlotOrientation.VERTICAL,true,false,false);
break;
case 31:
vFreeChart=ChartFactory.createBoxAndWhiskerChart(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getBoxAndWhiskerXYDataset(),true);
break;
case 32:
vFreeChart=ChartFactory.createWindPlot(strFreeChartInfo,strFreeChartXInfo,strFreeChartYInfo,this.getWindDataset(),true,false,false);
break;
case 33:
vFreeChart=ChartFactory.createWaferMapChart(strFreeChartInfo,this.getWaferMapDataset(),PlotOrientation.VERTICAL,true,false,false);
break;
default:
vFreeChart=ChartFactory.createPieChart(strFreeChartInfo,this.getPieDataset(),true,false,false);
break;
}
//图表背景颜色
vFreeChart.setBackgroundPaint(new Color(212,234,243));
}
public JFreeChart getChart()
{
return this.vFreeChart;
}
public void createImageFile(int iWidth,int iHeight,HttpSession session)
{
try
{
java.util.Date vDate=new java.util.Date(System.currentTimeMillis());
java.text.SimpleDateFormat vSimpleDateFormat=new SimpleDateFormat("yyyyMMddHHmmss");
java.util.Date vFileDate=null;
File[] vFileList=(new File(session.getServletContext().getRealPath("/"))).listFiles();
for(int kIndex=0;kIndex<vFileList.length;kIndex++)
{
if(vFileList[kIndex].isFile())
{
if(vFileList[kIndex].getName().indexOf(".jpg")!=-1)
{
vFileDate=vSimpleDateFormat.parse(vFileList[kIndex].getName().substring(0,vFileList[kIndex].getName().length()-4));
//十分钟前的临时文件删除
if(vDate.getTime()-vFileDate.getTime()>60*10*1000)
{
vFileList[kIndex].delete();
}
}
}
}
String strTime=vSimpleDateFormat.format(vDate);
strFileName=session.getServletContext().getRealPath("/")+"\\"+strTime+".jpg";
ChartUtilities.saveChartAsJPEG(new File(strFileName),100,this.getChart(),iWidth,iHeight);
strFileName="/"+getApplicationName(session.getServletContext().getRealPath("/"))+"/"+strTime+".jpg";
}
catch(Exception e)
{}
}
public String getImageFile()
{
return this.strFileName;
}
public String getApplicationName(String strRealPath)
{
String[] strAppArray=strRealPath.split("\\\\");
return strAppArray[strAppArray.length-1];
}
public boolean getRender()
{
return bRender;
}
public void setRender(boolean bRender)
{
this.bRender=bRender;
}
public String getTimeAxis()
{
return this.strTimeAxis;
}
public void setTimeAxis(String strTimeAxis)
{
this.strTimeAxis=strTimeAxis;
}
}
JSP应用示例
<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="java.io.*"%>
<jsp:useBean id="FreeChart" scope="session" class="com.function.FreeChart"/>
<head>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
</head>
<link rel="stylesheet" type="text/css" href="/defineOA/css/default.css">
<%
//初始化
//考虑图形中是否直接链接到统计查询表格
String strTimeList="";
String strMultipleTimeList="";
String strCategoryList="";
String strData="";
String strMultipleData="";
strTimeList="2005-05-01 00:00:00,2005-05-02 05:00:00,2005-05-03 10:00:00,2005-05-04 15:00:00,2005-05-05 20:00:00";
strMultipleTimeList="2005-05-01 00:00:00,2005-05-02 05:00:00,2005-05-03 10:00:00,2005-05-04 15:00:00,2005-05-05 20:00:00";
strCategoryList="JSP工作量,Servlet工作量,Bean工作量";
strData="1,2,3,4,5";
strMultipleData="1,2,3,4,5#2,3,4,5,6#3,4,5,6,7";
FreeChart.createDataset(strMultipleTimeList,strCategoryList,strMultipleData);
FreeChart.createDataset(strTimeList,strData);
FreeChart.setRender(true);
FreeChart.setTimeAxis("Hour");
if(request.getParameter("ChartType")==null)
{
FreeChart.createChart(1,"默认统计图","时间轴","统计值轴");
}
else
{
FreeChart.createChart(Integer.parseInt(request.getParameter("ChartType")),"统计图","时间轴","统计值轴");
}
FreeChart.createImageFile(800,400,session);
response.setHeader("Pragma","No-cache");
response.setDateHeader("Expires",0);
response.setHeader("Cache-Control","no-cache");
%>
<%
for(int iIndex=0;iIndex<FreeChart.vChartTypeArray.length;iIndex++)
{
%>
<input type=button class="GeneralButton" value="<%=FreeChart.vChartTypeArray[iIndex]%>" onclick="window.location='/defineOA/test/chart.jsp?ChartType=<%=iIndex+1%>';">
<%
}
%>
<br>
<fieldset>
<legend>图表</legend>
<!--class="GeneralImage"-->
<br>
<center>
<table>
<tr>
<td style="border:1 solid #3399CC;"><img src="<%=FreeChart.getImageFile()%>"></td>
</tr>
</table>
</center>
<br>
</fieldset>
也可以将应用继续用Bean封装.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -