JFREECHART 자체는 SVG 그래픽을 생성 할 수 없지만 다른 것들은 다음과 같은 것 같습니다.
하나 : Java는 SVG 케이크 맵을 생성하며 각 컬러 대표의 일부를 보여주는 라벨과 함께 제공됩니다.
com.tellhow.svg; import java.fileoutputStream; * @author wind no.1 */public class cakysvgwithlabel {/// 다른 색상 [] colors = { "#f2e692", "#aa1111", "#799ae1", "#3e941b", "#66cc00", "#297110", "#d6a97b", "#82522b", "#aaaaff", "#1111aa", " #ff2222", "#ffaaaa"}; 'utf-8'?> "); sfile.append ("/n "); sfile.append (<svg xmlns : 'http : //www.org/2000/svg')); ( "/n"); "xmlns = 'http://www.w3.ord = 'http://www.w3.org/1999/xlink' "); sfile.append ("/n "); sfile.append ("xml : space = 'default' "); sfile. n "); sfile.append ("버전 = '1.1'너비 = '100%'높이 = '100%'viewbox = '0 2024 570'> "); sfile.append ("/n ") ;;" < "<"< "<fifs> </defs>"); "/n"; , 0,0,16.384, -9.83) 'xmlns ='http://www.w3.org/2000/svg '> "); sfile.append ("/n ");주기 경로 태그 생성. String Path = Creatpath (502, 300, 300, 이름); ); sfile.append ( "</svg>"); 퍼센트 백분율 배열* @param 이름은 색상 대표자 이름을 표시합니다* @return*/ public Stric String CreatPath (Double X0, Double y0, Double [] 이름) {StringBuffer Sfile = New StringBuffer (); x1 = 0; // 새 팬이 double y1 = 0; Radian = 0; Arc Double Textradian = 0; ) {radian = getradian [0]; (x0+getcos (Textradian*r); middley = (y0-getsin (textradian)*r); double % = math.round (Percents [0]*100) /100.0;. k = math.abs (Midey- y0)/(midex-x0); Double Textlen = 70; if (radian <6) {linelen = 90; {유형이 0이면 케이크 맵 표시 if (textradian <(math.pi/2))) {sfile.append ( "<line x1 = '"+middlex+"'y1 = '"+middley+"'x2 = '+(Middlex+Math.cos (sita)*linelen)+"'y2 = '+(Math.sin (sita)*linelen))+"'stroke = '#000000'/> "); sfile. Append ( "/n"); "<text x = '"+(Middlex+Math.cos (sita)+"'y = '+(sita)*textlen) )+" 'space ='font-family = 'font-family ='tahoma 'font-size ='21 'fill ='stroke = 'red'eline- shift ='기준선 '>"+%+"%</text>") ;} else if (textradian> (math.pi/2) && textradian <math.pi) {sfile.append ( "<line x1 = '"+middlex+"'y1 = '"+middley+"'x2 = '"+ (Middlex-Math.cos (Sita)*Linen)+" 'y2 ='"+(Math.sin (Sita)*)+" 'stroke ='#000000 '/>"); /n "); sfile.append ("<text x = ' "+(middlex-math.cos (sita)*textlen)+"'y = ' "+(Middley- (math.sin (sita)*textlen) )+" ''space = 'font-family ='tahoma 'font-size = '21'fill = '빨간색'스트로크 = '빨간색'기준선-시프트 = '기준선'>"+%+"%</text> ");} else if ((textradian> (math.pi) && textradian <(math.pi*3/2)) {sfile.append ("<line x1 = ' "+middlex+"'y1 = ' "+middley+ " 'x2 ='"+(Middlex-Math.cos (Sita)*Linelen)+" 'Y2 ='"+(Middley+(Math.Sin (Sita)*Linelen))+" 'Stroke ='#000000 '/ > "); sfile.append ("/n "); sfile.append ("<text x = ' "+(Middlex- Math.cos (Sita)*TextLen)+"'y = ' "+(Middley+(Math .sin (sita)*textlen))+" 'space ='preserve 'font-family ='tahoma 'font-size ='21 'fill ='빨간색 'stroke ='빨간색 '기준선-시프트 ='기준선 '>." +%+"%</text>"); "+middlex+" 'y1 =' "+middley+" 'x2 =' "+(middlex+math.cos (sita)*linelen)+" 'y2 ='+(middley+math.sin (sita)*linelen) +"스트로크 = '#000000'/>"); "/n"); 'y =' "+(Middley+(Math.sin (sita)*textlen))+" 'space ='preserve 'font-family ='tahoma 'font-size = '21'fill = '빨간색'스트로크 = '빨간색 'Baseline-Shift ='Baseline '> "+%+"%</text> ");} sfile.append ("/n "); if (getradian (percents [0])> math.pi) {sfile.append ( "<path d = 'm"+x0+""+y0+"l"+(x0+r)+"+r+"a "+r+" "+r+"0 1 "+x1+" "+y1+" l "+x0+"+y0+"z 'fill ='"+colors [0]+"/>");} else {sfile.append ( "<path d = 'm"+x0+""+y0+"l "+(x0+r)+"+r+"a"+r+""+r+""+r+"+x1+" "+y1+"l "+x0+" "+y0+"z 'fill =' "+colors [0]+" '/> ");} sfile.append ("/n "); rect x ='+(x0+2*r)+" 'y =' "+(y0-r/2.0+n)+" '' 너비 = '60 'height ='30 'fill =' "+color [i]+" 'stroke ='#fffffff 'Stroke-dasharray ='1,1 ' /> "); sfile.append (" /n " ); 2*r+80)+" 'y =' '+(y0-r/2.0+n+25)+"'space = 'font-family ='font-size = '28'fill = ' "+색상 [0]+" 'stroke ='#000000 '스트로크-다슈어 레이 ='1,1 '베이스 라인-시프트 ='기준선 '> "+이름 [0]+"</text> "); ("/ n ");} else {textradian = radian+(getradian (percents [i]) /2); // 표시기 라인의 아크와 x 축. radian = radian+getradian (Epcents [i]); / // I 자형 팬 앞의 아크 (x0+getCos)*r); ]*100.0; } double sita = math.atan (k); .Append ( "" "<line x1 = '"+midex+"'y1 = '"+middley+"'x2 = '"+(Middlex+math.cos (sita)*linelen)+"'y2 = '"+(수학 .sin (sita)*linelen)+" 'stroke ='#000000 '/>"); (sita)*textlen)+" 'y ='"+(math.sin (sita (sita)*textlen))+" 'space ='preserve 'font-font-font-size ='21 'fill ='빨간색 '스트로크 ='빨간색 '기준선-시프트 ='기준선 '> "+%+"%</text> "); {sfile.append ("<line x1 =' "+middlex+" 'y1 =' "+middley+" ' x2 = '+(Middlex-Math.cos (Sita)*Linelen)+"'y2 = '"+(Middey- (Math.sin (Sita)*Linelen)+"'stroke = '#000000'/>" ); sfile.append ( "/n"); )*textLen)+" 'space ='Preserve 'font-family ='tahoma 'font-size = '21'fill = '빨간색'스트로크 = '빨간색'기준선-시프트 = '기준선'>"+%+"%< /text> "); adian <(math.pi*3/2))) {sfile.append ("<line x1 = ' "+middlex+"'y1 = ' "+middley+"'x2 = ' "+(중간 X -math.cos (sita)*linelen)+" 'y2 ='"+(mthdley+(sita)*linlen)+" 'strong ='#000000 '/>"; /n ");"<text x = ' "+(midex-math.cos (sita)*textlen)+"'y = ' "+(math.sin (sita)*textlen)+"'space = '보존 'font -family ='tahoma 'font-size = '21'fill = 'red'stroke = 'red'baseline-shift = '기준선'> "+%+"%</text> "); radian> (수학. pi*3/2) && textradian <(math.pi*2)) {sfile.append ( "<line x1 = '"+middlex+"'y1 = '"+middley+"'x2 = '+(중간+수학 .cos (sita)*linelen)+" 'y2 ='"+(Middley+Math.sin (sita)*'stroke ='#000000 ' /> "); n "); sfile.append ("<text x = ' "+(middlex+math.cos (sita)*textlen)+"'y = ' "+(math.sin (sita)*textlen)+"' ' space = 'font-family ='tahoma 'font-size ='21 'fill ='red 'stroke ='red 'baseline-shift ='기준선 '>+%+"%"% </text> ""). ;} sfile.Append ( "/n"); // 매개 변수 1; 그림이있는 아크는 180보다 크고 (이 장소는 더 중요하다는 것을 의미합니다. [i])> math.pi) {sfile.append ( "<path d = 'm"+x0+""+y0+"l"+x1+""+y1+"a"+r+""+r+"0"+ (x1 = x0+getcos (Radian)*r)+"+(y1 = y0-getsin*r)+"l "+x0+" "+y0+"z 'fill =' "+색상 [i]+ "/>" "" "" "" "" ");} else {sfile.append ("<path d = 'm "+x0+" "+y0+"l "+x1+" "+y1+"+r+"+ r+"0"+(x1 = (x1 = x0+getCos (라디안)*r)+"+"+"+"+"y0-getsin (radian)*r)+"l "+x0+" "+y0+"z '채우기 = ' "+색 [i]+"' /");} sfile.append (" /n ");} n+= 50; sfile.append ("<rad = ' "+(x0+2*r)+ " 'y ='"+(y0 (y0 -r /2.0+n)+"'width = '60'height = '30 'fill =' "+색상 [i]+" 'stroke ='#fffffff 'dasharray = '1,1' /> "" ") ;;" /n "); sfile.append ("<텍스트 x = ' "+(x0+2*r+80)+"'y = ' "+( y0-r/2.0+n+25)+" 'space ='font-family = '宋体 宋体'font-size = '28 'fill ='"+색상 [0]+" 'stroke ='#000000 '스트로크 -dasharray = '1,1'Baseline-Shift = 'Baseline'> "+names [i]+"</text> "); sfile.append ("/n ");}} return sfile.tostration (); } // 아크 공개 정적 이중 getradian (double fenshu) {return (fenshu*math.pi)/50;} // 사인적 공개 정적 이중 GetSin (Double Radian) {return math.sin (Radian); } // yu xian public static double getcos (double radian)로 돌아갑니다. 10};}; 문자열 =] 이름 = { "主变 :"+data [0]+"one", "isfeller :"+data [1]+"", "line :"+data [2]+"", "+data [3]+"个 ","母线 : "+data [4]+"个 "}; create (data, names);} private static void create (int [] data, string [] names) { try {createesvg ( "d : /a.svg", getpercent (data), names);} catch (예외 e) {e.printstacktrace ();}} private static double [] getpercent (int data []) {double sum = 0; d는 [] = new double [data.length]; i <data.length; i] = (data [i]/sum)*100;} 공개 정적 void createSvg (String filererealPath, double [] 이름 [] 이름 [] 이름 [] 이름 [] ) {string sfile = 초기화 (percents, names); .delete ();} fileoutp utstream fos = fileoutputStream (svgfile); }}}2. Java는 SVG 3D 케이크 맵을 생성합니다.
(이것은 그래픽을 생성 할 수 있지만 불완전한 것은 더 이상 코드를 수정하지 못했습니다. 왜냐하면 나는 이것이 가치가 없다고 생각하기 때문에 더 이상 코드를 수정하지 않았습니다. 그리고 JfreeChart는 더 좋을 수도 있습니다. 기능은 더 강력하지만 이러한 프로그램은 SVG를 더 많이 알게되었습니다. 3d.) 생성 된 효과의 효과는 주로 두 개의 팬이있는 경우 결함이 나타납니다 조정 : svgdeveloper를 사용하여 SVG 그래픽을 열고 팬 모양의 결함 코드를 정렬합니다.
com.xj.svg import java.file; #9aabee ","#3e941b ","#f2e692 ","#66cc00 ","#297110 ","#d6a97b ","#82522b ","#aaaaff ","#1111aa ","#ff22222 "," #ffaaaa ","#aa1111 "}; public static void main (String [] args) {double data [] = {20,20,50}; try {createesvg ("f : /f.svg ", getpercent (data );} catch (예외 e) {e.printstacktrace ();}} 정적 문자열 초기화 (double [] %) {double percents [] = {10,15,5,20,40, 10}; StringBuffer (); "<? xml 버전 = 'utf-8'?>"); 'http://www.w3.org/2000/svg' "); sfile.append ("/n "); sfile.append ("xmlns = 'http://www.w3.org/ 2000/svg' "); sfile.append ("/n "); sfile.append ("xmlns : 'http : //www.org/1999/xlink' "); sfile.append ("xml : space = 'default' "); sfile.append ("/n "); sfile.append ("version = '1.1'width = 'height ='100% 'viewbox ='0 01024 600 '> "); sfile. Append ( "/n"); "Defs> </defs>"; (Path); Sfile.append ( "/n"); * @param x0 origin x * @param y0 origin y * @param langr * @param shortr * @param fenshu * @return * / static String c reatepath (Double x0, Double Y0, Double Langr, Double Shortr, Double Percents [] {stringbuffer = double xbottom = 0; 스트로크 = '#000000'transform = '행렬 (1,0,0,1.638, -9.83)'xmlns = 'http://www.w3.org/2000/svg'> "); sfile.append ("/ n "); for (int i = 0; i <percents.length; i ++) {system.out.println ("i : "+i); radian = radian+getradian (percents [i]); // 첫 번째 팬은 첫 번째 팬, 아크의 합계. +radian); if (radian == math.pi/2) {xbottom = x0; 3/2) {xbottom = x0; Shortr+tanradian*langr*langr; // 底面的 x 底面的 ybottom = y0- (tanradian*langr*shortr) /math.sqrt (sqvalue); // 底面的 y 坐标} else if (radian> math. pi/2 && radian <= math.pi) {System.out.println ( "if2 :"+radian); > radian <math.pi* 3/2) {System.out.println ( "if3 :"xbottom = x0- (langr* shortr); (tanradian*langr*shortr) /math.sqrt (sqvalue);} else if (radian> math.pi*3/2 && radian <math.pi*2) {Systemm .out.println ( "if4 :"+radian ); xbottom = x0+(langr*shortr) /mth.sqrt (sqvalue); .pi {// pi 아크보다 더 큽니다 "); sfile.append ("<path d = 'm "+x0+" "+y0+"l "+(x0+langr)+" "+y0+"+langr+""+shortr+"0 1 0"+xbottom+" "+ybottom+"z ' /> "); sfile.append (" /n "); sfile.append ("<path d ='m "+(x0+langr)+" "+(y0-50)+" A "+langr+" "+shortr+"0 1 0 "+xbottom+" "+(ybottom-50)+"l "+xbottom+"+ybottom+"a"+langr+""+shortr+"0 1"+(x0+ langr)+"+y0+"z ' /> ");" /n "; "+(x0+langr)+"+"+(y0-50)+"a "+langr+"+shortr+"0 1"+xbottom+"+(ybottom-50)+"z '/> "); sfile. Append ( "/n"); "</g>"); ]+" '>"); Sfile.Append ( "/n"); +y0+"a"+langr+""+shortr+"0 0"+xbottom+"z ' />"); x0+langr)+""+(y0-50)+"a"+langr+""+shortr+"0 0"+xbottom+"+(ybottom-50)+"l "+xbottom+" "+ybottom+"a " +langr+"+shortr+"0 1 "+(x0+langr)+" "+y0+"z ' /> "); M "+x0+" ""+(y0-50)+"l"+(x0+langr)+"+"+(y0-50)+"a"+langr+"" "+shortr+"0 0 0 "+xbottom+" "+(ybottom-50)+"z '/> "); sfile.append ("/n "); sfile.append ("</g> "); sfile. append ("/n ");}} else {radian == math.pi/2) {xbottom1 = x0; /2) {xbottom1 = x0; // 底面的 x 坐标 ybottom1 = y0+shortr; // 底面的 y 坐标} else {double tanradian = math.abs (radian (radian)); *tanradian*langr*langr; ybottom1 = y0- (tanradian*langr) /math.sqrt (sqvalue) {system.out.println ( "if2 :"xbottom1 = x0- /math.sqrt (sqvalue)/math.sqrt (sqvalue); xbottom1 = x0- (langr*shortr)/math.sqrt (sqvalue); {System.out.println ( "i"f4 : "+radian); xbottom1 = x0+(langr*shortr) /math.sqrt (sqvalue); ybottom1 = y0+(tanradian*langr*shortr) /math.sqrt (sqvalue) ;}} tradian (percents [i]) >> math.pi) {// pi arc보다 큽니다 ( "<gry = '+colors [i]+"'> ");"/n "; +xbottom+""+ybottom+"+langr+" "" ""+shortr+"0"+xbottom1+"" "+ybottom1+"z ' /> "); sfile.append (" /n "); sfile.append ("< 경로 d = 'm "+(xbottom)+" "" "" "" "" "" ")+"a "+langr+" "+shortr+"0 1 "+xbottom1+"+(ybottom1-50)+"l"+ xbottom1+"+ybottom1+"+langr+"" "" "" "+ybottom+"z ' /> "); = 'm "+x0+" "+(y0-50)+"l "+(xbottom)+"+"+"+(Ybottom-50)+"a"+langr+""+shortr+"0 1"+xbottom1+""+ (ybottom1-50)+"z '/>"( "/n"); println ( "pi보다 작음"); "+색상 [i]+" '> "); sfile.append ("/n "); sfile.append ("<path d ='m "+x0+ ""+y0+"l"+xbottom+""+ybottom+"a"+langr+""+shortr+"0 0"+xbottom1+""+ybottom1+"z ' />"); ; = 'm "+(xbottom)+" ""+(ybottom-50)+"a"+langr+""+shortr+"0"+xbottom1+"+(ybottom1-50)+"l "+xbottom1+". +ybottom1+"a"+langr+""+shortr+"0 1"+xbottom+"+ybottom+"z ' /> "); 50)+"l"+(xbottom)+""+(ybottom-50)+"a"+langr+"+shortr+"0 0 "+xbottom1+"+(ybottom1-50)+"z '/>")). sfile.append ( "/n"); ;} // 아크로 돌아 가기 공개 정적 이중 더블 더블 (더블 퍼센트) {return ( %*math.pi)/50;} // 사인 상태 정적 이중 GetSin (Double Radian) {return math.sin으로 돌아갑니다. (Radian);} // 문자열로 돌아가는 공개 정적 이중 getCos (Double Radian) {return Math.cos (Radian);} private static double [] getpercent (double sum = 0; [] = 새로운 이중 [data.length]; i ++) {percents [i] = (data [i]/sum)*100;} public static void createesvg (String filererealpath, double [] epcents) {String sfile = 초기화 (percents); byte [] bytefil = svgfile = 새 파일 (svgfile.exists ()) {svgfile.delete (); fos.write (bytefil); fos.close ();} catch (예외) {system.out.print (ex.getMessage ());}}}3. JFREECHART를 사용하여 SVG 그래픽을 동적으로 생성합니다.
Java.ava.batik.den.gericdgraphics2d; CategoryDataset; import org.jfree.chart.plot. */ public class barchartdemo {public static void main (string [] args)은 ioexception {categorydataset dataset = getDataset (); "과일 출구 차트", // 차트 제목 "Fruit", // 디스플레이 레이블 "수율", // 숫자 샤프트 데이터 세트의 디스플레이 태그, // 데이터 세트 Plotorientation.Vertical, // 차트 방향 : 수평, 수직 전송 , // 범례를 표시할지 (간단한 열 다이어그램은 false이어야합니다) false, // URL 링크가 생성되는지 //fruit3.svg "); (0,0,400,300); 이미지 jfreeChart 차트 = ChartFactory.createBarchArt3d ( "Fruit Outlet", // 디스플레이 태그 "출력", // 디스플레이 레이블 데이터 세트, // 데이터 세트 Plotorientation.Tertical, // 차트 방향 : URL 링크 생성 여부); jpg, 1, 차트, 400, 300, null);} 마침내 {try {fos_jpg.close ();} catch (예외 e) {}} / ** * 데모를위한 간단한 데이터 세트 가져옵니다 * * @return * / private staticdatasetaset () {) ydataset dataSet = dataSet.AddValue ( "10,"Grape "); (200, "1", "lychee") ADDVALUE (300, "Grape"); ","lychee "); return dataSet;} / *** 데모가 사용하는 조합 데이터 세트 * * * @return * / private static categoryDatasetAsetDataset2 () {defaultCategoryDatasetAset = new defaultCategoryDaset (); DataSet.Add 값 (100, "Beijing", "Apple"); DataSet.AddValue (100, "Shanghai,"Apple "); DataSet.AddValue (100,"Guangzhou ","Apple "); DataSet.AddValue (200, Beijing"). , "pear"); "); DataSet.AddValue (200,"Guangzhou ","Pear "); DataSet.AddValue (300,"Beijing ","Grape "); DataSet.AddValue (300,"Shanghai "," 포도 "); DataSet. addValue (300,"Guangzhou ","Grape "); DataSet.AddValue (400,"Beijing ","Banana "); DataSet.addValue (400,"Shanghai ","Banana "); Guangzhou ","바나나 "); DataSet.AddValue (500,"베이징 ","Litchi "); DataSet.AddValue (500,"Shanghai ","Litchi ");} /*** Exports a JFREECHART는 SVG 파일 * @Param을 내보내십시오 차트, 파일 SVGFILE) XML 문서 DOMIMPLETATION DOMIMPLETATION. / SVG 생성기 차트를 그리십시오. outputstream.close ()};이것을 사용할 때는 두 가지 점에주의를 기울여야합니다.
1. JFREECHART 자체는 SVG 그래픽을 생성 할 수 없으므로 Java 툴킷 인 Apache를 사용해야합니다.
Batik-awt-util.jar
BATIK-DOM.JAR
BATIK-SVGGEN.jar
BATIK-UTIL.jar
BATIK-XML.jar
jfreechart -.0.0.jar
2. SVG를 생성 할 수 있습니다 Renesis SVG 플레이어라고 불리는 또 다른 하나는 시청자가 중국어를 지원합니다.
위의 내용은 Java 생성 케이크 SVG와 JFreeChart의 모든 내용입니다.