java代碼生成扇形圖 java繪制扇形圖

java生成直方圖和餅圖

可以啊,用Java2D繪圖庫(kù)很容易的,都是些線(xiàn)、矩形、扇形、字符串而已,以前項(xiàng)目中這么作過(guò),如果不作通用類(lèi)庫(kù)的話(huà)結(jié)構(gòu)也可以不考慮那么些,直接作個(gè)專(zhuān)用方法,傳數(shù)據(jù)對(duì)象進(jìn)去,返回圖像BufferedImage之類(lèi)就行了。只是些四則運(yùn)算。

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),雁江企業(yè)網(wǎng)站建設(shè),雁江品牌網(wǎng)站建設(shè),網(wǎng)站定制,雁江網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷(xiāo),網(wǎng)絡(luò)優(yōu)化,雁江網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M(mǎn)足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專(zhuān)業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶(hù)成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。

或者找其它類(lèi)庫(kù)。

JAVA實(shí)現(xiàn)簡(jiǎn)單的畫(huà)圖板

樓主寫(xiě)一個(gè)html,很容易把下面代碼嵌入到applet,可以google一下實(shí)現(xiàn),

還有copy自己不知道算不算復(fù)制。。。-_-!

--------------------------------------------------------------------

樓主給你一個(gè)我的,直接保存成pb.java編譯運(yùn)行,就是你要的畫(huà)圖功能 ,可以參考一下

____________________________________________________________________

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import javax.swing.*;

import java.awt.geom.*;

import java.io.*;

class Point implements Serializable

{

int x,y;

Color col;

int tool;

int boarder;

Point(int x, int y, Color col, int tool, int boarder)

{

this.x = x;

this.y = y;

this.col = col;

this.tool = tool;

this.boarder = boarder;

}

}

class paintboard extends Frame implements ActionListener,MouseMotionListener,MouseListener,ItemListener

{

int x = -1, y = -1;

int con = 1;//畫(huà)筆大小

int Econ = 5;//橡皮大小

int toolFlag = 0;//toolFlag:工具標(biāo)記

//toolFlag工具對(duì)應(yīng)表:

//(0--畫(huà)筆);(1--橡皮);(2--清除);

//(3--直線(xiàn));(4--圓);(5--矩形);

Color c = new Color(0,0,0); //畫(huà)筆顏色

BasicStroke size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);//畫(huà)筆粗細(xì)

Point cutflag = new Point(-1, -1, c, 6, con);//截?cái)鄻?biāo)志

Vector paintInfo = null;//點(diǎn)信息向量組

int n = 1;

FileInputStream picIn = null;

FileOutputStream picOut = null;

ObjectInputStream VIn = null;

ObjectOutputStream VOut = null;

// *工具面板--畫(huà)筆,直線(xiàn),圓,矩形,多邊形,橡皮,清除*/

Panel toolPanel;

Button eraser, drLine,drCircle,drRect;

Button clear ,pen;

Choice ColChoice,SizeChoice,EraserChoice;

Button colchooser;

Label 顏色,大小B,大小E;

//保存功能

Button openPic,savePic;

FileDialog openPicture,savePicture;

paintboard(String s)

{

super(s);

addMouseMotionListener(this);

addMouseListener(this);

paintInfo = new Vector();

/*各工具按鈕及選擇項(xiàng)*/

//顏色選擇

ColChoice = new Choice();

ColChoice.add("black");

ColChoice.add("red");

ColChoice.add("blue");

ColChoice.add("green");

ColChoice.addItemListener(this);

//畫(huà)筆大小選擇

SizeChoice = new Choice();

SizeChoice.add("1");

SizeChoice.add("3");

SizeChoice.add("5");

SizeChoice.add("7");

SizeChoice.add("9");

SizeChoice.addItemListener(this);

//橡皮大小選擇

EraserChoice = new Choice();

EraserChoice.add("5");

EraserChoice.add("9");

EraserChoice.add("13");

EraserChoice.add("17");

EraserChoice.addItemListener(this);

////////////////////////////////////////////////////

toolPanel = new Panel();

clear = new Button("清除");

eraser = new Button("橡皮");

pen = new Button("畫(huà)筆");

drLine = new Button("畫(huà)直線(xiàn)");

drCircle = new Button("畫(huà)圓形");

drRect = new Button("畫(huà)矩形");

openPic = new Button("打開(kāi)圖畫(huà)");

savePic = new Button("保存圖畫(huà)");

colchooser = new Button("顯示調(diào)色板");

//各組件事件監(jiān)聽(tīng)

clear.addActionListener(this);

eraser.addActionListener(this);

pen.addActionListener(this);

drLine.addActionListener(this);

drCircle.addActionListener(this);

drRect.addActionListener(this);

openPic.addActionListener(this);

savePic.addActionListener(this);

colchooser.addActionListener(this);

顏色 = new Label("畫(huà)筆顏色",Label.CENTER);

大小B = new Label("畫(huà)筆大小",Label.CENTER);

大小E = new Label("橡皮大小",Label.CENTER);

//面板添加組件

toolPanel.add(openPic);

toolPanel.add(savePic);

toolPanel.add(pen);

toolPanel.add(drLine);

toolPanel.add(drCircle);

toolPanel.add(drRect);

toolPanel.add(顏色); toolPanel.add(ColChoice);

toolPanel.add(大小B); toolPanel.add(SizeChoice);

toolPanel.add(colchooser);

toolPanel.add(eraser);

toolPanel.add(大小E); toolPanel.add(EraserChoice);

toolPanel.add(clear);

//工具面板到APPLET面板

add(toolPanel,BorderLayout.NORTH);

setBounds(60,60,900,600); setVisible(true);

validate();

//dialog for save and load

openPicture = new FileDialog(this,"打開(kāi)圖畫(huà)",FileDialog.LOAD);

openPicture.setVisible(false);

savePicture = new FileDialog(this,"保存圖畫(huà)",FileDialog.SAVE);

savePicture.setVisible(false);

openPicture.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{ openPicture.setVisible(false); }

});

savePicture.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{ savePicture.setVisible(false); }

});

addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{ System.exit(0);}

});

}

public void paint(Graphics g)

{

Graphics2D g2d = (Graphics2D)g;

Point p1,p2;

n = paintInfo.size();

if(toolFlag==2)

g.clearRect(0,0,getSize().width,getSize().height);//清除

for(int i=0; in ;i++){

p1 = (Point)paintInfo.elementAt(i);

p2 = (Point)paintInfo.elementAt(i+1);

size = new BasicStroke(p1.boarder,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);

g2d.setColor(p1.col);

g2d.setStroke(size);

if(p1.tool==p2.tool)

{

switch(p1.tool)

{

case 0://畫(huà)筆

Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);

g2d.draw(line1);

break;

case 1://橡皮

g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder);

break;

case 3://畫(huà)直線(xiàn)

Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);

g2d.draw(line2);

break;

case 4://畫(huà)圓

Ellipse2D ellipse = new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x-p1.x) , Math.abs(p2.y-p1.y));

g2d.draw(ellipse);

break;

case 5://畫(huà)矩形

Rectangle2D rect = new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x-p1.x) , Math.abs(p2.y-p1.y));

g2d.draw(rect);

break;

case 6://截?cái)啵^(guò)

i=i+1;

break;

default :

}//end switch

}//end if

}//end for

}

public void itemStateChanged(ItemEvent e)

{

if(e.getSource()==ColChoice)//預(yù)選顏色

{

String name = ColChoice.getSelectedItem();

if(name=="black")

{c = new Color(0,0,0); }

else if(name=="red")

{c = new Color(255,0,0);}

else if(name=="green")

{c = new Color(0,255,0);}

else if(name=="blue")

{c = new Color(0,0,255);}

}

else if(e.getSource()==SizeChoice)//畫(huà)筆大小

{

String selected = SizeChoice.getSelectedItem();

if(selected=="1")

{

con = 1;

size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);

}

else if(selected=="3")

{

con = 3;

size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);

}

else if(selected=="5")

{con = 5;

size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);

}

else if(selected=="7")

{con = 7;

size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);

}

else if(selected=="9")

{con = 9;

size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);

}

}

else if(e.getSource()==EraserChoice)//橡皮大小

{

String Esize = EraserChoice.getSelectedItem();

if(Esize=="5")

{ Econ = 5*2; }

else if(Esize=="9")

{ Econ = 9*2; }

else if(Esize=="13")

{ Econ = 13*2; }

else if(Esize=="17")

{ Econ = 17*3; }

}

}

public void mouseDragged(MouseEvent e)

{

Point p1 ;

switch(toolFlag){

case 0://畫(huà)筆

x = (int)e.getX();

y = (int)e.getY();

p1 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p1);

repaint();

break;

case 1://橡皮

x = (int)e.getX();

y = (int)e.getY();

p1 = new Point(x, y, null, toolFlag, Econ);

paintInfo.addElement(p1);

repaint();

break;

default :

}

}

public void mouseMoved(MouseEvent e) {}

public void update(Graphics g)

{

paint(g);

}

public void mousePressed(MouseEvent e)

{

Point p2;

switch(toolFlag){

case 3://直線(xiàn)

x = (int)e.getX();

y = (int)e.getY();

p2 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p2);

break;

case 4: //圓

x = (int)e.getX();

y = (int)e.getY();

p2 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p2);

break;

case 5: //矩形

x = (int)e.getX();

y = (int)e.getY();

p2 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p2);

break;

default :

}

}

public void mouseReleased(MouseEvent e)

{

Point p3;

switch(toolFlag){

case 0://畫(huà)筆

paintInfo.addElement(cutflag);

break;

case 1: //eraser

paintInfo.addElement(cutflag);

break;

case 3://直線(xiàn)

x = (int)e.getX();

y = (int)e.getY();

p3 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p3);

paintInfo.addElement(cutflag);

repaint();

break;

case 4: //圓

x = (int)e.getX();

y = (int)e.getY();

p3 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p3);

paintInfo.addElement(cutflag);

repaint();

break;

case 5: //矩形

x = (int)e.getX();

y = (int)e.getY();

p3 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p3);

paintInfo.addElement(cutflag);

repaint();

break;

default:

}

}

public void mouseEntered(MouseEvent e){}

public void mouseExited(MouseEvent e){}

public void mouseClicked(MouseEvent e){}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==pen)//畫(huà)筆

{toolFlag = 0;}

if(e.getSource()==eraser)//橡皮

{toolFlag = 1;}

if(e.getSource()==clear)//清除

{

toolFlag = 2;

paintInfo.removeAllElements();

repaint();

}

if(e.getSource()==drLine)//畫(huà)線(xiàn)

{toolFlag = 3;}

if(e.getSource()==drCircle)//畫(huà)圓

{toolFlag = 4;}

if(e.getSource()==drRect)//畫(huà)矩形

{toolFlag = 5;}

if(e.getSource()==colchooser)//調(diào)色板

{

Color newColor = JColorChooser.showDialog(this,"調(diào)色板",c);

c = newColor;

}

if(e.getSource()==openPic)//打開(kāi)圖畫(huà)

{

openPicture.setVisible(true);

if(openPicture.getFile()!=null)

{

int tempflag;

tempflag = toolFlag;

toolFlag = 2 ;

repaint();

try{

paintInfo.removeAllElements();

File filein = new File(openPicture.getDirectory(),openPicture.getFile());

picIn = new FileInputStream(filein);

VIn = new ObjectInputStream(picIn);

paintInfo = (Vector)VIn.readObject();

VIn.close();

repaint();

toolFlag = tempflag;

}

catch(ClassNotFoundException IOe2)

{

repaint();

toolFlag = tempflag;

System.out.println("can not read object");

}

catch(IOException IOe)

{

repaint();

toolFlag = tempflag;

System.out.println("can not read file");

}

}

}

if(e.getSource()==savePic)//保存圖畫(huà)

{

savePicture.setVisible(true);

try{

File fileout = new File(savePicture.getDirectory(),savePicture.getFile());

picOut = new FileOutputStream(fileout);

VOut = new ObjectOutputStream(picOut);

VOut.writeObject(paintInfo);

VOut.close();

}

catch(IOException IOe)

{

System.out.println("can not write object");

}

}

}

}//end paintboard

public class pb

{

public static void main(String args[])

{ new paintboard("畫(huà)圖程序"); }

}

用java編寫(xiě)一個(gè)顏色為紅色,粗線(xiàn)型的笑臉和哭臉,需要繼承JFrame類(lèi),用java中的繪制圖形做

JFreeChart------------它是一種組件技術(shù),專(zhuān)用于在java中實(shí)現(xiàn)圖形報(bào)表

----------餅圖,柱狀圖,折線(xiàn)圖

JFreeChart它是一種獨(dú)立圖表技術(shù),它與struts2本身并無(wú)關(guān)系,只不過(guò),它可以與struts2配合使用

餅圖的步驟:

1、創(chuàng)建一個(gè)web工程

2、導(dǎo)入struts2框架(core,struts2-jfreeChart)

3、向工程導(dǎo)入(jfreechart.jar,jcommon.jar)

4、創(chuàng)建BaseAction繼承于A(yíng)ctionSupport,并且,在類(lèi)中,聲明一個(gè)屬性 JFreeChart chart;并且生成set,get方法

5、編寫(xiě)ChartAction類(lèi),繼承于BaseAction

6、在ChartAction類(lèi)中,編寫(xiě) showPie()用于顯示餅圖

7、在struts.xml配置當(dāng)前action

8、在index.jsp配置,通過(guò)img src="chart!showPie.action"進(jìn)入到指定方法

=================================================================================================================

9、編寫(xiě)ChartDao類(lèi),模擬從數(shù)據(jù)庫(kù)查詢(xún)數(shù)據(jù)

//得到餅圖需要的數(shù)據(jù)集

