java绘制一个饼图_一个简单的绘制饼图的 Java Bean 实例
1.[代码]ChartBean.java
/**
* Copyright (c) Ian F. Darwin, http://www.darwinsys.com/, 1996-2002.
* All rights reserved. Software written by Ian F. Darwin and others.
* $Id: LICENSE,v 1.8 2004/02/09 03:33:38 ian Exp $
*/
package com.darwinsys.charts;
import java.awt.*;
/**
* Simple charting bean. This version just draws a Pie Chart.
*
* It doesn't even label the pie slices; that is left as a
* (non-trivial) exercise for the reader. Please read the
* Technical Report "How Hard can it be to draw Pie Charts?" by Chris
* van Wyck, Purdue/Bell Labs, 1989??, before you decide how easy
* the work is going to be!
*/
public class ChartBean extends Component {
/** The title to print on the chart */
protected String title;
/** the data to draw */
protected ChartData data[];
/** degrees in a circle */
public static final int CIRCLE = 360;
/** a set of colors to draw the pies in */
protected Color[] colors = {
Color.red,
Color.blue,
Color.green,
Color.pink,
Color.orange
};
/** Construct a ChartBean with a title */
public ChartBean(String s) {
title = s;
setBackground(Color.white);
}
/** Construct a ChartBean with no title (no-arg constructor
* required for Beans).
*/
public ChartBean() {
this(null);
}
public void setLabel(String s) {
title = s;
}
public String getLabel() {
return title;
}
public void setData(ChartData[] newStuff) {
data = newStuff;
repaint();
}
public void paint(Graphics g) {
Dimension sz = getSize();
int w = sz.width, h = sz.width;
if (title != null)
g.drawString(title, w/10, (int)(h*.9));
if (data == null || data.length == 0) {
g.drawOval(0, 0, w, h);
g.drawString("Please provide some data!", w/10, h/2);
return;
}
int total = 0;
int angle = 0;
int rad = 0; // "radians" (actually degrees) to draw
int colNum = 0;
for (int i=0; i
total += data[i].value;
for (int i=0; i
rad = (int)(CIRCLE * ((float)data[i].value / (float)total));
// System.out.println("data: "+data[i].name+";"+data[i].value+
// ",rad="+rad);
g.setColor(colors[colNum++]);
colNum%=colors.length; // keep it in bounds
g.fillArc(0, 0, w, h, angle, rad);
angle += rad;
}
}
public Dimension getMinimumSize() {
return new Dimension(100, 120);
}
public Dimension getPreferredSize() {
return new Dimension(200, 240);
}
}
java绘制一个饼图_一个简单的绘制饼图的 Java Bean 实例相关推荐
- java 语言 写字板_一个简单的java语言写字板.docx
一个简单的java语言写字板.docx 一个简单的JAVA语言写字板一.需求分析1.需求分析:现在网络上各种文档编辑器数不胜数.功能也是应有尽有,有能改变字体的,有可以改变字体颜色的,但是,这些软件有 ...
- java有几大对象_一个 Java 对象到底有多大?
阅读本文大概需要 2.8 分钟. 出处:http://u6.gg/swLPg 编写 Java 代码的时候,大多数情况下,我们很少关注一个 Java 对象究竟有多大(占据多少内存),更多的是关注业务与逻 ...
- java中逻辑运气_一个基于运气的数据结构,你猜是啥?
排行榜 懂行的老哥一看这个小标题,就知道我要以排行榜作为切入点,去讲 Redis 的 zset 了. 是的,经典面试题,请实现一个排行榜,大部分情况下就是在考验你知不知道 Redis 的 zset 结 ...
- 5年java程序员述职报告_一个5年Java程序员的年终总结,献给还在迷茫中的你
我越来越担心我作为一个Java程序员的未来. 恍然间,发现自己在这个行业里已经摸爬滚打了五年了,原以为自己就凭已有的项目经验和工作经历怎么着也应该算得上是一个业内比较资历的人士了,但是今年在换工作的过 ...
- 网易 java社招面试_一个妹子网易Java岗社招面试经历分享
博客群发软件--用 Windows Live Writer完美发布新浪网易blogcnbl 博客群发软件--用 Windows Live Writer完美发布新浪.网易.blogcn.blogbus. ...
- java string最大长度_一个Java字符串中到底有多少个字符?
作者:鸟窝 依照Java的文档, Java中的字符内部是以UTF-16编码方式表示的,最小值是 (0),最大值是(65535), 也就是一个字符以2个字节来表示,难道Java最多只能表示 65535个 ...
- java程序样例_一个完整的java程序示例
一个完整的java程序示例 2020-08-15 05:22 阅读数 74 第一个java程序 package mypack; //相当于一个目录 public class HelloWorld{ p ...
- ppt怎么做流程图饼图_环形流程图如何绘制?5分钟让你精通绘制技巧
环形流程图如何绘制?环形图是由两个及两个以上大小不一的饼图叠在一起,挖去中间所相交的部分所构成的图形.简单的饼图只能表现一个总数据所占的百分比,从多方面展示既不经济也不便利,而环形图恰恰相反,对于多方 ...
- 批处理bat绘制五彩爱心_这个女人通过绘制世界上最长的洞穴而启发了首批热门电子游戏之一...
批处理bat绘制五彩爱心 重点 (Top highlight) Claire L. Evans is the author of Broad Band: The Untold Story of the ...
- python中用于绘制各种图形_如何在Python绘制图形
如何在Python绘制图形 Python提供了一种最流行的绘图库,称为Matplotlib.它是开源的,跨平台的,可以根据数组中的数据制作2D图.它通常用于数据可视化并通过各种图形表示. Matplo ...
最新文章
- 一文读懂产业互联网的前世今生!
- 愿将一生献宏谋——送别于敏侧记
- mysql 织梦 优化,优化分析:分享织梦搭建和后台优化设置
- JAVA中list.contains()方法,要重写equals(),hashcode()方法
- 设计模式之_Strategy_03
- 计算机语言史话论文,【论文节选】自然语言处理发展历史。
- php当前完整url的写法
- 机器学习-极大似然估计
- 博客园博客美化相关文章目录
- oracle驱动包如何看版本,查看JDBC驱动版本
- windows下cmd批量复制文件
- 怎么样才能防御dos攻击
- 逻辑删除还是物理删除
- 小学计算机应用能力培训的计划,小学老师信息技术应用能力提升培训个人计划...
- 禅与 Objective-C 编程艺术 (Zen and the Art of the Objective-C Craftsmanship 中文翻译)
- thinkphp ajax 跨域请求 Access-Control-Allow-Origin 完美解决
- 股票期货盈亏比的计算,胜率与盈亏比的关系
- 用python计算圆柱体的体积和表面积_Java圆柱体表面积和体积计算代码实例
- SpringMVC前端控制器的配置理解
- JavaScript中的二进制搜索算法
热门文章
- Linux进程管理:内核中的优先级继承互斥(rtmutex.h):防止优先级反转
- UNIX网络编程:unpv13e编译错误:net/if_dl.h:没有那个文件或目录
- OpenCv之图像形态学(笔记08)
- background-image属性设置图片尺寸_Matlab | 批量修改图片尺寸及图片灰度化
- linux7本地yum安装,RHEL7安装本地离线yum源仓库
- OpenShift 4 - Service Mesh使用入门
- Visual Studio Code 202008 Python 扩展更新
- Windows Terminal 0.9 发布
- SQL 使用总结四(关于索引)
- c# -- 二维码生成