⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jxyarea.jsp

📁 提供 精通Java Web动态图表编程 一书的源代码, 大家赶快下载呀
💻 JSP
字号:
<!--
	Fig. 8.2_14: jXYArea.jsp
	功能: JFreeChart实例14: 基于XYDataset数据集的区域图表
-->
<%@ page language="java" contentType="image/png;charset=GB2312"
	import="java.awt.*"
	import="java.text.*"
	import="org.jfree.chart.*"
	import="org.jfree.chart.axis.*"
	import="org.jfree.chart.servlet.*"
	import="org.jfree.chart.plot.*"
	import="org.jfree.chart.renderer.*"
	import="org.jfree.chart.axis.*"
	import="org.jfree.chart.entity.*"
	import="org.jfree.chart.labels.*"
	import="org.jfree.chart.title.*"
	import="org.jfree.chart.renderer.xy.*"
	import="org.jfree.data.*"
	import="org.jfree.data.xy.*"
	import="org.jfree.data.time.*"
	import="org.jfree.ui.*"
	import="org.jfree.util.*"
%>
<%!    
	String chartTitle = "JFreeChart实例14: 基于XYDataset数据集的区域图表";

	// 创建数据集
	public XYDataset createDataset()
	{        
        TimeSeries tsc = new TimeSeries(chartTitle);
        double value = 0.0;
        Day day = new Day();
        for (int i = 0; i < 200; i++) 
		{
            value += Math.random() - 0.5;
            tsc.add(day, value);
            day = (Day) day.next();
        }

        TimeSeriesCollection dataset = new TimeSeriesCollection(tsc);
        return dataset;           
    }

	public JFreeChart createChart(XYDataset dataset)
	{
		// 创建图表对象
		JFreeChart chart = ChartFactory.createXYAreaChart
		(
			chartTitle,					// 图表标题
			"统计时间",		               // 坐标标题
			"随机值",                  // 坐标标题
			dataset,                  // 定义绘制数据
			PlotOrientation.VERTICAL, // 区域图的方向
			true,                     // 定义图表是否包含图例
			true,                     // 定义图表是否包含提示
			false                     // 定义图表是否包含URL
		 );
		 return chart;
	}
%>
<%
		// 创建一个 500X375 的图像
		int width=500, height=375;		

        XYDataset dataset = createDataset();
        JFreeChart chart = createChart(dataset);

        // 开始自定义图表绘制的相关属性

        // 设置整个图表的背景颜色
		GradientPaint bgGP = new GradientPaint(0, 0, Color.YELLOW, 
		  0, height, Color.WHITE, false);
        chart.setBackgroundPaint(bgGP);

        // 设置图表对象的绘制属性
        XYPlot plot = chart.getXYPlot();

        // 设置横轴上的时间刻度的显示格式
		DateAxis domainAxis = new DateAxis("统计时段");        
		DateFormat df = new SimpleDateFormat("yyyy-MM");
		DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 30, df);
		domainAxis.setTickUnit(unit);

        // 保留区域图两端的空白
		//domainAxis.setLowerMargin(0.0);
        //domainAxis.setUpperMargin(0.0);
		
		plot.setDomainAxis(domainAxis);

        // 设置前景色的透明度
		plot.setForegroundAlpha(0.5f);  
        
		// 结束自定义图表绘制的相关属性
		
		ChartRenderingInfo info = 
				   new ChartRenderingInfo(new StandardEntityCollection());

		// 设置图片生成格式
        String fileName = 
		   ServletUtilities.saveChartAsPNG(chart, width, height, info, session);
	
        // 设置图片生成路径
		String graphURL = 
		   request.getContextPath() + "/servlet/DisplayChart?filename=" + fileName; 
%>
<HTML>
 <HEAD>
       <TITLE><%=chartTitle%></TITLE>
 </HEAD>
 <BODY>
       <P ALIGN="CENTER">
       <img src="<%=graphURL %>" border="1" >
       </P>
 </BODY>
</HTML>

<%
/**************************************************************************
 * (C) Copyright 2004-2005 by Jingkui Zhong(钟京馗) and Huan Tang(唐桓).  *
 * All Rights Reserved.                                                   *
 *                                                                        *
 * DISCLAIMER: The authors of this code have used their                   *
 * best efforts in preparing the code. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these codes. The authors *
 * shall not be liable in any event for incidental or consequential       *
 * damages in connection with, or arising out of, the furnishing,         *
 * performance, or use of these programs.                                 *
 **************************************************************************/
 %>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -