×é¼þÖÐÖ÷Òª°üÀ¨Öù״ͼ»æÖÆ¡¢±ýͼ»æÖÆ¡¢ÕÛÏßͼ»æÖÆ¡¢¸ÊÌØÍ¼»æÖÆ¡¢µãÏßͼ»æÖƺÍʱÐòͼ»æÖÆ¡£ÏÂÃæÎÒÃǽ«ÏòÄú½²½â»æÖƸ÷ÖÖͼÐεķ½·¨£¬ÒÔ¼°×é¼þJavaBeanÀàÖеÄһЩ·½·¨ºÍ¸÷Àà²ÎÊýÒÔ¼°Ö÷Òª´úÂë½âÊÍ¡£
3.3.1 »æÖÆÖù״ͼ
»æÖÆÖù״ͼµ÷ÓÃ×é¼þÖеÄDrawBar.javaÀ࣬ͨ¹ýdrawBar.jspÒ³ÃæÉú³ÉÖù״ͼ£¬Í¼Æ¬´æ·ÅÓÚ´ÅÅÌÖС£ÔÚJSPÒ³ÃæÖÐÉú³ÉͼƬµÄ´úÂëÈçÏÂËùʾ¡£
//1£®´´½¨»Öù״ͼµÄ¶ÔÏó
DrawBar test=new DrawBar();
//2£®Ìí¼ÓÊý¾Ý¼¯
test.addData("Æ»¹û", 100,"±±¾©");
test.addData("Î÷ºìÊÁ",300,"±±¾©");
test.addData("»Æ¹Ï",200,"±±¾©");
test.addData("²¨ÂÞ",400,"±±¾©");
test.addData("ÌÒ×Ó",500,"±±¾©");
test.addData("ÀóÖ¦",-300,"±±¾©");
test.addData("Ïð½º",300,"±±¾©");
test.addData("éÙ×Ó",200,"±±¾©");
test.addData("Æ»¹û",300,"ÉϺ£");
test.addData("Î÷ºìÊÁ",200,"ÉϺ£");
test.addData("»Æ¹Ï",-400,"ÉϺ£");
test.addData("²¤ÂÜ",200,"ÉϺ£");
test.addData("ÌÒ×Ó",-300,"ÉϺ£");
test.addData("ÀóÖ¦",500,"ÉϺ£");
test.addData("Ïð½º",300,"ÉϺ£");
test.addData("éÙ×Ó",400,"ÉϺ£");
//3£®ÉèÖÃͼƬÊôÐÔ
test.init();
test.setTitle("Ë®¹û¼Û¸ñÖù״ͼ");
test.setYTitle("Ë®¹û¼Û¸ñ");
test.setXTitle("µØµã");
test.setBgColor("white");
test.setIsV(true);
test.setWidth(600);
test.setMargin(0.1);
test.setHeight(500);
test.setXFontSize(10);
test.setYFontSize(10);
//4£®±£´æÍ¼Æ¬
test.saveAbs("e:\\DrawBar.jpg");
Éú³ÉʾÀýÖù״ͼÈçͼ3-2Ëùʾ¡£


