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

📄 customcewolf.jsp

📁 提供 精通Java Web动态图表编程 一书的源代码, 大家赶快下载呀
💻 JSP
字号:
<!--
	Fig. 8.4_11: CustomCewolf.jsp
	功能: Cewolf 编程实例26: 自定义绘制属性
-->
<%@ page contentType="text/html;charset=GB2312"
	import="java.awt.* , java.text. *, java.util.*"
	import="de.laures.cewolf.*, de.laures.cewolf.tooltips.*"
	import="de.laures.cewolf.links.*"
	import="org.jfree.chart.*"
	import="org.jfree.chart.axis.*"
	import="org.jfree.chart.plot.*"
	import="org.jfree.chart.renderer.*"
	import="org.jfree.chart.entity.*"
	import="org.jfree.chart.labels.*"
	import="org.jfree.chart.title.*"
	import="org.jfree.chart.renderer.category.*"
	import="org.jfree.data.*"
	import="org.jfree.data.gantt.*"
	import="org.jfree.data.time.*"
%>
<%@ taglib uri="/WEB-INF/cewolf.tld" prefix="cewolf" %>

<%!
	String chartTitle = "Cewolf 编程实例26: 自定义绘制属性";				
%>

<%
// 创建数据集
DatasetProducer ganttData = new DatasetProducer()
{
  final private long now = System.currentTimeMillis();
  final private long day = 1000 * 60 * 60 * 24;
  final private String[]workflows =
  {
    "分析", "设置", "实施", "测试", "展示", "运作"
  };

  final private String[]person =
  {
    "弗兰克", "保罗", "戴西", "克里丝"
  };

  public Object produceDataset(Map params)
  {
    TaskSeriesCollection ds = new TaskSeriesCollection();
    for (int j = 0; j < 4; j++)
    {
      TaskSeries ser = new TaskSeries(person[j]);
      long lastEnd = now + getRandomTime();
      for (int i = 0; i < workflows.length; i++)
      {
        long myEnd = lastEnd + getRandomTime();
        Task t = new Task(workflows[i], new SimpleTimePeriod(
          new Date(lastEnd), new Date(myEnd)));
        ser.add(t);
        lastEnd = myEnd;
      }
      ds.add(ser);
    }
    return ds;
  }

  private long getRandomTime()
  {
    return day * (long)(Math.random() * 31+15);
  }

  public String getProducerId()
  {
    return "GanttDataProducer";
  }

  public boolean hasExpired(Map params, Date since)
  {
    return true;
  }
};
pageContext.setAttribute("ganttData", ganttData);

ChartPostProcessor chartParameter = new ChartPostProcessor()
{
  public void processChart(Object chart, Map params)
  {
    // 获得 JFreeChart 对象
    JFreeChart jChart = (JFreeChart)chart;
    jChart.setAntiAlias(false);

    // 设置整个图表的背景的绘制属性
    GradientPaint chartBG = new GradientPaint(0, 0, 
      new Color(45, 86, 172), 0, 375, new Color(89, 113, 255));
    jChart.setBackgroundPaint(chartBG);

    // 设置图表标题
    TextTitle title = jChart.getTitle();
    title.setPaint(Color.YELLOW);
    title.setFont(new Font("汉真广标", Font.BOLD, 25));

    // 设置甘特图中,各个直方块的绘制颜色
    CategoryPlot plot = (CategoryPlot)jChart.getPlot();
    BarRenderer renderer = (BarRenderer)plot.getRenderer();
    renderer.setDrawBarOutline(true);

    Color color[] = new Color[5];
    color[0] = new Color(99, 99, 0);
    color[1] = new Color(255, 169, 66);
    color[2] = new Color(255, 0, 66);
    color[3] = new Color(33, 0, 255);
    for (int i = 0; i < color.length; i++)
    {
      renderer.setSeriesPaint(i, color[i]);
    }

    // 设置图表绘制区域的背景绘制属性
    GradientPaint bg = new GradientPaint(0, 50, new Color(248, 253, 255), 0,
      250, new Color(205, 237, 252));
    plot.setBackgroundPaint(bg);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.BLUE);
    plot.setRangeGridlinePaint(Color.RED);

    // 设置坐标轴标题以及刻度值的字体、颜色及其它绘制属性
    Font labelFont = new Font("黑体", Font.BOLD, 16);
    Font tickFont = new Font("宋体", Font.PLAIN, 12);

    DateAxis rangeAxis = (DateAxis)plot.getRangeAxis();
    DateFormat df = new SimpleDateFormat("yyyy-MM");
    DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 30, df);
    rangeAxis.setTickUnit(unit);
    rangeAxis.setTickLabelFont(tickFont);
    rangeAxis.setTickLabelPaint(Color.WHITE);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLabelFont(labelFont);
    domainAxis.setLabelPaint(Color.YELLOW);
    domainAxis.setTickLabelFont(tickFont);
    domainAxis.setTickLabelPaint(Color.WHITE);

    // 定义图例的绘制属性
    StandardLegend legend = (StandardLegend)jChart.getLegend();
    legend.setDisplaySeriesShapes(true);

    legend.setShapeScaleX(1.5);
    legend.setShapeScaleY(1.5);
    legend.setDisplaySeriesLines(true);
    legend.setItemFont(tickFont);
  }
};
pageContext.setAttribute("chartParameter", chartParameter);

%>

<HTML>
 <HEAD>
       <TITLE><%=chartTitle%></TITLE>
 </HEAD>
 <BODY>

<cewolf:chart
	id="gantt"
	title="<%=chartTitle%>"
	type="gantt"
	xaxislabel="工作流">
    <cewolf:data>
        <cewolf:producer id="ganttData" />
    </cewolf:data>
	<cewolf:chartpostprocessor id="chartParameter"/>
</cewolf:chart>

<cewolf:img
	chartid="gantt"
	renderer="/cewolf"
	width="500"
	height="375">
</cewolf:img>

</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 + -