看看他的demo,你就知道怎么用了,在src里面源代码

解决方案 »

  1.   

    除了demo,你可以去下面网站看看Download the code that accompanies this article: 
    http://www.javaworld.com/javaworld/jw-12-2002/opensource/jw-1227-opensourceprofile.zip The JFreeChart homepage: 
    http://www.object-refinery.com/jfreechart jCharts is an open source alternative to JFreeChart: 
    http://jcharts.sourceforge.net For more open source tools, browse Erik Swenson's Open Source Profile columns: 
    http://www.javaworld.com/columns/jw-opensource-index.shtml Browse the Development Tools section of JavaWorld's Topical Index: 
    http://www.javaworld.com/channel_content/jw-tools-index.shtml Chat about Java development in the JavaWorld Forum: 
    http://forums.devworld.com/webx?13@@.ee6b802 Sign up for JavaWorld's free weekly email newsletters: 
    http://www.javaworld.com/subscribe 
      

  2.   

    package demo;
    import java.awt.*;
    import java.sql.*;
    import java.awt.Color;
    import java.util.Date;
    import java.util.Calendar;
    import java.io.*;
    import javax.servlet.http.HttpSession;
    import com.jrefinery.chart.*;
    import com.jrefinery.chart.entity.*;
    import com.jrefinery.chart.renderer.*;
    import com.jrefinery.chart.servlet.*;
    import com.jrefinery.data.Task;
    import com.jrefinery.data.SimpleTimePeriod;
    import com.jrefinery.data.TaskSeries;
    import com.jrefinery.data.TaskSeriesCollection;
    import com.jrefinery.data.IntervalCategoryDataset;
    import com.jrefinery.chart.ChartFactory;
    import com.jrefinery.chart.JFreeChart;
    import com.jrefinery.data.IntervalCategoryDataset;
    import com.jrefinery.chart.plot.CategoryPlot;
    import javax.servlet.*;
    import javax.servlet.http.*;public class GanttDemo extends HttpServlet  {
    private static Connection con=null;
     private static Statement stmt=null;
     private static ResultSet rs=null;
     private static TaskSeries s1=null;
     private static TaskSeries s2=null;
     private static TaskSeriesCollection collection=null;
     public void doPost(HttpServletRequest request, HttpServletResponse response)
             throws IOException, ServletException
         {
             String OneColor = null;
             String TwoColor = null;
                 OneColor =request.getParameter("One");
                 TwoColor=request.getParameter("Two");
          GanttDemo gantt = new GanttDemo();
          PrintWriter pw = new PrintWriter(System.out);
          String filename =generateGanttChart(null, pw);
      }public  static String generateGanttChart(HttpSession session, PrintWriter pw) {
        String filename = null;
        
        try{
          IntervalCategoryDataset dataset=createGanttDataset();
          JFreeChart chart = ChartFactory.createGanttChart("Gantt Chart",
              "Task",
              "Date",
              dataset,
              true,
              true,
              false
              );
          StandardLegend legend = (StandardLegend) chart.getLegend();
          legend.setAnchor(StandardLegend.NORTH);
          chart.setBackgroundPaint(Color.white);
          CategoryPlot plot = chart.getCategoryPlot();
          plot.getRenderer().setSeriesPaint(0, Color.yellow);
          plot.getRenderer().setSeriesPaint(1, Color.red);
          ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
          filename = ServletUtilities.saveChartAsPNG(chart, 800, 600, info, session);
          ChartUtilities.writeImageMap(pw, filename, info);
          pw.flush();
        } catch(Exception e)
            {
                System.out.println("Exception - " + e.toString());
                e.printStackTrace(System.out);
                filename=null;
            }
        return filename;
      }  public  static IntervalCategoryDataset createGanttDataset(){
        try{
          String driver = "oracle.jdbc.driver.OracleDriver";
          Class.forName( driver ).newInstance();
          String url = "jdbc:oracle:thin:@192.168.0.8:1521:develop";
          con = DriverManager.getConnection(url, "szhr", "szhr123");
          stmt=con.createStatement();
          String sql = "select * from EG_TASK order by id";
          ResultSet rs=stmt.executeQuery(sql);
          String telphone = null;
          String Task_name=null;
          Date StartTime,EndTime,PlanStart,PlanEnd;
          int Task_level;
          s1 = new TaskSeries("计划任务");
          s2 = new TaskSeries("实际任务");
              while(rs.next()){
                Task_name = new String(rs.getString("TASK_NAME"));
                StartTime=rs.getDate("TASK_STARTTIME");
                EndTime=rs.getDate("TASK_ENDTIME");
                PlanStart=rs.getDate("TASK_PLANSTART");
                PlanEnd=rs.getDate("TASK_PLANEND");
                s1.add(new Task(Task_name,
                              new SimpleTimePeriod(PlanStart,
                                                   PlanEnd)));
                if(StartTime==null ||EndTime==null){
                  StartTime=EndTime=PlanStart;
                }
                s2.add(new Task(Task_name,
                               new SimpleTimePeriod(StartTime,
                                                    EndTime)));
              }
            con.close();
            collection = new TaskSeriesCollection();
            collection.add(s1);
            collection.add(s2);
            return collection;
           }catch( Exception x ){
              System.err.println( x );
              return null;
           }
      }
    }
      

  3.   

    但jfreechart如果序列数超过9个则颜色就重复了,如柱形图,如超过9个,则从第10个开始颜色就重了,jfreechart version:0.9.4
      

  4.   

    不过也想知道 用它怎么弄jsp+bean的形式