ͼ3-2 Ë®¹û¼Û¸ñÖù״ͼ
ÏÂÃæÎÒÃǽéÉÜÒ»ÏÂDrawBar.javaÀà¡£
ÃèÊö£º¸ÃÀàÖ÷ÒªÓÃÓÚ»Öùͼ£¬ÇÒ¸ÃÀàÖ§³Öµ¥Ì¬Ä£ÐÍ¡£
Éú³ÉDrawBar¶ÔÏóÓÐÁ½ÖÖ·½Ê½£º
1£®DrawBar draw=new DrawBar()£»
2£®DrawBar draw= DrawBar.getInstance()£»£¨ÍƼöʹÓã©
ʹÓ÷½·¨£ºÉú³ÉÖù״ͼÖ÷Òª·ÖËIJ½
1£®´´½¨»Öù״ͼµÄ¶ÔÏó£»
2£®Ìí¼ÓÊý¾Ý¼¯£»
3£®ÉèÖÃÏà¹ØÊôÐÔ£»
4£®Éú³ÉͼƬ¡£
°üÃû£ºsmart.jrsoft.chart
ÒýÓõİü¡¢Àà˵Ã÷£º
import java.awt.Color;
import java.io.FileOutputStream;
import smart.jrsoft.chart.*;
·½·¨£º
|
·½ ·¨ Ãû |
Ãè Êö |
|
public void setTitle(String str) |
ÉèÖûÖù״ͼµÄͼ±í±êÌâ |
|
|
ÊäÈë |
String str ͼ±í±êÌâ |
|
|
Êä³ö |
|
|
|
public void setXTitle(String str) |
ÉèÖÃĿ¼ÖáµÄÏÔʾ±êÇ© |
|
|
ÊäÈë |
String str Ŀ¼ÖáµÄÏÔʾ±êÇ© |
|
|
Êä³ö |
|
|
|
public void setYTitle(String str) |
ÉèÖÃÊýÖµÖáµÄÏÔʾ±êÇ© |
|
|
ÊäÈë |
String str ÊýÖµÖáµÄÏÔʾ±êÇ© |
|
|
Êä³ö |
|
|
|
public void setXFontSize(int i) |
ÉèÖÃXÖáÊýÖµµÄ×ÖÌå´óС |
|
|
ÊäÈë |
int i XÖáÊýÖµµÄ×ÖÌå´óС |
|
|
Êä³ö |
|
|
|
public void setYFontSize(int i) |
ÉèÖÃYÖáÊýÖµµÄ×ÖÌå´óС |
|
|
ÊäÈë |
int i YÖáÊýÖµµÄ×ÖÌå´óС |
|
|
Êä³ö |
|
|
|
public void setBgColor(String str) |
¸Ä±ä±³¾°ÑÕÉ« |
|
|
ÊäÈë |
@ int str ±³¾°ÑÕÉ«ÃèÊö ±ÈÈ磺BLACK black blue Blue µÈ |
|
|
Êä³ö |
|
|
|
public void setBgcolor(int red,int green,int blue) |
ÉèÖûÖù״ͼµÄ±³¾°ÑÕÉ« |
|
|
ÊäÈë |
int red ºìÉ«É«ËØÖµ int green ÂÌÉ«É«ËØÖµ int blueÀ¶É«É«ËØÖµ |
|
Ðø±í
|
·½ ·¨ Ãû |
Ãè Êö |
|
|
Êä³ö |
|
|
|
public void setWidth(int width) |
ÉèÖûÖù״ͼµÄͼƬ¿í¶È |
|
|
ÊäÈë |
int width ͼƬ¿í¶È£¨µ¥Î»ÎªÏñËØ£© |
|
|
Êä³ö |
|
|
|
public void setHeight(int height) |
ÉèÖûÖù״ͼµÄͼƬ¸ß¶È |
|
|
ÊäÈë |
int¸ß¶È£¨µ¥Î»ÎªÏñËØ£© |
|
|
Êä³ö |
|
|
|
public void setMargin(double margin) |
ÉèÖÃÿ×éÖù¼äµÄ¾àÀ룬ÊýֵΪ°Ù·Ö±È£¨ÖµÔÚ0¡«1Ö®¼ä£©µÄÐÎʽ |
|
|
ÊäÈë |
double margin Öù¼ä¾à Èç0.1±íʾ¼ä¾àÕ¼Ò»×éÖùºÍ¼ä¾àµÄ°Ù·ÖÖ®10% |
|
|
Êä³ö |
|
|
|
public void setIsV(boolean isV) |
¸Ä±äͼƬÏÔʾ·½Ê½¡£Ä¬ÈÏΪ´¹Ö±ÏÔʾÖùÐÎͼ |
|
|
ÊäÈë |
boolean isV ÊÇ´¹Ö±ÏÔʾ£ºtrue ·ñ´¹Ö±ÏÔʾ£ºfalse |
|
|
Êä³ö |
|
|
|
public void setFileName(String str) |
¸Ä±äÎļþÃû³Æ |
|
|
ÊäÈë |
String str ÎļþÃû³Æ |
|
|
Êä³ö |
|
|
|
public void init() |
³õʼ»¯²ÎÊý |
|
|
ÊäÈë |
|
|
|
Êä³ö |
|
|
|
public void addData(String name,int value, String group) |
Ìí¼ÓÒª½øÐлÖù״ͼµÄÊý¾Ý |
|
|
ÊäÈë |
String name µ¥ÔªÏîÃû³Æ int value µ¥ÔªÖµ String group ¸Ãµ¥ÔªÏîËùÊôµÄ×é |
|
|
Êä³ö |
|
|
|
public boolean saveAbs(String fileName) |
±£´æÉú³ÉµÄÖùͼÎļþ£¨ÎļþÃû³Æ¿É´øÂ·¾¶£© |
|
|
ÊäÈë |
String filenameÎļþÃû³Æ |
|
|
Êä³ö |
return ³É¹¦£ºtrue ʧ°Ü£º false |
|
¸ÃÀàÖÐÌí¼ÓÊý¾Ý·½·¨´úÂëÈçÏÂËùʾ£º
public void addData(String name,int value, String group){
if(dataset!=null){
dataset.addValue(value,group,name);
}else{
dataset=new DefaultCategoryDataset();//ʵÀý»¯
dataset.addValue(value,group,name);
}
}
ÉèÖÃͼƬÊôÐÔ¼°Éú³ÉͼƬ·½·¨´úÂëÈçÏÂËùʾ£º
public boolean saveAbs(String fileName) {
if (!fileName.equals("temp.jpg")) {
this.setFileName(fileName);
}
if (dataset == null) {
return false;
}
else {
JFreeChart chart = null;
if (isV == true) {
chart = ChartFactory.createBarChart3D(
this.title, // ͼ±í±êÌâ
this.XTitle, // Ŀ¼ÖáµÄÏÔʾ±êÇ©
this.YTitle, // ÊýÖµÖáµÄÏÔʾ±êÇ©
dataset, // Êý¾Ý¼¯
PlotOrientation.VERTICAL, // ͼ±í·½Ïò£ºË®Æ½¡¢´¹Ö±
true, // ÊÇ·ñÏÔʾͼÀý(¶ÔÓÚ¼òµ¥µÄÖù״ͼ±ØÐëÊÇfalse)
false, // ÊÇ·ñÉú³É¹¤¾ß
false); // ÊÇ·ñÉú³ÉURLÁ´½Ó
}
else {
chart = ChartFactory.createBarChart3D(
this.title,
this.XTitle,
this.YTitle,
dataset,
PlotOrientation.HORIZONTAL,
true,
false,
false);
}
CategoryPlot categoryplot = chart.getCategoryPlot();
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setCategoryMargin(this.margin);
chart.setBackgroundPaint(this.bgcolor); //ÉèÖñ³¾°ÑÕÉ«
//ÉèÖÃYÖá
NumberAxis numAxis = (NumberAxis) categoryplot.getRangeAxis();
numAxis.setTickLabelFont(new Font("black", Font.ITALIC, this.Ysz));
//ÖáÊý¾Ý×ÖÌå´óС
//ÉèÖÃXÖá
categoryaxis.setTickLabelFont(new Font("black", Font.ITALIC, this.Xsz));
try {
fosJpg = new FileOutputStream(fileName);
ChartUtilities.writeChartAsJPEG(fosJpg, 100, chart, this.width,
this.height, null);
}
catch (Exception e) { }
finally {
this.dataset.clear();
try {
fosJpg.close();
}
catch (Exception e) { }
}
return true;
}
}
3.3.2 »æÖƱýͼ
»æÖƱýͼµ÷ÓÃ×é¼þÖеÄDrawPie.javaÀ࣬ͨ¹ýdrawPie.jspÒ³ÃæÉú³É±ýͼ£¬Í¼Æ¬´æ·ÅÓÚ´ÅÅÌ¡£ÔÚJSPÒ³ÃæÖÐÉú³ÉͼƬµÄ´úÂëÈçÏÂËùʾ¡£
//1.Éú³É»±ýͼµÄÀà¶ÔÏó
DrawPie test=DrawPie.getInstance();
//2.Ìí¼Ó»æÍ¼µÄÊý¾Ý¼¯
test.addData("½ÜÈí", 43.00);
test.addData("ÓîÐÅ", 40.34);
test.addData("ÖÐÈí", 17.23);
test.addData("΢Èí", 32.43);
test.addData("»¯Îª", 45.23);
test.addData("IBM",22.34);
//3.ÉèÖÃͼƬÊôÐÔ
test.init();
test.setBgcolor(Color.white);
test.setTitle("±ýͼ±êÌâ");
test.setWidth(800);
test.setHeight(450);
test.setLabelFontSize(10);
test.setFactor(0.2);
//4.±£´æÍ¼Æ¬
test.saveAbs("E:\\pie.jpg");
//5.±£´æÍ¼Æ¬ÎļþºÍµØÍ¼Îļþ
test.saveAbs("E:\\pie.jpg","E:\\pie.map","http://MyJsp.jsp")
ÉÏÃæ²½ÖèÖеĵÚ4²½ÓëµÚ5²½¿ÉÒÔ¸ù¾Ý²»Í¬ÐèÒª½øÐÐÑ¡Ôñ£¬µÚ5²½ÔÚÉú³ÉͼƬͬʱÉú³ÉͼƬµÄmapÎļþ¡£
Éú³ÉʾÀý±ýͼÈçͼ3-3Ëùʾ¡£
Éú³ÉµÄͼƬmapÎļþÒ²´æ·ÅÓÚ´ÅÅÌÖУ¬¿ÉÓÃÎı¾±à¼Æ÷´ò¿ª£¬ÆäÄÚÈÝÈçÏÂËùʾ¡£
<map id="testName" name="testName">
<area shape="poly" coords="546,253,529,269,508,283,484,295,457,303,400,197,400,197" href="http://localhost:8080/test/MyJsp.jsp?category=IBM&pieIndex=0" alt=""/>
<area shape="poly" coords= "505,109,527,123,545,139,558,157,565,176,568,196,566,215,559,235,546,253,400,197,400,197" href="http://localhost:8080/test/MyJsp.jsp?category=»ªÎª&pieIndex=0" alt=""/>
<area shape="poly" coords="343,91,364,87,385,85,407,84,428,86,448,89,468,94,487,101,505,109,400,197,400,197" href="http://localhost:8080/test/MyJsp.jsp?category=΢Èí&pieIndex=0" alt=""/>
<area shape="poly" coords="269,125,285,114,303,105,322,97,343,91,400,197,400,197" href="http://localhost:8080/test/MyJsp.jsp?category=ÖÐÈí&pieIndex=0" alt=""/>
<area shape="poly" coords="258,258,245,242,236,225,231,208,231,190,235,173,242,156,254,140,269,125,400,197,400,197" href="http://localhost:8080/test/MyJsp.jsp?category=ÓîÐÅ&pieIndex=0" alt=""/>
<area shape="poly" coords="457,303,429,308,401,310,373,308,346,304,320,296,296,286,275,273,258,258,400,197,400,197" href="http://localhost:8080/test/MyJsp.jsp?category=½ÜÈí&pieIndex=0" alt=""/>
</map>

