当前位置:首页 » 编程语言 » java饼图

java饼图

发布时间: 2023-04-27 07:30:52

‘壹’ java 能不能为一个JFrame中的JPanel添加一个饼形图

import java.awt.Graphics;
import javax.swing.*;

class mypanel extends JPanel{
public void paint(Graphics g){
super.paint(g);
g.drawOval(50, 50, 100, 50);//画椭圆其实是画矩形的内接椭圆,(x,y,width,height)起始坐标,外判告接矩形宽和高,
}
}
public class Jpanel extends JFrame {
Jpanel(){
super("椭圆");
setSize(200,200);
setContentPane(new mypanel());
setVisible(true);
}
public static void main(String[] args) {
new Jpanel();
}
}//饼形图应该就是特殊的椭圆吧,掘神明想要什么形状的 ,改变width和瞎轮height就行了

‘贰’ 怎么用JAVA 开发的圆饼图

java绘制饼图
<%@ page language="java" contentType="image/png;charset=GBK" pageEncoding="GBK"
import="java.awt.*, javax.imageio.*,java.awt.geom.*,java.awt.image.*"%>
<%!// 绘制饼图的说明
public void drawTips(String tips, Color color, Arc2D.Double arc2d, Graphics2D g2d) {
Arc2D.Double position = arc2d;
position.setAngleExtent(arc2d.getAngleExtent() / 2);
position.x = arc2d.x - 15;
position.y = arc2d.y - 15;
position.width = arc2d.getWidth() + 50;
position.height = arc2d.getHeight() + 50;
Point2D.Double endPoint = (Point2D.Double) position.getEndPoint();
g2d.setPaint(color);
int stringLength = g2d.getFontMetrics().stringWidth(tips);
if (endPoint.x <= arc2d.getCenterX())
g2d.drawString(tips, (float) endPoint.x - stringLength,
(float) endPoint.y);
else {
g2d.drawString(tips, (float) endPoint.x, (float) endPoint.y);
}
}
%>
<%
// 清空岩滑缓冲区
response.reset();
// 注意这里的MIME类型
response.setContentType("image/png");
//悉枣巧 创建一个 500X375 的图像
int width = 500, height = 375;
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
// 创建Java2D对象
Graphics2D g2d = image.createGraphics();
// 填充整个背景
g2d.setPaint(Color.WHITE);
g2d.fillRect(0, 0, width, height);
// 绘制阴影,由灰色渐进圆角矩形组成
GradientPaint grayGP = new GradientPaint(0, 0, Color.GRAY, width,
height, new Color(218, 214, 212), false);
g2d.setPaint(grayGP);
RoundRectangle2D.Float bgRR = new RoundRectangle2D.Float(5, 5,
width - 5, height - 5, 50, 50);
g2d.fill(bgRR);
// 绘制渐进蓝色圆角矩形背景
GradientPaint blueGP = new GradientPaint(0, 0, new Color(252, 197,
113), width / 2, height / 2, new Color(255, 255, 169), true);
g2d.setPaint(blueGP);
g2d.fillRoundRect(0, 0, width - 5, height - 5, 50, 50);
// 绘制深蓝色圆角矩睁键形轮廓
BasicStroke bs = new BasicStroke(1.2f);
g2d.setStroke(bs);
g2d.setPaint(new Color(55, 71, 105));
g2d.drawRoundRect(0, 0, width - 5, height - 5, 50, 50);
// 绘制图表标题
//String chartTitle = "客户构成分析";
g2d.setColor(Color.BLACK);
g2d.setFont(new Font("宋体", Font.PLAIN, 30));
//int stringLength = g2d.getFontMetrics().stringWidth(chartTitle);
//g2d.drawString(chartTitle, (width - stringLength) / 2, 30);
// 定义圆弧
Arc2D.Double arc2d = new Arc2D.Double();
double startAngle = 30.0, arcAngle = 0.0;
double rectWidth = 295.0, rectHeight = 245.0;
Point2D.Double p2d = new Point2D.Double((width - rectWidth) / 2, 70.0);
int arcType = Arc2D.PIE;
Color color[] = new Color[5];
color[0] = new Color(99, 99, 0);
color[1] = new Color(255, 169, 66);
color[2] = new Color(33, 255, 66);
color[3] = new Color(33, 0, 255);
color[4] = new Color(255, 0, 66);
double bookSales[] = new double[5];
double totalSales = 0.0;
// 定义厚度
int thickness = 25;
for (int i = 0; i < bookSales.length; i++) {
bookSales[i] = 1 + Math.random() * 99;
totalSales += bookSales[i];
}
// 绘制起始角度不大于90度的圆弧
startAngle = 30;
for (int i = 0; i < bookSales.length; i++) {
arcAngle = bookSales[i];
if (startAngle >= 90) {
break;
}
for (int j = thickness; j > 0; j--) {
g2d.setColor(color[i].darker());
arc2d = new Arc2D.Double(p2d.x, p2d.y + j, rectWidth,
rectHeight, startAngle, arcAngle, arcType);
// 填充圆弧
g2d.fill(arc2d);
}
// 更新圆弧的起始角度
startAngle += arcAngle;
}
// 绘制起始角度不小于270度的圆弧
startAngle = 390;
for (int i = bookSales.length - 1; i > 0; i--) {
arcAngle = bookSales[i];
if (startAngle <= 270) {
break;
}
for (int j = thickness; j > 0; j--) {
g2d.setColor(color[i].darker());
arc2d = new Arc2D.Double(p2d.x, p2d.y + j, rectWidth,
rectHeight, startAngle, -arcAngle, arcType);
// 填充圆弧
g2d.fill(arc2d);
}
// 更新圆弧的起始角度
startAngle -= arcAngle;
}
// 绘制起始角度在90度到270度之间的圆弧
startAngle = 30;
for (int i = 0; i < bookSales.length; i++) {
arcAngle = bookSales[i];
if (startAngle > 90 && startAngle < 270) {
for (int j = thickness; j > 0; j--) {
g2d.setColor(color[i].darker());
arc2d = new Arc2D.Double(p2d.x, p2d.y + j, rectWidth,
rectHeight, startAngle + arcAngle, -arcAngle,
arcType);
// 填充圆弧
g2d.fill(arc2d);
}
}
// 更新圆弧的起始角度
startAngle += arcAngle;
}
// 绘制最上面一层圆弧
startAngle = 30;
for (int i = 0; i < bookSales.length; i++) {
arcAngle = bookSales[i];//item.getPercent() * 3.6;
g2d.setColor(color[i]);
arc2d = new Arc2D.Double(p2d.x, p2d.y, rectWidth, rectHeight,
startAngle, arcAngle, arcType);
// 填充圆弧
g2d.fill(arc2d);
// 描绘圆弧轮廓
g2d.setStroke(new BasicStroke(1.2f));
g2d.setPaint(Color.GRAY);
g2d.draw(arc2d);
// 更新圆弧的起始角度
startAngle += arcAngle;
g2d.setFont(new Font("宋体", Font.PLAIN, 12));
}
// 部署图形
g2d.dispose();
// 利用ImageIO类的write方法对图像进行编码
ServletOutputStream sos = response.getOutputStream();
ImageIO.write(image, "PNG", sos);
sos.close();

