Jfreechart selbst kann keine SVG -Grafiken generieren, aber Sie können eine andere Sache verwenden, um zu generieren.
Eins: Java erzeugt eine SVG -Kuchenkarte, die mit einem Etikett geliefert wird, um den Teil jedes Farbvertreters anzuzeigen
Paket com.tellhow.svg; "#f2e692", "#AA1111", "#799ae1", "#3E941B", "#66cc00", "#297110", "#D6A97B", "#82522B", "#aaaaff", "# 1111aa ", " #ff2222", "#ffaaaa"}; 'Utf-8'?> "); Sfile.Append ("/n "); ("/n"); = 'http://www.w3.org/1999/xlink' "); N "); <"<" <"<DEFS> </defs>"); , 0,0,16.384, -9.83) 'xmlns =' http://www.w3.org/2000/svg '> "); STRING PATH = CreatPath (502, 300, 300, Namen, Namen); ); Percent prozentuale Array* @Param -Namen Zeigen Sie den Namen des Farbvertreters an* @return*/ public stric String creatPath (Double X0, Double Y0, Double [] Wahrung, String [] Namen) {StringBuffer SFILE = new StringBuffer (); x1 = 0; ; ++) == 0) {radian = getRadian (Percents [0]); Middlex = (x0+getCos (textradian*r); Middley = (y0-Getsin (Textradian)*R); Double Prozent = Math.Round (Percent [0]*100) /100,0;. K = Math.Abs ((((((((((((((()) /100.0 /100.0 ((((((((((). MIDEY-y0)/(MIDEX-X0); 50; 0) {wenn ein Typ 0 ist, die Kuchenkarte Anzeige if (textradian <(math.pi/2))) {sfile.Append ("<Zeile x1 = '"+Middlex+"y1 ='"+Middley+"' X2 = '"+(Middlex+Math.cos (Sita)*Linelen)+"' y2 = '"+(math.sin (Sita)*Linelen))+"' stroke = '#000000'/> "); SFILE.Append ("/n"); textLen))+"'space =' Preserve 'font-family =' Tahoma 'font-size =' 21 'fill =' stroke = 'Red Eline- Shift =' Baseline '>"+Prozent+"%</text>" );} Else if (textradian> (math.pi/2) && textradian <math.pi) {sfile.Append ("<Zeile x1 = '"+Middlex+"' y1 = '"+Middley+"x2 ='" +(Middlex-math.cos (Sita)*Leinen)+"'y2 ='"+(Math.sin (Sita)*Linlen)+"'Stroke ='#000000 '/>"); "/n"); "'space =' Preserve 'font-family =' Tahoma 'Schriftgröße =' 21 'fill =' Red 'Strike =' Red 'Baseline-Shift =' Baseline '>"+Prozent+"%</text> ");} Else if (textradian> (math.pi) && textradian <(math.pi*3/2)) x2 = '"+(Middlex-math.cos (Sita)*Linelen)+"' y2 = '"+(Midgey+(Math.sin (Sita)*Linlen)+"' Stroke = '#000000'/> ") ; sfile.Append ("/n"); *textLen)+"'space =' Preserve 'Schriftart-font-font-size =' 21 'fill =' red 'stroke =' red 'basiline-schift =' baseline '>"+Prozent+"%</text>" ); an <<< (math.pi*2)) {sfile.Append ("<Zeile x1 = '"+Middlex+"y1 ='"+Middley+"'x2 ='"+(Middlex+Math .Cos (Sita)*Linelen)+"'y2 ='"+(Middley+Math.sin (Sita)*Linelen)+"Stroke = '#000000'/>"); ); 'Preserve' font-family = 'Tahoma' font-size = '21 'fill =' Red 'STROKE =' Red 'Baseline-Shift =' Baseline '> "+Prozent+"%</text> "");} Sfile .Append ("/n"); +"+r+" a "+r+" ""+r+"0 1 0"+x1+""+y1+"l"+x0+"+y0+" z 'fill =' "+farben [0]+" '/> " );} Else {sfile.append ("<path d = 'm"+x0+""+y0+"l"+(x0+r)+"+r+" a "+r+" "+r+"+x1+"" " +y1+"l"+x0+""+y0+"z 'fill ='"+farben [0]+"'/>");} sfile.append ("/n"); +2*r)+"'y ='"+(y0-r/2,0+n)+"'width = '60' height = '30' fill = '"+color [i]+"Stroke =' #FFFFFFF 'STROKE-Casharray =' 1,1 ' /> "); 25)+"'space =' Preserve 'font-familie =' font-size = '28' fill = '"+color -Shift = 'Baseline'> "+Namen [0]+" </text> "); ("/n ");} else {textradian = radian+(getRadian (Wahres [i])/2); // GET GET Der Bogen der Indikatorlinie und die x-Achse. ); ) Doppelte Linelen = 50; ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::: Math.atan (k); ) {sfile.Append ("" <Zeile x1 = '"+midex+"' y1 = '"+Middley+"' x2 = '"+(Middlex+Math.cos (Sita)*Linelen)+" y2 =' "" +(Math.sin (Sita)*Linelen)+"Stroke = '#000000'/>"); math.cos (sita)*textlen)+"'y ='"+(math.sin (sita)*textlen))+"Space = 'Preserve' Font-font-Size = '21' FILL = 'Rot' stroke = 'rot' Basislinker-Shift = 'Baseline'> "+Prozent+"%</text> "); Middley+"'x2 ='"+(Middlex-math.cos (Sita)*Linelen)+"'y2 ='"+(Middey- (Math.sin (Sita)*Linelen)+"Stroke = '#000000' /> "); sfile.Append ("/n "); sin (sita)*textlen)+"'space =' Preserve 'font-family =' tahoma 'font- size = '21' fill = 'rot' stroke = 'rot' Basislinker-Shift = 'Baseline'>"+Prozent+ "%</Text>"); 'x2 =' "+(Middlex-math.cos (Sita)*Linelen)+" 'y2 =' "+(mathdley+(math.sin (sita)*linlen)+" strong = '#000000'/> "); )+"'space =' Preserve 'font -family =' Tahoma 'Schriftgröße = '21' fill = 'Red' STROKE = 'Red' Baseline-Shift = 'Baseline'>"+Prozent+%</text> "); Radian> (math.pi*3/2) && textradian <(math.pi*2)) {sfile.append (" <Zeile x1 = '"+Middlex+"' y1 = '"+Middley+" x2 = '"+(Middlex+Math.cos (Sita)*Linelen)+"' y2 = '"+(Middley+Math.sin (Sita)*Linelen)+" Stroke ='#000000 '/> "); SFILE.Append ("" " /n"); )*textLen))+"'space =' Preserve 'font-family =' Tahoma 'font-size =' 21 'fill =' rot 'stroke =' rot 'Basislinien-Verschiebung =' Baseline '>+Prozent+"% " % </text> "");} Sfile.Append ("/n"); Wichtiger) if (getRadian (Percent [i])> math.pi) {sfile.append ("<Pfad 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 = '"+farben [i]+"'/> "" "" "" ");} else {sfile.append (" <path d = 'm "+x0+"+y0+"l"+x1+"" +y1+"+r+" "+r+" 0 0 "+(x1 = (x1 = x0+getCos (radian)*r)+"+(y1 = y0-Getsin (radian)*r)+"l"+x0+ ""+y0+"z 'fill ='"+color [i]+"' /");} Sfile.Append (" /n");} n+= 50; (x0+2*r)+"'y ='"+(y0 (y0 -r /2.0+N)+"'width = '60' Height = '30 'fill =' "+farben [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 =' zongyi 'font-size = '28' fill = '"+farben [0]+" 'stroke ='#000000 'stroke-casharray =' 1,1 ::::::::::::::::::::::::::::::::::::::::::::::3 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: > "+Namen [i]+" </text> "); Return (fenshu*math.pi)/50;} // kehre zum Sinus Public Static Double Getsin (Double Radian) zurück. radian) {return math.cos (radian); Daten [0]+"Eins", "Dispeller:"+Daten [1]+"", "Zeile:"+Daten [2]+"", "+Daten [3]+" 个 "," 母线: " +Daten [4]+"个"}; Daten), Namen);} catch (Ausnahme E) {E. printstacktrace ();}} private statische Doppel [] getSercent (int data []) {double sum = 0; Länge]; ] = (data [i]/sum)*100;} Rückgabegenehmigungen;} public static void erregtvg (String filererealPath, double [] Wahrung, String [] Namen) tion {String sFile = initialisieren (Percents, Namen); byte [] bytefil = sfile.getBytes ("utf-8"); ; fos.write (byteFil);2. Java erzeugt SVG 3D -Kuchenkarte.
(Dies kann Grafiken erzeugen, aber unvollkommen, ich habe den Code nicht mehr geändert, weil ich denke sind einige der Etiketten darin?) 3d.) Der Effekt des erzeugten Effekts hat einen Fehlereffekt. Passen Sie an: SVGDeveloper.
Paket 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 ", getSercent (Daten );} Catch (Ausnahme e) {e.printstacktrace ();}} statische String initialize (double [] Prozent) {Double Percent [] = {10,15,5,20,40, 10}; StringBuffer (); 'http://www.w3.org/2000/svg' "); "); SFILE.Append ("/n "); = 'Standard' "); sFile.Append ("/n "); append ("/n"); (Pfad); * @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 SFILE STROKE = '#000000' Transformation = 'Matrix (1,0,0,1.638, -9.83)' xmlns = 'http://www.w3.org/2000/svg'> "); SFILE.Append ("/" n "); für (int i = 0; i <Percent.length; i ++) {System.out.println (" i: "+i); radian = radian+getRadian (Percent [i]); // Der erste Lüfter -die Summe des Bogens. +Radian); 3/2) {xbottom = x0; Shortr+Tanradian*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); > Math.pi && radian <math.pi* 3/2) {System.out.println ("if3:"+radian); (Tanradian*Langr*shortr) /math.sqrt ( ); .pi {// größer als der PI -Bogen, dh ein Prozentsatz von mehr als 50% SFILE.Append ("<Gry = '" Color [i]+"'>"); "); "+ybottom+" z ' /> "); A "+Langr+" "+Shortr+" 0 1 0 "+xbottom+" "+(ybottom-50)+" l "+xbottom+"+ybottom+"a"+Langr+"+Shortr+" 0 1 1 "+(x0+ Langr)+""+y0+"z ' />"); "+(X0+langr)+" "+(y0-50)+" a "+Langr+"+Shortr+"0 1 0"+xbottom+"+(ybottom-50)+" z '/> "); append ("/n"); ]+"'>"); +Y0+"A"+Langr+""+Shortr+"0 0"+xbottom+""+ybottom+"z ' />"); X0+Langr)+""+(y0-50)+"A"+Langr+""+Shortr+"0 0 0"+xbottom+"+(ybottom-50)+" l "+xbottom+"+ybottom+"a" +Langr+""+Shortr+"0 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 "); Sonst {if (radian == math.pi/2) {xbottom1 = x0; /2) {xbottom1 = x0; // 底面的 x 坐标 ybottom1 = y0+shortr; // 底面的 y 坐标} else {double tanradian = math.abs (math.tan (radian)) ;; *Tanradian*Langr*Langr; ybottom1 = y0- (Tanradian*Langr*shortr) /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 (Percent [i]) >> Math.pi) {// größer als PI -Arc, dh ein Prozentsatz von mehr als 50% system.out.println ("größer als pi"); ("<gry = '"+farben [i]+">"); +xbottom+""+ybottom+"+Langr+" "" "+Shortr+" 0 1 0 "+xbottom1+" "+ybottom1+" z ' /> "); Pfad d = 'm "+(xbottom)+" "" "" "" "")+"A"+Langr+""+Shortr+"0 1 0"+xbottom1+"+(Ybottom1-50)+" L "+++++ xbottom1+""+ybottom1+"+Langr+" "" "" 0 1 1 "+xbottom+" "+ybottom+" z ' /> "); = 'm "+x0+" "+(y0-50)+" l "+(xbottom)+"+(ybottom-50)+"A"+Langr+""+Shortr+"0 1 0"+xbottom1+"+"+"+"+"+"+"+"+"+"+"+"+" (Ybottom1-50)+"Z '/>"); println ("weniger als pi"); "+y0+" l "+xbottom+" "+ybottom+" a "+Langr+" "+Shortr+" 0 0 "+xbottom1+" "+ybottom1+" z ' /> "); ; +ybottom1+"A"+Langr+""+Shortr+"0 0 1"+xbottom+""+ybottom+"z ' />"); 50)+"l"+(xbottom)+""+(ybottom-50)+"a"+Langr+"+Shortr+" 0 0 0 "+xbottom1+"+(ybottom1-50)+"Z '/>") ; sfile.Append ("/n"); ;} // Kehre zum Bogenpublikum statisches Doppel -Doppel -Doppel (doppelter Prozent) {Return (Prozent*math.pi)/50;} // Zurück zum Sinus State Static Double Getsin (Double Radian) {return math.sin (Radian);} // Kehre zur String Public Static Double GetCos (Double Radian) {Return Math.cos (Radian); [] = New Double [data.length]; I ++) {Percents [i] = (Daten [i]/sum)*100;} Rückgabeverdiener;} public static void createsvg (String filererealPath, double [] Wahrung) {String SFILE = Initialize (Percents); byte [] bytefil = sfile.getBytes ("utf-8"); fos.write (bytefil);3. Verwenden Sie JFreechArt, um SVG -Grafiken dynamisch zu generieren:
Java.Awt.Rectangle; CategoryDataset; */ Public class barchartdemo {public static void main (String [] args) löscht ioException {categoryDataset dataset = getDataset (); "Obst -Outlet -Diagramm", // Diagrammtitel "Frucht", // Anzeigeetikett "Ertrag", // Die Anzeige -Tags des numerischen Wellendatensatz , // ob eine Legende angezeigt wird (für einfache Spaltendiagramme muss falsch sein) falsch, //, ob ein Werkzeug falsch erzeugt wird // ob die URL -Verbindung erzeugt wird); (0,0,400.300); Bild jfreechart chart = chartfactory.createbarchart3d ("Fruchtauslass", // Die Anzeige -Tags "Ausgabe", // Beschriftungsdatensatz, // Data Set Plotorientation.vertical, // Diagrammrichtung: Horizont, ob ein URL -Link generiert werden soll); JPG, 1, Diagramm, 400, 300, null);} endlich {try {fos_jpg.close ();} catch (Ausnahme E) {}} / ** * Erhalten Sie ein einfaches Data -Set -Objekt für die Demonstration * * @return * / private staticDatasetaset () {) {) ydataset dataset = new DefaultCategoryDataset (); (200, "1", "Lychee"); "," lychee "); Datensatz zurückgeben;} / *** Erhalten Sie einen der Kombinationsdatensatz, der von der Demonstration verwendet wird (100, "Peking", "Apple"); , "Birne"); GRAPE "); Datensatz. Addvalue (300," Guangzhou "," Grape "); Dataset.addValue (400," Peking "," Banana "); Datensatz.Addvalue (400," Shanghai "," Banana "); Guangzhou); "," Banana "); dataset.addValue (500," Peking "," Litchi "); Datensatz.AddValue (500," Shanghai "," Litchi "); JFreechArt zu einer SVG -Datei. Diagramm, Rechteckgrenzen, Datei SVGFile) erstellt ein XML -Dokument Domimplementation domimpl = genericDomplementation.GetDomImplementation (); / Zeichnen Sie das Diagramm im SVG-Generator-Diagramm. ; OutputStream.close ();Wenn Sie dies verwenden, müssen Sie auf zwei Punkte achten:
1. Jfreechart selbst kann SVG -Grafiken nicht generieren, Sie müssen Batik verwenden.
Batik-awt-util.jar
batik-dom.jar
batik-svggen.jar
Batik-util.jar
Batik-xml.jar
Jfreechart -.0.0.jar
2. Es ist möglich, SVG zu erzeugen Ein anderer namens Renesis SVG Player, dieser der Betrachter unterstützt Chinese.
Der obige Inhalt ist der gesamte Inhalt von Java, die Cakes SVG und Jfreechart erzeugt haben, und ich hoffe, dass es allen gefällt.