JFREECHART no puede generar gráficos SVG, pero puede usar otra cosa para ayudar a generar.
Uno: Java genera SVG Cake Map, que viene con una etiqueta para mostrar la parte de cada representante de color
paquete 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: space = 'default' "); sfile. append ("/ n "); sfile.append (" version = '1.1' width = '100%' height = '100%' ViewBox = '0 0 2024 570'> "); sfile.append ("/n ") ;;" <"<" <"<ffs> </defs>"); , 0,0,16.384, -9.83) 'xmlns =' http://www.w3.org/2000/svg '> "); sfile.append ("/n "); // cíclico crea una etiqueta de ruta. Ruta de cadena = creatpath (502, 300, 300, porcentajes, nombres); ); Porcentaje de porcentaje de porcentaje* @Param Names muestra el nombre del representante de color* @return*/ public stric stric creatpath (doble x0, doble y0, doble [] percents, string [] nombres) {StringBuffer sfile = new StringBuffer (); x1 = 0; Radian = 0; ) == 0) {radian = getRadian (porcentaje [0]); (x0+getCos (textradian*r); middley = (y0-getsin (textradian)*r); doble porcentaje = math.round (percents [0]*100) /100.0; y0)/(Midex-x0)); Double TextLen = 70; {Cuando un tipo es 0, la pantalla del mapa de la torta 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"); )+"'Space =' Preserve 'Font-Family =' Tahoma 'font-size =' 21 'relleno =' stroke = 'rojo' Eline- shift = 'basal'>"+porcentaje+"%</ext>") ;} Else if (textradian> (math.pi/2) && textradian <math.pi) {sfile.append ("<line x1 = '"+middlex+"' y1 = '"+middley+"' x2 = '"+ (Middlex-Math.cos (Sita)*Lino)+"'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' relleno = 'rojo' stroke = 'rojo' basal-shift = 'base'>"+porcentaje+"%</ext> ");} else if ((textradian> (math.pi) && textradian <(math.pi*3/2))) {sfile.append (" <línea 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 'relleno =' rojo 'stroke =' rojo 'shift de línea de base =' base '>" +porcentaje+"%</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' relleno = 'rojo' stroke = 'rojo 'basal-shift =' basal '> "+porcentaje+"%</ext> ");} 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 'relleno ='"+colores [0]+"'/>");} else {sfile.append ("<path d =' m"+x0+""+y0+"l "+(x0+r)+"+r+"a"+r+""+r+"+x1+" "+y1+" l "+x0+" "+y0+" z 'relleno =' "+colores [0]+" '/> ");} sfile.append ("/n "); rect x ='"+(x0+2*r)+"'y ='"+(y0-r/2.0+n)+"' Width = '60 'Height =' 30 'Fill =' "+Color [i]+" 'Stroke ='#fffffff 'Stroke-Dasharray =' 1,1 ' /> "); sfile.append (" /n " ); "+Colors [0]+" 'Stroke ='#000000 'Stroke-Dasharray =' 1,1 'basal-shift =' basal '> "+nombres [0]+" </text> "); ("/ n ");} else {textradian = radian+(getradian (porcentajes [i]) /2); // Obtenga el arco de la línea indicadora y el eje x. Radian = radian+gotradian (percents [i]); / / / / // La suma del arco frente al ventilador en forma de I (x0+getCos (textradian)*r); ]*100.100.0; ; .Append ("" <línea x1 = '"+mideex+"' y1 = '"+middley+"' x2 = '"+(middlex+math.cos (sita)*linelen)+" y2 =' "+(matemáticas .sin (Sita)*Linelen)+"'Stroke ='#000000 '/>"); (Sita)*TextLen)+"'y ='"+(Math.sin (Sita (Sita)*TextLen))+"'Space =' Preserve 'Font-Font-Font-Size =' 21 'Fill =' Red 'Stroke =' rojo 'basal-shift =' basal '> "+porcentaje+"%</ext> "); {sfile.append (" <línea x1 =' "+middlex+" 'y1 =' "+middley+" ' x2 = '"+(Middlex-Math.cos (Sita)*Linelen)+"' y2 = '"+(Middey- (Math.sin (Sita)*Linelen)+"' Stroke = '#000000'/> " ); )*textLen)+"'space =' Preserve 'Font-Family =' Tahoma 'font- size = '21' relleno = 'rojo' stroke = 'rojo' basal-shift = 'base'>"+porcentaje+"%< /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-matath.cos (sita)*textLen)+"' y = '"+(math.sin (sita)*textlen)+"' space = 'Preserve 'font -family =' tahoma 'font-size = '21' relleno = 'rojo' stroke = 'rojo' basal-shift = 'basal'> "+porcentaje+"%</text> "); radian> (matemáticas. pi*3/2) && textradian <(math.pi*2)) {sfile.append ("<línea x1 = '"+middlex+"y1 ='"+middley+"'x2 ='"+(math+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' relleno = 'rojo' stroke = 'rojo' basal-shift = 'basal'>+porcentaje+"%"% </text> "") ;} 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 'relleno =' "+colores [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 'llena = '"+color [i]+"' /");} sfile.append (" /n ");} n+= 50; sfile.append (" <rad = '"+(x0+2*r)+ "'y ='"+(y0 (y0 -r /2.0+n)+"'width = '60' height = '30 'relleno =' "+colores [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' relleno = '"+colores [0]+"' Stroke = '#000000' Stroke -DashArray = '1,1' basal-shift = 'basal'> "+nombres [i]+" </text> "); sfile.append ("/n ");}} return sfile.ToStration (); } // Devuelve el ARC public static double getradian (doble fenshu) {return (fenshu*math.pi)/50;} // Regreso al sine público estático doble getsin (doble radian) {return math.sin (radian); } // Regrese a Yu Xian public static Double GetCos (Double Radian) {return Math.cos (radian); 10}; "+Datos [3]+" 个 "," 母线: "+datos [4]+" 个 "}; crear (datos, nombres);} private estático void create (int [] data, string [] nombres) { Pruebe {CreateSVg ("d: /a.svg",getpercent (data), nombres);} capt (excepción e) {E.PrintStackTrace ();}} privado estático Doble [] getPORTENT (int data []) {double Sum = 0; ; ) Tion {String sfile = Initialize (Percents, Names); .delete ();} fileOutp utstream fos = new FileOtputStream (SVGFile); }}}2. Java genera SVG 3D Map Cake.
(Esto puede generar gráficos, pero imperfecto, ya no modificé el código, porque creo que esto no vale la pena, y Jfreechart puede ser mejor. La función es más fuerte, pero estos programas me han hecho saber el SVG más. ¿Son algunas de las etiquetas en él?) 3d.) El efecto del efecto generado tendrá un efecto de falla. Ajuste: SVGDeveloper.
paquete com.xj.svg; #9aabee ","#3E941b ","#F2E692 ","#66CC00 ","#297110 ","#D6A97b ","#82522b "," #AAAAFF ","#1111AA ","#FF222222 "," #Ffaaaa ","#aa1111 "}; public static void main (string [] args) {double data [] = {20,20,50}; try {createSVg (" f: /f.svg ", getPORTENT (datos (datos );} Catch (Exception e) {E.PrintStackTrace ();}} cadena estática Initialize (doble [] porcentaje) {doble percents [] = {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' "); 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% 'verbox =' 0 0 1024 600 '> "); Sfile. append ("/n"); (Ruta); * @param x0 origen x * @param y0 origen y * @param langr * @param shortr * @param fenshu * @return * / static string c reatepath (doble x0, doble y0, doble langr, doble shortr, doble percents [] ) {StringBuffer Sfile = New StringBuffer (); Stroke = '#000000' transform = 'matrix (1,0,0,1.638, -9.83)' xmlns = 'http://www.w3.org/2000/svg'> "); sfile.append ("/"/"/" n "); para (int i = 0; i <percents.length; i ++) {System.out.println (" i: "+i); radian = radian+getradian (porcentos [i]); // El primer ventilador en forma del primer ventilador, la suma del arco. +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 (sqValue);} else if (radian> math.pi*3/2 && radian <math.pi*2) {systemm .out.println ("if4:"+radian ); .pi {// más que el arco Pi, es decir, un porcentaje de más del 50% de Sfile.append ("<gry = '"+color [i]+"'>"); "); sfile.append (" <rath 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+" langr)+""+y0+"z ' />"); "+(X0+langr)+" "+(y0-50)+" a "+langr+"+shortr+"0 1 0"+xbottom+"+(ybottom-50)+" z '/> "); sfile. 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 "); sfile.append (" </g> "); sfile. append ("/n ");}} Else {if (radian == math.pi/2) {xbottom1 = x0; /2) {xbottom1 = x0; // 底面的 x 坐标 ybottom1 = y0+shortr; // 底面的 y 坐标} else {doble tanradian = math.abs (math.tan (radian)); *Tanradian*langr*langr; ybottom1 = y0- (tanradian*langr*shortr) /math.sqrt (sqValue); /Math.sqrt (sqValue); ; {System.out.println ("I" f4: "+radian); xbottom1 = x0+(langr*shortr) /math.sqrt (sqvalue); ybottom1 = y0+(tanradian*langr*shorrtr) /math.sqrt (sqvalue) ;}} Tradian (porcentajes [i]) >> Math.pi) {// Mayor que Pi Arc, es decir, un porcentaje de más del 50% de System.out.println ("más grande que PI"); ("<gry = '"+colores [i]+"'>"); +xbottom+""+ybottom+"+langr+" "" "+shortr+" 0 1 0 "+xbottom1+" "+ybottom1+" z ' /> "); sfile.append (" /n "); sfile.append (" <"<<ringe ruta 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 ("menos que pi"); ""+y0+"l"+xbottom+""+ybottom+"a"+langr+""+shortr+"0 0 0"+xbottom1+""+ybottom1+"z ' />"); ; = 'M "+(xbottom)+" ""+(ybottom-50)+"A"+langr+""+shortr+"0 0"+xbottom1+"+(ybottom1-50)+" l "+xbottom1+" " +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 '/>") ; ;} // Regrese al ARC public static double doble doble (doble porcentaje) {return (porcentaje*math.pi)/50;} // Regrese al sine State static double getsin (doble radian) {return math.sin (Radian);} // Regrese a la cadena publicita Double GetCos (doble radian) {return Math.cos (radian);} private static double [] getPORTENT (dou ble data []) {doble suma = 0; [] = New Double [data.length]; I ++) {percents [i] = (data [i]/sum)*100;} return Porcents;} public static void createSvg (string filerRealPath, doble [] porcentaje) {String sfile = Initialize (Percents); byte [] bytefil = sfile.getbytes ("utf-8"); fos.write (bytefil);3. Use JFreechart para generar dinámicamente gráficos SVG:
Importar java.awt.rectangle; CategyDataSet; */ Public class BarchartDemo {public static void main (string [] args) lanza ioexception {categoryDataSet dataSet = getDataSet (); "Gráfico de salida de frutas", // Título de la tabla "Fruit", // Mostrar etiqueta "rendimiento", // Las etiquetas de visualización del conjunto de datos del eje numérico, // conjunto de datos Plotorientation.vertical, // Dirección del gráfico: Horizontal, transmisión vertical , // si se debe mostrar una leyenda (para los diagramas de columna simples debe ser falso) Falso, // si se debe generar una herramienta False // si se genera el enlace de URL); (0,0,400,300); Imagen jfreeChart Chart = ChartFactory.CreateBarchart3d ("Outlet de frutas", // Las etiquetas de visualización "Salida", // Mostrar etiqueta DataSet, // Conjunto de datos Plotorientation.vertical, // Dirección del gráfico: Horizont si a generar un enlace de URL); jpg, 1, gráfico, 400, 300, nulo);} finalmente {try {fos_jpg.close ();} capt (excepción e) {}} / ** * Obtenga un objeto de conjunto de datos simple para la demostración * * @return * / private staticDataSetAset () {) {) ydataSet DataSet = new DefaultCategoryDataSet (); (200, "1", "Lychee"); "", "Lychee"); return dataSet;} / *** obtenga uno el conjunto de datos de combinación utilizado por la demostración * * * @return * / private static categoryDataSetaSetDataSet2 () {defaultCategoryDataSetaset = new DefaultCategoryDaset (); dataSet.add Valor Valor (100, "Beijing", "Apple"); , "Pera"); Uva "); dataSet. AddValue (300," Guangzhou "," uva "); DataSet.addValue (400," Beijing "," Banana "); DataSet.AddValue (400," Shanghai "," Banana "); Guangzhou "," Banana "); DataSet.AddValue (500," Beijing "," Litchi "); DataSet.addValue (500," Shanghai "," Litchi ");"); JfreeChart a un archivo SVG. Gráfico, límites del rectángulo, archivo SVGFile). / Dibuje el gráfico en el Generador SVG. ;Al usar esto, debe prestar atención a dos puntos:
1. Jfreechart en sí no puede generar gráficos SVG, debe usar Batik.
Batik-Awt-Util.Jar
Batik-Dom.Jar
batik-svggen.jar
Batik-Util.Jar
batik-xml.jar
jfreechart -.0.0.Jar
2. Es posible generar SVG. Otro llamado Renesis SVG Player, este es el espectador que apoya el chino.
El contenido anterior es todo el contenido de los pasteles generados por Java SVG y JFreechart generaron gráficos SVG.