ͼ3-3 ±ýͼ
ÎÒÃÇ¿Éͨ¹ý¶ÁÈ¡Îı¾µÄ·½Ê½¶ÁÈ¡ÎļþÎı¾µÄÄÚÈÝ¡£
BufferedReader in = new BufferedReader(new FileReader("E:\\pie.map"));
String line = null;
while((line = in.readLine())!=null)
{
out.println(line);
}
ÏÂÃæÎÒÃǽéÉÜÒ»ÏÂDrawPie.javaÀà¡£
ÃèÊö£º¸ÃÀàÖ÷ÒªÓÃÓÚ±ýͼ£¬ÇÒ¸ÃÀàÖ§³Öµ¥Ì¬Ä£ÐÍ¡£
Éú³ÉDrawPie¶ÔÏóÓÐÁ½ÖÖ·½Ê½£º
1£®DrawPie draw=new DrawPie ();
2£®DrawPie draw= DrawPie.getInstance();£¨ÍƼöʹÓã©
ʹÓ÷½·¨£ºÉú³É±ýͼÖ÷Òª·ÖÎå²½
1£®½¨»±ýͼµÄ¶ÔÏó´´½¨»Öù״ͼµÄ¶ÔÏó£»
2£®Ìí¼ÓÊý¾Ý¼¯£»
3£®ÉèÖÃÏà¹ØÊôÐÔ£»
4£®Éú³ÉͼƬ¡£
°üÃû£ºsmart.jrsoft.chart
ÒýÓõİü¡¢Àà˵Ã÷£º
import java.awt.Color;
import java.io.FileOutputStream;
import smart.jrsoft.chart.*;
·½·¨£º
|
·½ ·¨ Ãû |
Ãè Êö |
|
public void setTitle(String str) |
ÉèÖñí±êÌâ |
|
ÊäÈë |
String str ͼ±í±êÌâ |
|
Êä³ö |
|
|
public void setBgColor(String str) |
¸Ä±ä±³¾°ÑÕÉ« |
|
ÊäÈë |
String str ±³¾°ÑÕÉ«ÃèÊö ±ÈÈ磺BLACK black blue BlueµÈ |
|
Êä³ö |
|
|
public void setBgcolor(int red,int green,int blue) |
ÉèÖñ³¾°ÑÕÉ«£¨·½Ê½ÎªRGBģʽ£© |
|
ÊäÈë |
int red ºìÉ«É«ËØÖµ int green ÂÌÉ«É«ËØÖµ int blueÀ¶É«É«ËØÖµ |
|
Êä³ö |
|
|
public void setBgcolor(Color color) |
ÉèÖñ³¾°ÑÕÉ« |
|
ÊäÈë |
int colorÑÕÉ«¶ÔÏó |
|
Êä³ö |
|
|
public void setWidth(int width) |
ÉèÖÃͼƬ¿í¶È |
|
ÊäÈë |
int width ͼƬ¿í¶È£¨µ¥Î»ÎªÏñËØ£© |
|
Êä³ö |
|
|
public void setHeight(int height) |
ÉèÖÃͼƬ¸ß¶È |
|
ÊäÈë |
int height¸ß¶È£¨µ¥Î»ÎªÏñËØ£© |
|
Êä³ö |
|
|
public void setLabelFontSize(int i) |
ÉèÖ÷ÖÀà±êÇ©×ÖÌå´óС |
|
ÊäÈë |
int i ×ÖÌå´óС |
|
Êä³ö |
|
|
public void setFactor(double dbl) |
ÉèÖñýͼµÄZÖá |
|
ÊäÈë |
double dbl ZÖá¸ß¶È |
|
Êä³ö |
|
|
public void setForeAlpha(float value) |
ÉèÖñýͼ͸Ã÷¶È |
|
ÊäÈë |
float valueͼÐεÄ͸Ã÷¶ÈÖµ0¡«1 |
|
Êä³ö |
|
|
public void setFileName(String str) |
¸Ä±äÎļþÃû³Æ |
|
ÊäÈë |
String str ÎļþÃû³Æ |
|
Êä³ö |
|
Ðø±í
|
·½ ·¨ Ãû |
Ãè Êö |
|
public void init() |
³õʼ»¯²ÎÊý |
|
ÊäÈë |
|
|
Êä³ö |
|
|
public void addData(String name, double value) |
Ìí¼ÓÒª½øÐлÖù״ͼµÄÊý¾Ý |
|
ÊäÈë |
String name µ¥ÔªÏîÃû³Æ double value µ¥ÔªÖµ |
|
Êä³ö |
|
|
public boolean saveAbs(String fileName) |
Òª±£´æÎªµÄÎļþÃû³Æ ¿ÉÒÔ´øÂ·¾¶ |
|
ÊäÈë |
String filenameÎļþÃû³Æ |
|
Êä³ö |
return ³É¹¦£ºtrue£»Ê§°Ü£ºfalse |
|
public boolean saveMap(String imgName , String mapName, String url) |
Òª±£´æÎªµÄÎļþÃû³Æ ¿ÉÒÔ´øÂ·¾¶ µØÍ¼ÎļþURL |
|
ÊäÈë |
String imgnameÎļþÃû³Æ String mapnameÎļþÃû³Æ String urlµØÖ·Ãû³Æ |
|
Êä³ö |
return ³É¹¦£ºtrue£»Ê§°Ü£ºfalse |
¸ÃÀàÖÐÉú³ÉͼƬµÄ·½·¨ÓÐÁ½ÖÖ£¬·Ö±ðÊÇ£º
public boolean saveAbs(String fileName) {
if (!fileName.equals("temp.jpg")) {
this.setFileName(fileName);
}
if (dataset == null) {
return false;
}
else {
JFreeChart piechart = ChartFactory.createPieChart3D(this.title,
this.dataset, true, false, false);
piechart.setBackgroundPaint(this.bgcolor); //ÉèÖñ³¾°ÑÕÉ«
PiePlot pieplot= (PiePlot) piechart.getPlot();
pieplot.setLabelFont(new Font("black", Font.BOLD, this.labelFontSize));//·ÖÀà±êÇ©×ÖÌå
PiePlot3D pieplot3d = (PiePlot3D) piechart.getPlot();
pieplot3d.setDepthFactor(factor);//3D±ýͼµÄZÖá¸ß¶È
pieplot3d.setStartAngle(290D);
pieplot3d.setDirection(Rotation.CLOCKWISE);
pieplot3d.setForegroundAlpha(this.foreAlpha);
pieplot3d.setNoDataMessage("No data to display");
try {
fosJpg = new FileOutputStream(fileName);
ChartUtilities.writeChartAsJPEG(fosJpg, 100, piechart, this.width,
this.height, null);
}
catch (Exception e) { }
finally {
try {
fosJpg.close();
}
catch (Exception e) { }
}
return true;
}
}
¸Ã·½·¨ÖÐÓû§ÉèÖÃͼƬµÄÃû³Æ¡¢¸ß¶È¡¢¿í¶È¡¢ZÖá¸ß¶ÈµÈ¡£
public boolean saveMap(String imgName,String mapName,String url) {
PrintWriter w = null;
FileOutputStream fosCri = null;
ChartRenderingInfo info=new ChartRenderingInfo();
if (!fileName.equals("temp.jpg")) {
this.setFileName(fileName);
}
if (dataset == null) {
return false;
}else {
JFreeChart piechart = ChartFactory.createPieChart3D(this.title,
this.dataset, true, false, false);
piechart.setBackgroundPaint(this.bgcolor); //ÉèÖñ³¾°ÑÕÉ«
PiePlot pieplot= (PiePlot) piechart.getPlot();
pieplot.setLabelFont(new Font("black", Font.BOLD, this.labelFontSize));
//·ÖÀà±êÇ©×ÖÌå
PiePlot3D pieplot3d = (PiePlot3D) piechart.getPlot();
pieplot3d.setDepthFactor(factor);//3D±ýͼµÄZÖá¸ß¶È
pieplot3d.setStartAngle(290D);
pieplot3d.setDirection(Rotation.CLOCKWISE);
pieplot3d.setForegroundAlpha(this.foreAlpha);
pieplot3d.setNoDataMessage("No data to display");
pieplot3d.setURLGenerator(new StandardPieURLGenerator(url));
try{
fosJpg = new FileOutputStream(imgName);
ChartUtilities.writeChartAsJPEG(fosJpg,100,piechart,this.width,this.height,info);
fosCri = new FileOutputStream(mapName);
w = new PrintWriter(fosCri);
ChartUtilities.writeImageMap(w, "testName", info,true);//Éú³ÉmapÎļþ
w.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try{
w.close();
}catch(Exception e){ }
try{
fosCri.close();
}catch(Exception e){ }
try{
fosJpg.close();
}catch(Exception e){ }
}
return true;
}
}
¸Ã·½·¨ÓëÉÏÃæ·½·¨²»Í¬µÄµØ·½ÊÇÉú³ÉͼƬµÄͬʱÉú³ÉÏà¶Ô¸ÃͼƬµÄmapÎļþ¡£
3.3.3 »æÖÆÕÛÏßͼ
»æÖÆÕÛÏßͼµ÷ÓÃ×é¼þÖеÄDrawLine.javaÀ࣬ͨ¹ýdrawLine.jspÒ³ÃæÉú³ÉÕÛÏßͼ£¬Í¼Æ¬´æ·ÅÓÚ´ÅÅÌÖС£JSPÒ³ÃæÖÐÉú³ÉͼƬµÄ´úÂëÈçÏÂËùʾ¡£
//1.Éú³É»ÕÛÏßͼµÄÀà¶ÔÏó
DrawLine drawLine = DrawLine.getInstance();
//2.Ìí¼Óµã¼¯
drawLine.setXYPointList("µã¼¯Ò»");
drawLine.addPoint(1.0D, 1.0D);
drawLine.addPoint(2D, 4D);
drawLine.addPoint(3D, 3D);
drawLine.addPoint(4D, 5D);
drawLine.addPoint(6D, 7D);
drawLine.addPoint(7D, 7D);
drawLine.addPoint(8D, 8D);
drawLine.addPointList();
drawLine.setXYPointList("µã¼¯¶þ");
drawLine.addPoint(5.0D, 1.0D);
drawLine.addPoint(2D, 3D);
drawLine.addPoint(5D, 3D);
drawLine.addPoint(2D, 5D);
drawLine.addPoint(3D, 2D);
drawLine.addPoint(7D, 1D);
drawLine.addPoint(3D, 8D);
drawLine.addPointList();
//3.ÉèÖÃͼƬÊôÐÔ
drawLine.init();
drawLine.setTitle("²âÊÔÕÛÏßͼ");
drawLine.setXTitle("²âÊÔÕÛÏßͼºá×ø±ê");
drawLine.setYTitle("²âÊÔÕÛÏßͼ×Ý×ø±ê");
drawLine.setBgColor(Color.white);
drawLine.setForeColor(Color.lightGray);
drawLine.setSpaceLineColor(Color.white);
drawLine.setWidth(800);
drawLine.setHeight(450);
//4.±£´æÍ¼Æ¬
drawLine.saveAbs("e:\\DrawLine.jpg");
Éú³ÉʾÀýÕÛÏßͼÈçͼ3-4Ëùʾ¡£


