JFReechart自体はSVGグラフィックを生成できませんが、別のものを使用して生成することができます。
1つ:JavaはSVGケーキマップを生成します。これには、各色の代表者の一部を示すラベルが付属しています
パッケージcom.tellhow.svg。 "#f2e692"、 "#aa1111"、 "#799ae1"、 "#3e941b"、 "#66cc00"、 "#297110"、 "#d6a97b"、 "#82522b"、 "#aaaff"、 "#1111aa"、 「#FF2222」、「#ffaaaa」}; 'utf-8'?> "); sfile.append("/n "); sfile.append(<svg xmlns: 'http://www.org/2000/svg'")); ( "/n"); = 'http://www.w3.org/1999/xlink' "); sfile.append("/n "); sfile.append(" xml:space = 'default' "); sfile。 n "); sfile.append(" version = '1.1' width = '100%' height = '100%' viewbox = '0 0 2024 570'> "); sfile.append("/n ");;" <"<" <"<defs> </defs>"); 、0,0,16.384、-9.83) 'xmlns =' http://www.w3.org/2000/svg '> "); sfile.append("/n "); //循環パスタグを作成します。 String Path = 502、300、300、名前); ); sfile.append( "</svg>");パーセントパーセント配列* @param名lightrive* @return*/ public stric string creatpath(double x0、double [] percents、string [] names {stringbuffer sfile = new stringbuffer(); x1 = 0; radian = 0; == 0){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; {タイプが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"); sfile.append( "<text x = '+(middlex+math.cos(sita)*textlen)+" y =' "+(math.sin(sita)*textlen) )+"space = 'preserve' font-family = 'tahoma' font-size = '21' fill = 'stroke =' red 'eline- shift =' baseline '>"+パーセント+"%</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)*linlen))+"stroke = '#000000'/>"); /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 =' red 'stroke =' red 'baseline-shift =' baseline '>"+パーセント+"%</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 = '"+(middery+(math .sin(sita)*textlen))+"'space =' preserve 'font-family =' tahoma 'font-size =' 21 'fill =' red 'stroke =' red 'baseline-shift =' baseline '>" +パーセント+"%</text>") "+middlex+" 'y1 =' "+middley+" 'x2 =' "+(middlex+math.cos(sita)*linelen)+" 'y2 =' "+(middley+math.sin(sita)*linelen) +"stroke = '#000000'/>"); 'y =' "+(middley+(math.sin(sita)*textlen))+" 'space =' preserve 'font-family =' tahoma 'font-size = '21' fill = 'red' stroke = '赤'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 0"+x1+""+y1+" l "+x0+"+y0+"z 'fill ='"+colors [0]+"'/>");} else {sfile.append( "<path d =' m"+x0+""+y0+"l "+(x0+r)+"+r+"a"+r+"" "+r+"+x1+""+y1+"l"+x0+""+y0+"z 'fill ='"+colors [0]+" '/>」 width = '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 = 'pront-family =' font-size = '28' fill = ' "+colors [0]+" 'stroke ='#000000 'stroke-dashArray =' 1,1 'baseLine-shift =' baseline '> "+names+" </text> ");("/"/ n ");} else {textradian = radian+(getradian(percents [i]) /2); //インジケーターラインとx軸の弧を取得します。radian= radian+getradian(percents [i]); / / // I字型ファンの前のアーク(x0+getCos(textradian)*r); ]*100.0; ;} double sita = math.atan(k); .Append( "" <line x1 = '"+midex+"' y1 = '"+middley+"' x2 = '"+(middlex+math.cos(sita)*linelen)+"' y2 = '"+(math .sin(sita)*linelen)+"stroke = '#000000'/>"); (sita)*textlen)+"'y ='"+(math.sin(sita(sita)*textlen))+"'space =' preserve 'font-font-font-font-size =' 21 'fill =' red 'stroke =' red 'baseline-shift =' baseline '> "+パーセント+"%</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 = 'red' stroke = 'red' baseline-shift = 'baseline'>"+パーセント+"%< /text> "); adian <(math.pi*3/2)))){sfile.append(" <line x1 = '"+middlex+"' y1 = '"+middley+"' x2 = '"+(middlex -math.cos(sita)*linelen)+"'y2 ='"+(mthdley+(sita)*linlen) 'strong ='#000000 '/> "); /n ");" <text x = '"+(midex-math.cos(sita)*textlen)+"' y = '"+(math.sin(sita)*textlen)+"' space = 'preserve 'font -family =' tahoma 'font-size = '21' fill = 'red' stroke = 'red' baseline-shift = 'baseline'> "+パーセント+"%</text> "); radian>(math。 pi*3/2)&& textradian <(math.pi*2)){sfile.append( "<line x1 = '"+middlex+"' y1 = '"+middley+"' x2 = '"+(middlex+math .cos(sita)*linelen)+"'y2 ='"+(middley+math.sin(sita)*linelen)+"stroke = '#000000' />"); n "); sfile.append(" <text x = '"+(middlex+math.cos(sita)*textlen)+"' y = '"+(math.sin(sita)*textlen)+"' ' space = 'preserve' font-family = 'tahoma' font-size = '21' fill = 'red' stroke = 'red' baseline-shift = 'baseline'>+"%"% "%</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(radian)*r)+" l "+x0+" "+y0+" z 'fill =' "+colors [i]+ "'/>" "" "" "" "" "");} else {sfile.append( "<path d =' m"+x0+"" "+y0+"+x1+""+y1+"+r+" "+ r+"0 0"+(x1 =(x1 = x0+getcos(radian)*r)+"+(y1 = y0-getsin(radian)*r)+" l "+x0+" "+y0+" z 'フィル= '"+color [i]+"' /");} sfile.append(" /n ");} n+= 50; sfile.append(" <rad = '"+(x0+2*r)++ "'y ='"+(y0(y0 -r /2.0+)+"'Width = '60' height = '30 '' "+colors [i]+" 'stroke ='#fffffff 'DashArray = '1,1' /> "" "");; " /n"); sfile.append( "<text x = '"+(x0+2*r+80)+"' y = '"+( y0-r/2.0+n+25)+"'space =' preserve 'font-family ='宋体 'font-size = '28' fill = '"+colors [0]+"' stroke = '#000000'ストローク-dasharray = '1,1' Baseline-shift = 'baseline'> "+names [i]+" </text> "); sfile.append("/n ");}} return sfile.tostration(); } // arc public static double getradian(double fenshu){return(fenshu*math.pi)/50;} //サインパブリックstatic double getsin(double radian){return math.sin(radian); } // yu xian public static double getcos(double radian)に戻る{return math.cos(radian); 10}; string [] names = {"主变:"+data [0]+"one"、 "+data [1]+" "、" line: "+data "+data [3]+"个 "、"母线: "+data [4]+"个 "}; create(data、names);} private static void create(int [] data、string [] names){ try {createsvg( "d:/a.svg"、getpercent(data)、names);} catch(exception e){e.printstacktrace();}} private static double [] getPercent(int data []){double sum = 0; ; i <data.length; percents [i] =(data [i]/sum)*100;} ){string sfile = initial(percents、names); .delete();} fileoutp utstream fos = new fileoutputstream(svgfile); }}}2。JavaはSVG 3Dケーキマップを生成します。
(これはグラフィックを生成することができますが、不完全です、私はもうコードを変更しませんでした。これは価値がないと思うので、JFreechartはより良いかもしれません。機能はより強くなりますが、これらのプログラムはSVGをもっと知りました。その中のいくつかのラベルはありますか?)3D。)生成された効果は、主に2つのファンの形で表示されます調整:SVGDeveloperを使用してSVGグラフィックを開き、障害のファンコードをアレンジします。
パッケージcom.xj.svg。 #9aabee "、"#3e941b "、"#f2e692 "、"#66cc00 "、"#297110 "、"#d6a97b "、"#82522b "、"#aaaaff "、"#1111aa "、"#ff22222 "、"、 " #ffaaaaa "、"#aa1111 "}; public static void main(string [] args){double data [] = {20,20,50}; try {createsvg(" f:/f.svg "、getPercent(data) );} catch(例外e){e.printstacktrace();}} static string initialize(double []パーセント){= {10,15,5,20,40、10}; StringBuffer(); 'http://www.w3.org/2000/svg' "); sfile.append("/n "); sfile.append(" xmlns = 'http://www.w3.org/ 2000/svg' ' 」 = 'default' "); sfile.append("/n "); sfile.append(" version = '1.1' width = 'height =' 100% 'viewbox =' 0 0 1024 600 '> "); sfile。 appled(n "); sfile.append("/n "); (パス); 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 [] ){string sfile = double xbottom = 0; stroke = '#000000' transform = 'matrix(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]); //最初のファンは、最初のファン、arc.out.println( "+radian)の合計を+radian); radian == math.pi/2){xbottom = x0; 3/2){xbottom = x0; // x座標= y0+shortr; Shortr+Tanradian*Tanradian*langr*langr; //底面的x {system.out.println( "if2:"+radian); > math.pi && radian <math.pi* 3/2){system.out.println( "+radian); (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 Arcよりも大きい、50%を超えるsfile.append( "<gry = '"+color [i]+"'>"); "); 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 1"+(x0+(x0+(x0+) langr)+""+y0+"z ' />"); "+(x0+langr)+" "+(y0-50)+" a "+langr+"+shortr+"0 1 0"+xbottom+"+(ybottom-50)+" z '/> "); sfile。 append( "/n"); sfile.append( "</g>"); ]+"'>"); sfile.append( "/n"); +y0+"+langr+" "+shortr+" 0 "+xbottom+"+ybottom+"z ' />"); x0+langr)+""+(y0-50)+"a"+langr+""+shortr+"0 0"+xbottom+"+(ybottom-50)+" l "+xbottom+" "+ybottom+" a " +langr+""+shortr+"0 1"+(x0+langr)+"+" 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 {if(radian == math.pi/2){xbottom1 = x0; /2){xbottom1 = x0; // *Tanradian*Langr*langr; ybottom1 = y0-(tanradian*langr*shortr)/math.sqrt(sqvalue); /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よりも、つまり50%を超えるSystem.out.println( "pi than pi"); ( "<gry = '"+colors [i]+"'>"); +xbottom+""+ybottom+"+langr+" "" ""+shortr+"0 1 0"+xbottom1+""+ybottom1+"z ' />"); sfile.append( " /n"); sfile.append( "<<< PATH D = 'M "+(XBOTTOM)+" "" "" "" ")+" a "+langr+" "+shortr+" 0 1 0 "+xbottom1+"+(ybottom1-50)+"l"+ Xbottom1+""+ybottom1+"+langr+" "" "" ""+xbottom+""+ybottom+"z ' />"); = 'm "+x0+" "+(y0-50)+" l "+(xbottom)+"+(ybottom-50)+"a"+langr+""+shortr+"0 1 0"+xbottom1+""+ (ybottom1-50)+"'/>"); println( "pi以下"); "+y0+"+xbottom+""+ybottom+"a"+langr+""+shortr+"0 0"+xbottom1+""+ybottom1+"z ' />"); ; = 'M "+(xbottom)+" "+(ybottom-50)+" a "+langr+" "+shortr+" 0 "+xbottom1+"+(ybottom1-50)+"l"+xbottom1+"" +ybottom1+"+langr+" "+shortr+" 0 1 "+xbottom+" z ' /> "); 50)+"l"+(xbottom)+""+(ybottom-50)+"a"+langr+"+shortr+" 0 0 "+xbottom1+"+(ybottom1-50)+"z '/>") ; sfile.append( "/g>"); ; (radian);} //文字列に戻るpublic static double getcos(double radian){return math.cos(radian);} private static double [] getpercent(dou ble data []){double sum = 0; [] = new double [data.length]; i ++){percents [i] =(data [i]/sum)*100;} public static void createSvg(string fileererealpath、double [] percents){string sfile = initialize(percents); byte [] bytefil = sfile.getBytes( "utf-8"); fos.write(bytefil); fos.close();} catch(exception ex){ex.getMessage();}}}}3. JFreechartを使用して、SVGグラフィックを動的に生成します。
Import java.io.*; categorydataset.data.category.defaultorydataset。 */ public class barchartdemo {public static void main(string [] args)throws ioexception {categorydataset dataset = getDataSet(); 「フルーツアウトレットチャート」、//チャートタイトル「フルーツ」、//表示ラベル「収量」、//数値シャフトデータセットのディスプレイタグ、//データセットplotorientation、//チャート方向:水平、垂直伝送、//凡例を表示するかどうか(単純な列図の場合はfalseでなければなりません)// false // URLリンクが生成されるかどうか); (0,0,400,300);画像jfreechart chart = chartfactory.createbarchart3d( "Fruit Outlet"、//表示タグ「出力」、//表示ラベルデータセット、//データセットplotorientation.vertical、//チャート方向:horizont URLリンクを生成するかどうか); jpg、1、チャート、400、300、null);}最後に{try {fos_jpg.close();} catch(Exception e){}} / ** *デモンストレーション用のシンプルなデータセットオブジェクトを取得します * * @return * / private statedatasetaset(){)ydataset dataset = new defaultcategorydataset(100、 "1"、 "grape"); (200、 "Lychee"); "、" lychee "); return dataset;} / ***デモンストレーションで使用されるコンビネーションデータセットを取得 * (100、「Beijing」、「Apple」); Dataset.AddValue(100、 "Apple"); dataset.addvalue(100、 "guangzhou"、 "apple"); dataset.addvalue 、「pear」); dataset.addvalue(200、 "guangzhou"、 "pear"); dataset.addvalue( "Beijing"、 "Grape"); dataset.addvalue(300、 "shanghai"、 " grape ");dataset。AddValue(300、" guangzhou "、" grape "); dataset.addvalue(400、" banana "、" banana "); dataset.addvalue(400、" shanghai "、" banana "); "、" banana "); dataset.addvalue(500、" beijing "、" litchi "); dataset.addvalue(" shanghai "、" litchi ");} /*** exports a jfreechart svgファイルチャート、長方形の境界、svgfile)xmlドキュメントを作成します。 / SVGジェネレーターChart.Dr(SVGGENATOR)を描画します。 ;これを使用する場合、2つのポイントに注意を払う必要があります。
1。JFREECHART自体はSVGグラフィックを生成できません。Batik、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プレーヤーと呼ばれるもう1つは、視聴者が中国語をサポートしています。
上記のコンテンツは、Java生成されたCakes SVGとJFReechart生成されたSVGチャートのすべてです。