1、用Jfreechart,请参考:
http://asp2.6to23.com/sentom/list.asp?id=10

解决方案 »

  1.   

    String title = "柱状图测试";
    String domain = "单位比较";
    String range = "数值";
    //CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
    DefaultCategoryDataset data = new DefaultCategoryDataset();
    for (int r = 0; r < 5; r++) {
      String rowKey = "单位 [" + (r + 1)+"]" ;
      //第一层循环:分析对象
      for (int c = 0; c < 6; c++) {
        //第二层循环:分析对象在时间点上的数据
        String columnKey = "2001年" + (c + 1) + "月";
        data.addValue(new Double(r * c + 5), rowKey, columnKey);
      }
    }JFreeChart chart = ChartFactory.createVerticalBarChart(title,domain,range,data,true,true,false);
    // then customise it a little...
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.red));
    chart.setTitle(new TextTitle(title, new Font("隶书", Font.ITALIC, 15)));
    CategoryPlot plot = (CategoryPlot)chart.getPlot();
    plot.setForegroundAlpha(0.9f);
    plot.setValueLabelFont(new Font("黑体", Font.TRUETYPE_FONT, 12));
    //plot.setSectionLabelFont(new Font("黑体", Font.TRUETYPE_FONT, 12));
    //注意以下代码
    NumberAxis verticalAxis = (NumberAxis)plot.getRangeAxis();
    verticalAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // 输出文件到指定目录
    String rfname = MathUtil.getRoundCode(22) + "b.jpeg";
    String fileName = "d:/test/" + rfname;
    try {
      ChartUtilities.saveChartAsJPEG(new File(fileName), 100, chart, 600, 600);
      // log.info("....Create image File:" + fileName);
    } catch (IOException exz) {
      System.out.print("....Cant’t Create image File");
    }
      

  2.   

    //我编了一个静态的,看看效果怎么样
    //------------------------------------------------------------------------import java.awt.RenderingHints;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Dimension;
    import java.awt.Container;
    import java.awt.BorderLayout;
    import java.awt.Color;import java.awt.geom.Arc2D;
    import java.awt.geom.Ellipse2D;
    import javax.swing.JFrame;
    import javax.swing.JPanel;public class DrawEllipse
    extends JFrame
    { public DrawEllipse()
    {
    setTitle("柱形椭圆");
    setSize(200,300);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DrawPanel panel=new DrawPanel(); Container contentPane=getContentPane();
    contentPane.add(panel,BorderLayout.CENTER); } public static void main(String[] args) 
    {
    new DrawEllipse().show();
    } class DrawPanel
    extends JPanel
    {
    public void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    Graphics2D g2=(Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON); Dimension szFrame=getSize(); Ellipse2D ellip=new Ellipse2D.Double(szFrame.getWidth()*0.05
    ,szFrame.getHeight()*0.05,szFrame.getWidth()*0.9,
    szFrame.getHeight()*0.5); Arc2D arc=new Arc2D.Double(ellip.getBounds2D(),0,99,Arc2D.PIE);

    g2.setColor(Color.red);
    g2.fill(arc);
    g2.setColor(Color.yellow);
    g2.draw(arc); arc=new Arc2D.Double(ellip.getBounds2D(),99,141,Arc2D.PIE); g2.setColor(Color.blue);
    g2.fill(arc);
    g2.setColor(Color.yellow);
    g2.draw(arc); arc=new Arc2D.Double(ellip.getBounds2D(),240,120,Arc2D.PIE); g2.setColor(Color.green);
    g2.fill(arc);
    g2.setColor(Color.yellow);
    g2.draw(arc); for(int i=2;i<=10;i++)
    { Ellipse2D szPie=new Ellipse2D.Double();
    szPie.setFrame(ellip.getX(),
    ellip.getY()+i,ellip.getWidth(),ellip.getHeight()); g2.setColor(Color.blue);
    arc=new Arc2D.Double(szPie.getBounds2D(),180,60,Arc2D.OPEN);
    g2.draw(arc);
    g2.setColor(Color.yellow);
    g2.draw(arc);
    g2.setColor(Color.green);
    arc=new Arc2D.Double(szPie.getBounds2D(),240,120,Arc2D.OPEN);
    g2.draw(arc);
    g2.setColor(Color.yellow);
    g2.draw(arc); } }
    }
    }
      

  3.   

    Jfreechart我不知道这个是否支持jdk1.1.6版本的?
      

  4.   

    to:yeahjava(梦魂) 
    上面的代码是我写的,实现不了上面提到的要求。
      

  5.   

    因为我只能用再浏览器中,所以只能用jdk1.1.6的,
    它没有这个类包,所以只能自己写类包,但没有算法!!!!
      

  6.   

    import java.awt.RenderingHints;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Dimension;
    import java.awt.Container;
    import java.awt.BorderLayout;
    import java.awt.Color;import java.awt.geom.Arc2D;
    import java.awt.geom.Ellipse2D;
    import javax.swing.JFrame;
    import javax.swing.JPanel;public class DrawEllipse
    extends JFrame
    { public DrawEllipse()
    {
    setTitle("柱形椭圆");
    setSize(400,550);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DrawPanel panel=new DrawPanel(); Container contentPane=getContentPane();
    contentPane.add(panel,BorderLayout.CENTER); } public static void main(String[] args) 
    {
    new DrawEllipse().show();
    } class DrawPanel
    extends JPanel
    {
    public void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    Graphics2D g2=(Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON); Dimension szFrame=getSize(); Ellipse2D ellip=new Ellipse2D.Double(szFrame.getWidth()*0.05
    ,szFrame.getHeight()*0.05,szFrame.getWidth()*0.9,
    szFrame.getWidth()*0.9*0.4); Arc2D arc=new Arc2D.Double(ellip.getBounds2D(),0,99,Arc2D.PIE);

    g2.setColor(Color.red);
    g2.fill(arc);
    g2.setColor(Color.yellow);
    g2.draw(arc); arc=new Arc2D.Double(ellip.getBounds2D(),99,141,Arc2D.PIE); g2.setColor(Color.blue);
    g2.fill(arc);
    g2.setColor(Color.yellow);
    g2.draw(arc); arc=new Arc2D.Double(ellip.getBounds2D(),240,120,Arc2D.PIE); g2.setColor(Color.green);
    g2.fill(arc);
    g2.setColor(Color.yellow);
    g2.draw(arc); for(int i=2;i<=szFrame.getHeight()*0.5;i++)
    { Ellipse2D szPie=new Ellipse2D.Double();
    szPie.setFrame(ellip.getX(),
    ellip.getY()+i,ellip.getWidth(),ellip.getHeight()); g2.setColor(Color.blue);
    arc=new Arc2D.Double(szPie.getBounds2D(),180,60,Arc2D.OPEN);
    g2.draw(arc);
    g2.setColor(Color.yellow);
    g2.draw(arc);
    g2.setColor(Color.green);
    arc=new Arc2D.Double(szPie.getBounds2D(),240,120,Arc2D.OPEN);
    g2.draw(arc);
    g2.setColor(Color.yellow);
    g2.draw(arc); }
    }
    }
    }