ͼ3-4 ²âÊÔÕÛÏßͼ
ÏÂÃæÎÒÃǽéÉÜÒ»ÏÂDrawLine.javaÀà¡£
ÃèÊö£º¸ÃÀàÖ÷ÒªÓÃÓÚ»ÕÛÏßͼ£¬ÇÒ¸ÃÀàÖ§³Öµ¥Ì¬Ä£ÐÍ¡£
Éú³ÉDrawLine¶ÔÏóÓÐÁ½ÖÖ·½Ê½£º
1£®DrawLine draw=new DrawLine ();
2£®DrawLine draw= DrawLine.getInstance();£¨ÍƼöʹÓã©
ʹÓ÷½·¨£ºÉú³ÉÕÛÏßͼÖ÷Òª·ÖËIJ½
´´½¨»ÕÛÏßͼµÄ¶ÔÏó£»
´´½¨µã¼¯²¢Ìí¼Óµã£»
³õʼ»¯»ÕÛÏß¶ÔÏó£»
Éú³ÉÕÛÏßͼ¡£
°üÃû£ºsmart.jrsoft.chart
ÒýÓõİü¡¢Àà˵Ã÷£º
import java.awt.Color;
import java.io.FileOutputStream;
import smart.jrsoft.chart.*;
·½·¨£º
|
·½ ·¨ Ãû |
Ãè Êö |
|
public void setTitle(String str) |
ÉèÖÃͼ±í±êÌâ |
|
ÊäÈë |
String str ͼ±í±êÌâ |
|
Êä³ö |
|
Ðø±í
|
·½ ·¨ Ãû |
Ãè Êö |
|
public void setXTitle(String str) |
ÉèÖÃĿ¼ÖáµÄÏÔʾ±êÇ© |
|
ÊäÈë |
String str Ŀ¼ÖáµÄÏÔʾ±êÇ© |
|
Êä³ö |
|
|
public void setYTitle(String str) |
ÉèÖÃÖµÖáµÄÏÔʾ±êÇ© |
|
ÊäÈë |
String str ÊýÖµÖáµÄÏÔʾ±êÇ© |
|
Êä³ö |
|
|
public void setBgcolor(String str) |
¸Ä±ä±³¾°ÑÕÉ« |
|
ÊäÈë |
String str±³¾°ÑÕÉ«ÃèÊö ±ÈÈ磺BLACK black blue BlueµÈ |
|
Êä³ö |
|
|
public void setBgcolor(int red,int green,int blue) |
ÉèÖñ³¾°ÑÕÉ« |
|
ÊäÈë |
int redºìÉ«É«ËØÖµ int greenÂÌÉ«É«ËØÖµ int blueÀ¶É«É«ËØÖµ |
|
Êä³ö |
|
|
public void setBgColor(Color color) |
ÉèÖñ³¾°ÑÕÉ« |
|
ÊäÈë |
Color colorÑÕÉ«¶ÔÏó |
|
Êä³ö |
|
|
public void setForeColor(String str) |
ÉèÖûæÕÛÏßÍ¼ÇøÓòµÄ±³¾°ÑÕÉ« |
|
ÊäÈë |
String str»æÕÛÏßÍ¼ÇøÓòµÄ±³¾°Ñ |
