您现在的位置: 无忧电子商务网 >> 信息学院 >> 程序开发 >> js >> 正文

- Draw a pie chart

作者:作者:未…    信息学院来源:网络收集    点击数:    更新时间:2006-8-27 我要参与讨论

   import java.util.*;
import java.awt.*;
import java.applet.Applet;

public class Graph extends Applet {
  int    depth, radius;

public void init() {
   float value;
   String at = getParameter("width");
   radius = (at != null) ?  Integer.valueOf(at).intValue() : 100;
   at = getParameter("depth");
   depth = (at != null) ? Integer.valueOf(at).intValue() : 20;
   at = getParameter("values");
   PieChartCanvas c = new PieChartCanvas(radius, depth);
   setLayout(new BorderLayout());

   // Create Hashtable to map color name (String) to Color type
   Hashtable colors = new Hashtable();
   colors.put("green", Color.green);
   colors.put("red", Color.red);
   colors.put("blue", Color.blue);
   colors.put("yellow", Color.yellow);
   colors.put("magenta", Color.magenta);
   colors.put("cyan", Color.cyan);
   colors.put("orange", Color.orange);
   colors.put("pink", Color.pink);
   colors.put("white", Color.white);
   colors.put("black", Color.black);

   // "value-color,value-color,..."
   StringTokenizer t = new StringTokenizer(at, ",");
   String s;
   int i;
   while (t.hasMoreTokens()) {
     s = t.nextToken();
     i = s.indexOf('-');
     value = Float.valueOf(s.substring(0, i)).floatValue();
     c.addSlice(value, (Color)colors.get(s.substring(i + 1)));
    }

   resize(c.getMinimumSize().width, c.getMinimumSize().height);
   add("Center", c);
   }
}

class PieChartCanvas extends Canvas {
   /*
   ** author     Ciaran Treanor  ciaran@broadcom.ie
   */
   final double aspectFudge = 2.5;
   int radius, depth, called = 1, numSlices = 0;
   float total = 0, value[] = new float[10];
   Color color[] = new Color[10];
   Graphics offGraphics;
   Image gfxBuff;

   public PieChartCanvas(int radius, int depth) {
     this.value = value;
     this.color = color;
     this.radius = rad

[1] [2] [3] 下一页

在google里搜索更多- Draw a pie chart

Google
Web www.51ec.org
  • 上一篇信息学院:

  • 下一篇信息学院: 没有了
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    我来说两句 对此文章发表了评论
      昵 称: *必填    ·注册用户·
      评 分: 1分 2分 3分 4分 5分     严禁发表危害国家安全、政治、黄色淫秽等内容的评论,用户需对自己在使用本网站服务过程中的行为承担法律责任。本站管理员有权保留或删除评论内容,评论内容只代表机友个人观点,与本网站立场无关。  
    评 论
    内 容

     
    评论列表 (最新 评论仅限网友观点!)

    推荐文章
  • 此栏目下没有推荐信息学院
  • 供求信息




    | 设为首页 | 加入收藏 | 关于我们 | 广告服务 | 联系方式 | 友情链接 | 版权申明