网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

饼状图的java代码 java饼状图 怎么动态更新数据

jfreechart生成饼状图显示数据的百分比

JFreeChart chart =null;

成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于网站设计、成都做网站、额尔古纳网络推广、微信小程序开发、额尔古纳网络营销、额尔古纳企业策划、额尔古纳品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联为所有大学生创业者提供额尔古纳建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com

PiePlot pieplot = (PiePlot) chart.getPlot();//获取图片对象

// 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位

piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator(

"{0}({2})", NumberFormat.getNumberInstance(),

new DecimalFormat("0.00%")));

以上为关键代码。需要通过setLableGenerator方法设置标签显示格式。StandardPieSectionLabelGenerator对象构造方法中,{0},{2}都将被替换为相应字符,{0}显示的是花生、大豆等信息,{2}显示的是百分比,后面两个参数是设置百分比格式,可以不设置,默认不保留小数点。最后图表显示的信息为:花生(xx.xx%)  小麦(xx.xx%)。

图下面的描述也可以设置显示格式,关键代码为:

// 图例显示百分比:自定义方式, {0} 表示选项, {1} 表示数值, {2} 表示所占比例

piePlot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(

"{0} ({2})"));

注意,这是setLegendLableGenerator()。可以多试试new StandardPieSectionLabelGenerator("{0} ({2})")里的参数设置。

用jsp怎样生成柱状图,饼状图,折线图

JFreeChart 可以绘制饼状图,折线图,柱状图等. awt/swing里可以使用,JSP里也可以使用

JFreeChart是 Java平台下开源的图表类库,是一个完全基于Java的图表开发技术。

支持的图表类型也比较丰富,比如饼图、柱状图、散点图、仪表盘、甘特图等多种图表,

还可以生成Web图形报表。JFreeChart可导出PNG和JPEG格式的文件

例如下面的柱状图

怎么用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创建如下饼图,本人新手,越简单越好,有注释更好

java有第三方的jar包可以支持,jfreechar,可以到网上搜索相关资料,饼状图,柱状图。。都有。

用的时候挺简单的。


文章名称:饼状图的java代码 java饼状图 怎么动态更新数据
当前地址:http://bjjierui.cn/article/dddpepj.html

其他资讯