JFREECHART lui-même ne peut pas générer des graphiques SVG, mais vous pouvez utiliser une autre chose pour aider à générer.
Un: Java génère la carte du gâteau SVG, qui est livrée avec une étiquette pour montrer la partie de chaque représentant de couleur
package com.tellhow.svg; "# f2e692", "# aa1111", "# 799ae1", "# 3e941b", "# 66cc00", "# 297110", "# d6a97b", "# 82522b", "#aaaaff", "# 1111aa" "# ff2222", "#ffaaaa"}; 'Utf-8'?> "); Sfile.append (" / n "); sfile.append (<svg xmlns: svg = 'http: //www.org/2000/svg'")); ("/ n"); = 'http://www.w3.org/1999/xlink' "); sfile.append (" / n "); sfile.append (" xml: espace = '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 "); // cyclique créer une balise de chemin. String Path = CreatPath (502, 300, 300, noms); ); Percents pourcentage du tableau * @param noms affiche le nom du représentant des couleurs * @ return * / public stric string createPath (double x0, double y0, double [] percents, string [] noms) {stringBuffer sfile = new StringBuffer (); x1 = 0; Radian = 0; // arc double textradian = 0; ) == 0) {radian = getradian (percents [0]); (x0 + getcos (textradian * r); middley = (y0-getsine (textradian) * r); double pourcent y0) / (midex-x0)); Double TextLen = 70; ot '"+ (Middx + math.cos (sita) * linelen) +"' y2 = '"+ (math.sin (sita) * linelen)) +"' stroke = '# 000000' /> "); sfile. Ajouter ("/ n"); ) + "'Space =' Preserve 'font-Family =' Tahoma 'font-size =' 21 'fill =' rAV = 'Red' eline- Shift = 'Baseline'>" + pour cent + "% </XET>") ;} Else if (textradian> (math.pi / 2) && textradian <math.pi) {sfile.append ("<line x1 = '" + middx + "' y1 = '" + middley + "' x2 = '" + (MiddleX-Math.cos (Sita) * Linen) + "'Y2 ='" + (Math.Sin (Sita) * Linlen)) + "'TRAD =' # 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' TRAD = 'Red' Baseline-Shift = 'Baseline'>" + pour cent + "% </ 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 = '"+ (middx- 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 '>" + pour cent + "% </ text>");} else if ((textradian> (math.pi * 3/2) && textradi et <(math.pi * 2))) {sfile.append ("<line x1 = ' "+ middx +" 'y1 =' "+ middley +" 'x2 =' "+ (midx + 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 = 'red 'Baseline-Shift =' Baseline '> "+ pour cent +"% </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 ='" + couleurs [0] + "'/>");} else {sfile.append ("<path d =' m" + x0 + "" + y0 + "l "+ (x0 + r) +" + r + "a" + r + "" + r + "+ x1 +" "+ y1 +" l "+ x0 +" "+ y0 +" z 'fill =' "+ couleurs [0] +" '/> ");} sfile.append (" / n "); rect x ='" + (x0 + 2 * r) + "'y ='" + (y0-r / 2.0 + n) + "' width = '60 'height =' 30 'fill =' "+ couleurs [i] +" 'tram =' # fffffff 'TRAD-dasharray =' 1,1 '/> "); sfile.append (" / n " ); "+ Colors [0] +" 'TRAD =' # 000000 'TRAD-Dasharray =' 1,1 'LASELINE-SHIFT =' BASELINE '> "+ NAMES [0] +" </XET> "); (" / n ");} else {textradian = radian + (getradian (percents [i]) / 2); // obtenir l'arc de la ligne indicatrice et l'axe x. Radian = radian + getradian (percents [i]); / // la somme de l'arc devant le fan en forme de I- (x0 + getcos (Textradian) * r); ] * 100) / 100,0; ; .APPEND ("" <line x1 = '"+ midex +"' y1 = '"+ middley +"' x2 = '"+ (midx + math.cos (sita) * linelen) +"' y2 = '"+ (mathématiques .sin (Sita) * Linelen) + "'Stroke =' # 000000 '/>"); (Sita) * textlen) + "'y ='" + (math.sin (sita (sita) * textlen)) + "'spatial =' conserver 'font-font-font-size =' 21 'fill =' rouge 'TRAD =' Red 'BaseLeline-Shift =' Baseline '> "+ pour cent +"% </ Text> "); {Sfile.APPEND (" <line x1 =' "+ middx +" 'y1 =' "+ middley +" ' x2 = '"+ (midx-math.cos (sita) * linelen) +"' y2 = '"+ (middey- (math.sin (sita) * linelen) +"' stroke = '# 000000' /> " )); ) * textlen) + "'Space =' Preserve 'font-Family =' Tahoma 'font-size = '21' fill = 'red' TRAD = 'Red' Baseline-Shift = 'Baseline'>" + pour cent + "% < / Text> "); adian <(math.pi * 3/2))) {sfile.append (" <line x1 = '"+ middlex +"' y1 = '"+ middley +"' x2 = '"+ (middlex -Math.cos (Sita) * LinElen) + "'y2 ='" + (mthdley + (math.sin (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' basline-shift = 'basline'> "+ pour cent +"% </XT> "); radian> (mathématiques. pi * 3/2) && textradian <(math.pi * 2)) {sfile.append ("<line x1 = '" + middlex + "' y1 = '" + middley + "' x2 = '" + (midx + mathy .Cos (Sita) * LinElen) + "'y2 ='" + (Middley + Math.Sin (SITA) * LINELEN) + "'TRAD =' # 000000 '/>"); n "); sfile.append (" <text x = '"+ (midx + math.cos (sita) * textlen) +"' y = '"+ (math.sin (sita) * textlen)) +"' Space = 'Preserve' font-Family = 'Tahoma' font-size = '21' fill = 'Red' TRAD = 'Red' Baseline-Shift = 'Baseline'> + pour cent + "%"% </XET> "") ;} sfile.append ("/ n"); [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 =' "+ couleurs [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 'remplissage = '"+ couleur [i] +"' / ");} sfile.append (" / n ");} n + = 50; sfile.append (" <rad = '"+ (x0 + 2 * r) + "'y ='" + (y0 (y0 -r /2.0+n)+"'width = '60' height = '30 'fill =' "+ couleurs [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 = '" + couleurs [0] + "' TRAD = '# 000000' tramage -dashArray = '1,1' LASELINE-SHIFT = 'BASELINE'> "+ NAMES [I] +" </ Text> "); sfile.append (" / n ");}} return sfile.toStration (); } // retourne l'arc public static double getradian (double fenshu) {return (fenshu * math.pi) / 50;} // return au sine public static Double getSin (double radian) {return math.sin (radian); } // retour à Yu Xian public static double getCos (double radian) {return math.cos (radian); 10};; "+ Données [3] +" 个 "," 母线: "+ data [4] +" 个 "}; create (data, noms);} private static void create (int [] data, string [] noms) { essayez {CREATESVG ("d: /a.svg",getpercent (data), noms);} catch (exception e) {e.printStackTrace ();}} Private Static Double [] Getpercent (int data []) {double Sum = 0; d ouble percents [] = new double [data.length]; ; ) Tion {String SFile = Initialise (Percents, noms); .Delete ();} fileoutp utstream fos = new FileOutputStream (svgFile); }}}2. Java génère une carte de gâteau SVG 3D.
(Cela peut générer des graphiques, mais imparfait, je n'ai plus modifié le code, car je pense que cette chose n'en vaut pas la peine, et JFreechart peut être mieux. La fonction est plus forte, mais ces programmes m'ont fait savoir davantage le SVG. Certaines étiquettes sont-elles dedans?) 3d.) L'effet de l'effet généré aura un effet de défaut. Ajuster: SVGDeveloper.
package com.xj.svg; # 9aabee "," # 3E941B "," # f2e692 "," # 66cc00 "," # 297110 "," # d6a97b "," # 82522b "," #aaaaff "," # 1111aa "," # ff22222 "," #Ffaaaa "," # aa1111 "}; public static void main (string [] args) {double data [] = {20,20,50}; try {créésvg (" f: /f.svg ", getpercent (data . StringBuffer (); 'http://www.w3.org/2000/svg' "); sfile.append (" / n "); sfile.append (" xmlns = 'http://www.w3.org/ 2000 / svg' "); sfile.append (" / n "); sfile.append (" xmlns: xlink = 'http: //www.org/1999/xlink' "); n"); = 'Default' "); sfile.append (" / n "); sfile.append (" version = '1.1' width = 'height =' 100% 'Viewbox =' 0 0 1024 600 '> "); sfile. APPENDRE (/ n "); (Chemin); * @param x0 Origin x * @param y0 Origin y * @param langr * @param shorttr * @param fenshu * @return * / static string c reatepath (double x0, double y0, double langr, double shorttr, double percents [] ) {StringBuffer SFile = New StringBuffer (); TRAD = '# 000000' transform = 'matrix (1,0,0,1.638, -9.83)' xmlns = 'http://www.w3.org / 2000 / svg'> "); sfile.append (" / n "); pour (int i = 0; i <percents.length; i ++) {System.out.println (" i: "+ i); radian = radian + getradian (percents [i]); // Le premier ventilateur -Plasse au premier ventilateur, la somme de l'arc. + Radian); if (radian == math.pi / 2) {xbottom = x0; 3/2) {xbottom = x0; Shortr + Tanradian * Tanradian * Langr * Langr; // 底面的 x 坐标 ybottom = y0- (tanradian * langr * shorttr) /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 * shorttr) /math.sqrt (sqvalue);} else if (radian> math.pi * 3/2 && radian <math.pi * 2) {systemm .out.println ("if4:" + radian )); .pi {// Plus grand que l'arc Pi, c'est-à-dire un pourcentage de plus de 50% SFILE.APPED ("<GRY = '" + Color [i] + "'>"); "); sfile.append (" <path d = 'm "+ x0 +" "+ y0 +" l "+ (x0 + langr) +" "+ y0 +" + langr + "" + shorttr + "0 1 0" + xbottom + " "+ ybottom +" z '/> "); sfile.append (" / n "); sfile.append (" <path d =' m "+ (x0 + langr) +" "+ (y0-50) +" A "+ Langr +" "+ Shorttr +" 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 +" + shorttr + "0 1 0" + xbottom + "+ (ybottom-50) +" z '/> "); sfile. APPENDRE ("/ n"); ] + "'>"); + Y0 + "A" + Langr + "" + Shorttr + "0 0" + Xbottom + "" + Ybottom + "Z '/>"); X0 + Langr) + "" + (Y0-50) + "A" + Langr + "" + Shorttr + "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 +" "" + shorttr + "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; // 底面的 x 坐标 ybottom1 = y0 + shorttr; // 底面的 y 坐标} else {double tanradian = math.abs (math.tan (radian)) ;; * Tanradian * Langr * Langr; ybottom1 = y0- (tanradian * Langr * shorttr) /math.sqrt (sqvalue); /Math.sqrt (sqvalue); orth ; {System.out.println ("i" f4: "+ radian); xbottom1 = x0 + (Langr * shorttr) /math.sqrt (sqvalue); ybottom1 = y0 + (tanradian * Langr * shorttr) /math.sqrt (sqvalue) ;}} Tradian (percents [i]) >> math.pi) {// supérieur à Pi arc, c'est-à-dire un pourcentage de plus de 50% System.out.println ("supérieur à PI"); ("<Gry = '" + Couleurs [i] + "'>"); + xbottom + "" + ybottom + "+ langr +" "" "+ shorttr +" 0 1 0 "+ xbottom1 +" "+ ybottom1 +" z '/> "); sfile.append (" / n "); sfile.append (" < Chemin D = 'M "+ (Xbottom) +" "" "" "" "" ") +" A "+ Langr +" "+ Shorttr +" 0 1 0 "+ Xbottom1 +" + (ybottom1-50) + "L" + xbottom1 + "" + ybottom1 + "+ langr +" "" "" "0 1" + xbottom + "" + ybottom + "z '/>"); = 'm "+ x0 +" "+ (y0-50) +" l "+ (xbottom) +" + (ybottom-50) + "A" + Langr + "" + Shorttr + "0 1 0" + xbottom1 + "" + (ybottom1-50) + "z '/>"); ("/ n"); println ("inférieur à pi"); g fill = '"+ couleurs [i] +"'> "); sfile.append (" / n "); sfile.append (" <path d = 'm "+ x0 + "" + y0 + "l" + xbottom + "" + ybottom + "A" + Langr + "" + Shorttr + "0 0" + xbottom1 + "" + ybottom1 + "z '/>"); ; + ybottom1 + "A" + Langr + "" + Shortr + "0 0 1" + xbottom + "" + ybottom + "z '/>"); 50) + "l" + (xbottom) + "" + (ybottom-50) + "A" + Langr + "+ Shorttr +" 0 0 0 "+ xbottom1 +" + (ybottom1-50) + "z '/>") ; ;} // Retour à l'arc public static double double (double pour cent) {return (pourcent * math.pi) / 50;} // retour à l'état sinus (Radian);} // Retour à la chaîne Public Double GetCos (Double Radian) {return Math.cos (Radian);} Private Static Double [] Getpercent (Doule Data []) {Double Sum = 0; [] = Nouveau double [data.length]; I ++) {percents [i] = (data [i] / sum) * 100;} return percents;} public static void createsvg (string filererealPath, double [] percents) {String sFile = initialize (percents); Byte [] bytefil = sfile.getBytes ("utf-8"); fos.write (bytefil);3. Utilisez JFREECHART pour générer dynamiquement les graphiques SVG:
Importation java.awt.rectangle; catégoriedataset; * / Classe publique BarchartDemo {public static void main (String [] args) lance ioException {catégoriedataset dataSet = getDataset (); "Fruit Outlet Chart", // Titre du graphique "Fruit", // Étiquette d'affichage "rendement", // Les balises d'affichage de l'ensemble de données numériques d'arbre, // Plotoritation de données.vertical, // Direction du graphique: transmission horizontale, verticale verticale , //, il faut afficher une légende (pour les diagrammes de colonnes simples doit être faux) false, // à générer un outil faux // si le lien URL est généré); (0,0,400,300); image jfreechart chart = chartfactory.createbarchart3d ("sort de fruits", // les balises d'affichage "sortie", // ensemble de données d'étiquette d'affichage, // le tracé de données de données. jpg, 1, graphique, 400, 300, null);} enfin {try {fos_jpg.close ();} catch (exception e) {}} / ** * Obtenez un objet de jeu de données simple pour la démonstration * * @return * / privé staticDataSetAt () {) {) yDataSet DataSet = new defaultCategoryDataset (); (200, "1", "Lychee"); "," lychee "); return dataSet;} / *** obtenez un un ensemble de données combinés utilisés par la démonstration * * * @return * / catégorie statique privéeDatasetAtDataSet2 () {defaultCategoryDatasetAt = new devilCategoryDaset (); dataSet.add value (100, "Beijing", "Apple"); , "Pear"); "); dataSet.addvalue (200," Guangzhou "," Pear "); DataSet.Addvalue (300," Beijing "," Grape "); DataSet.Addvalue (300," Shanghai "," Grape "); DataSet. AddValue (300," Guangzhou "," Grape "); DataSet.AddValue (400," Beijing "," Banana "); DataSet.Addvalue (400," Shanghai "," Banana "); Guangzhou "," Banana "); dataSet.addvalue (500," Beijing "," Litchi "); DataSet.Addvalue (500," Shanghai "," Litchi ");"); JFREECHART à un fichier SVG. Graphique, limites rectangulaires, fichier svgfile) lance ioEException Créer un document XML DomiMIMPlementation DOMIMPL = GenericDiceMPlementation.getDiceMplementation (); / Dessiner le graphique dans le graphique du générateur SVG.DR. ;Lorsque vous utilisez cela, vous devez faire attention à deux points:
1. JFREECHART lui-même ne peut pas générer des graphiques SVG, vous devez utiliser Batik.
Batik-awt-util.jar
batik-dom.jar
batik-svggen.jar
Batik-util.jar
batik-xml.jar
jfreechart -.0.0.jar
2. Il est possible de générer un SVG. Un autre appelé Renèse SVG Player, c'est le spectateur soutient le chinois.
Le contenu ci-dessus est tout le contenu de Cakes générés par Java SVG et des graphiques SVG générés par JFREECHART.