out.clear();
out = pageContext.pushBody();
%>

‘叁’ 如何用java整合echarts生成饼图

首先要把echarts所需的js和swf文件导入进去

//后台拼图标所需xml
StringBufferoutXml=newStringBuffer();//任务列表xml字符串
@Action("/task/loadMyTaskPercentXml")
()
{
HttpServletResponseres=ServletActionContext.getResponse();
res.setHeader("Cache-Control","no-store");
res.setHeader("Pragma","no-cache");
res.setDateHeader("Expires",0);
res.setContentType("text/xml;charset=GBK");
PrintWriterout=res.getWriter();
StringBufferoutXml=newStringBuffer(
"<?xmlversion="1.0"encoding="GBK"?> "滚绝);
outXml
.append("<chartbaseFontSize='12'caption='任务统计'subcaption=''yAxisMinValue='51650.1'yAxisMaxValue='71118.3'xaxisname='日期'yaxisname='数量'hovercapbg='FFECAA'hovercapborder='F47E00'formatNumberScale='0'decimalPrecision='0'showvalues='1'numdivlines='10'numVdivlines='0'shownames='1'rotateNames='1'>");
outXml.append(" ");
outXml.append("<setname='已完成任务(%)");
outXml.append("'value='"+s1.replace("%","")+"");
outXml.append("'/>");
outXml.append(" ");
outXml.append("<setname='未完链弊成任务(%)");
outXml.append("'value='"+s2.replace("%","")+"");
outXml.append("'/>");
outXml.append(" ");
outXml.append("</chart> "棚备族);
out.print(outXml.toString());
out.flush();
out.close();
returnnull;
}
在后台进行拼装xml,并且返回到页面
<divstyle="display:none"id="taskListGraph">${outXml}</div>
<scripttype="text/javascript">
vartext=document.getElementById("taskListGraph").innerHTML
varchart2=newFusionCharts("${base}/swf/Bar2D.swf?ChartNoDataText=暂无数据&XMLLoadingText=正在载入数据,请稍候","chart02","610","276");
chart2.setDataXML(text);
chart2.render('jdbox');
chart2.addParam("wmode","Opaque");
</script>
这样图就生成好了!