public DefaultPieDataset getPieDataset(){

DefaultPieDataset dp = new DefaultPieDataset();

dp.setValue("聯(lián)想",321);

dp.setValue("華碩",189);

dp.setValue("戴爾",98);

dp.setValue("IBM",213);

dp.setValue("Apple",287);

dp.setValue("惠普",120);

dp.setValue("SONY",87);

return dp;

}

==============================================================================================================

10、在ChartAction中的showPie方法,生成餅圖

public String showPie(){

//得以要顯示的數(shù)據(jù)集,根據(jù)數(shù)據(jù),生成餅圖

DefaultPieDataset dp = dao.getPieDataset();

//chart = ChartFactory.createPieChart("標(biāo)題",要顯示在餅圖中的數(shù)據(jù)集,是否顯示顏色說(shuō)明,"是否顯示工具提示","是否顯示網(wǎng)絡(luò)地址 ");

chart = ChartFactory.createPieChart("一季度各電腦品牌銷(xiāo)售匯總",dp,true,false,false);

return "success";

}

=============================================================================================================

11、在struts.xml文件,進(jìn)行相關(guān)配置

package name="struts2" extends="struts-default"

result-types

result-type name="chart" class="org.apache.struts2.dispatcher.ChartResult"/

/result-types

action name="chart" class="org.java.web.ChartAction"

result name="success" type="chart"

param name="width"800/param

param name="height"600/param

/result

/action

/package

=================================================================================================================

12、解決亂碼

標(biāo)題區(qū)的亂碼

Font f1 = new Font("隸書(shū)",Font.BOLD,40);

TextTitle tt = new TextTitle("一季度各電腦品牌銷(xiāo)售匯總",f1);

chart.setTitle(tt);//綁定標(biāo)題

顏色提示區(qū)亂碼

Font f2 = new Font("隸書(shū)",Font.BOLD,20);

LegendTitle lt = chart.getLegend();

lt.setItemFont(f2);//設(shè)置該區(qū)域的字體

解決餅圖中的亂碼

PiePlot pp = (PiePlot) chart.getPlot();//得到餅圖區(qū)域

pp.setLabelFont(f2);//設(shè)置餅圖區(qū)域中的字體

=============================================================================================================

13、設(shè)置餅圖中要顯示的數(shù)據(jù)格式

//該對(duì)象,用于指定餅圖要顯示的數(shù)據(jù)格式 //0:key //1:value 2:百分比

StandardPieSectionLabelGenerator sc = new StandardPieSectionLabelGenerator("{0},{1}臺(tái),{2}");

//把顯示的格式,綁定餅圖中

pp.setLabelGenerator(sc);

需要完整版請(qǐng)聯(lián)系我

Java繪制扇形圖

import java.awt.Graphics;

public class test {

public static void main(String[] args) {

Graphics g = null;

OKString os = new OKString();

os.paint(g);

}

}

null是對(duì)Graphics的聲明對(duì)象(方式)

希望可以幫到你,要是不理解可以再聊。。。

如何用java整合echarts生成餅圖

1.分為線(xiàn)上echarts、線(xiàn)下echarts(推薦使用線(xiàn)下echarts)。

2.如果是使用線(xiàn)下echarts,第一步開(kāi)始下載官網(wǎng)的插件包,先進(jìn)入主頁(yè)看見(jiàn)右上角的下載,根據(jù)自己需要的圖表下載對(duì)應(yīng)的插件包。

powerdesigner怎么用java代碼生成類(lèi)圖

使用PowerDesigner軟件逆向生成java類(lèi)圖的方法、步驟:1、打開(kāi)PowerDesiger軟件,點(diǎn)擊文件-建立新模型,新建Obect-OrientedModel2、點(diǎn)擊語(yǔ)言-ReverseEngineerJava,彈出反向生成類(lèi)圖設(shè)置窗口;3、在反向生成類(lèi)圖設(shè)置窗口中,選擇ReverseEngineer,可以選擇JavaFiles或JavaDirectories等,在這里我選擇JavaDirectories;4、然后點(diǎn)擊Add按鈕添加目錄,在這里我選擇一個(gè)java源文件目錄;5、點(diǎn)擊確定,PowerDesigner會(huì)顯示生成進(jìn)度窗口,完成以后在PowerDesigner工作空間下會(huì)顯示類(lèi)圖目錄結(jié)構(gòu);6、到此便將選中的Java目錄下的Java類(lèi)文件生成了靜態(tài)類(lèi)結(jié)構(gòu),

新聞名稱(chēng):java代碼生成扇形圖 java繪制扇形圖
文章路徑:http://muchs.cn/article12/hjdhdc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版品牌網(wǎng)站設(shè)計(jì)、面包屑導(dǎo)航、自適應(yīng)網(wǎng)站、Google、網(wǎng)頁(yè)設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)