‘肆’ 如何使用java做统计图表

//参考地址http://echarts..com/去网站下js控件,下面是饼图的代码,下图是我的代码效果
functionquery1(housetype,redStatisticsList,text0,cashingSum,tranferSum){
<!--红包发放数据-->


varmyrodiusred=echarts.init(document.getElementById('知颂碧mainrodius'));//ID
varredHousehold=housetype;
varredMoney=redStatisticsList;
varallMoney=0;//总金额搭举
$.each(redStatisticsList,function(index,item){
allMoney=allMoney+Number(item.value);
})
optionTwo={
title:{
text:text0,
subtext:"总金额:"+allMoney+" 提现樱戚总额:"+cashingSum+" 到账总额:"+tranferSum,
x:'center'
},
tooltip:{
trigger:'item',
formatter:"{a}<br/>{b}({d}%)"
},
legend:{
orient:'vertical',
left:'left',
data:housetype
},
series:[
{
type:'pie',
radius:'55%',
center:['50%','60%'],
data:redMoney,
itemStyle:{
emphasis:{
shadowBlur:10,
shadowOffsetX:0,
shadowColor:'rgba(0,0,0,0.5)'
}
}
}
]
};
myrodiusred.setOption(optionTwo);
}

‘伍’ java freechart 饼图厚度

饼图的厚度是可以自己设置的 ,默认厚度一般比较厚。

每一个饼图片区的外廓默认是一条细灰线勾画出来的。PiePlot类提供了如下选择项:
完全不显示片区外廓
通过改变缺宏档省的值来改变全部的片区外廓
单独改变部分饼图的片区外廓

  • 完全关闭/开启片区外廓

调用该方法可以触发PlotChangeEvent事件。


片区外廓的控制

在片区外廓显示的时候,我们可以改变饼图片区的整个外廓颜色或风格或者单个饼图片区的

颜色册镇或风格。 整个外廓颜色或风格的修改需要在基本层里面设置,单个饼图片区的颜色设置

需要在系列层中设置。 在基本层里,如果没有更高层的颜色设置,则调用已定义的默认设

置。 我们可以使用PiePot类的方法州绝粗来改变我们的设置

热点内容
职场的幸福密码是什么 发布:2024-11-01 12:34:57 浏览:748
18经验起床的服务器ip 发布:2024-11-01 12:30:15 浏览:39
这个锁屏密码是什么 发布:2024-11-01 12:24:51 浏览:92
相机存储卡排名 发布:2024-11-01 12:24:49 浏览:958
androidxml格式化 发布:2024-11-01 12:23:14 浏览:165
Vb6编译是错误不知道错误代码 发布:2024-11-01 12:16:23 浏览:159
局域网电脑访问服务器怎么提速 发布:2024-11-01 12:14:09 浏览:322
美创数据库 发布:2024-11-01 12:05:45 浏览:916
你改爱奇艺密码什么意思 发布:2024-11-01 12:04:48 浏览:409
矩阵分解python 发布:2024-11-01 11:58:23 浏览:367