O próprio Jfreechart não pode gerar gráficos SVG, mas você pode usar outra coisa para ajudar a gerar.
Um: Java gera mapa de bolos SVG, que vem com uma etiqueta para mostrar a parte de cada representante de cores
pacote com.tellow.svg; "#f2e692", "#aa1111", "#799e1", "#3E941b", "#66CC00", "#297110", "#d6a97b", "#82522b", "#aaafaf", "#1111A", " #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 (" versão = '1.1' largura = '100%' altura = '100%' viewBox = '0 0 2024 570'> "); sfile.append ("/n ") ;;" <"<" <"<Defs> </ffs>"); , 0,0,16.384, -9.83) 'xmlns =' http://www.w3.org/2000/svg '> "); sfile.append ("/n "); // cyclic Crie uma etiqueta de caminho. Caminho da String = CreatPath (502, 300, 300, porcentões, nomes); ); PEDOR DE PERCENTES ARRAY* @param Nomes exibem o nome do representante de cores* @return*/ public stric string cretpath (duplo x0, duplo y0, duplo [] porcents, string [] nomes) {stringbuffer sfile = new stringbuffer (); x1 = 0; Radian duplo = 0; ++) == 0) {Radian = getRadian (porcentões [0]); Middlex = (x0+getCos (textradian*r); Middley = (y0-getsin (textradian)*r); dupla por cento = math.ound (porcents [0]*100) /100.0;. midey-y0)/(midex-x0)); 50; 0) {Quando um tipo é 0, a exibição do mapa do bolo se (textradian <(math.pi/2))) {sfile.append ("<linha 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 'preenchimento =' stroke = 'vermelho eline- shift =' linha de base '>"+por cento+"%</sext>" );} Else if (textradian> (math.pi/2) && textradian <Math.pi) {sfile.append ("<linha x1 = '"+middlex+"' y1 = '"+Middley+"' x2 = '" " +(Middlex-Math.cos (sita)*linho)+"'y2 ='"+(Math.sin (sita)*Linlen))+"'Stroke ='#000000 '/>"); "/n"); "'Space =' preserve 'font-family =' Tahoma 'font-size =' 21 'preench =' vermelho 'greve =' vermelho 'shift da linha de base =' linha de base '>"+por cento+"%</xt> ");} Else if (textradian> (math.pi) && textradian <(math.pi*3/2)) sfile.append (" <linha x1 = '"+middlex+"' y1 = '"+Middley+"' x2 = '"+(Middlex-Math.cos (sita)*linelen)+"' y2 = '"+(Midgey+(Math.sin (sita)*Linlen)+"' Stroke = '#000000'/> ") ; *textlen)+"'space =' preserve 'fonte-font-font-size =' 21 'preenchimento =' vermelho 'stroke =' vermelho 'shift da linha de base =' linha de base '>"+por cento+"%</sext>" ); .COS (SITA)*Linelen)+"'y2 ='"+(Middley+Math.sin (sita)*linelen)+"'Stroke ='#000000 '/>"); ); 'Preservar' font-family = 'tahoma' font-size = '21 'preench =' vermelho 'stroke =' vermelho 'shift da linha de base =' linha de base '> "+por cento+"%</sext> "");} sfile .Append ("/n"); +"+r+" a "+r+" "+r+" 0 1 0 "+x1+" "+y1+" l "+x0+"+y0+"z 'preencht ='"+cores [0]+"'/>" );} Else {sfile.append ("<caminho d = 'm"+x0+""+y0+"l"+(x0+r)+"+r+" a "+r+" "+r+"+x1+"" " +y1+"l"+x0+""+y0+"z 'preenchimento ='"+cores [0]+"'/>");} sfile.append ("/n"); +2*r)+"'y ='"+(y0-r/2.0+n)+"'width = '60' altura = '30' preenchimento = '"+cor [i]+"' stroke = ' #Fffffff 'stroke-destray =' 1,1 ' /> "); sfile.append (" /n "); 2*r+80)+"' y = '"+(y0-r /2.0+n+ 25)+"'space =' preserve 'font-family =' font-size = '28' preencht = '"+cores [0]+"' stroke = '#000000' stroke-destray = '1,1' de linha de base -Shift = 'Baseline'> "+nomes [0]+" </text> "); ("/n ");} else {textradian = radian+(getradian (porcents [i])/2); // Get o arco da linha indicadora e o eixo x. ); Lineleiro duplo = 50; Quando um tipo é 0, a exibição do mapa do bolo se (textradian <(math.pi/2))) {sfile.append ("" <linha x1 = '"+midex+"' y1 = '"+Middley+"' x2 = '"+(Middlex+Math.cos (sita)*linelen)+"' y2 = '"+(Math.sin (sita)*linelen)+"' Stroke = '#000000'/>); ("/n"); )))+"'space =' preserve 'fontes-font-size =' 21 'preencher =' vermelho 'acaricia =' vermelho 'shift da linha de base =' linha de base '>"+por cento+"%</sext>") ; (Middey- (Math.sin (SITA)*Linelen)+"'Stroke ='#000000 '/>"); Middlex-Math.cos (sita)*textlen)+"'y ='"+(math.sin (sita)*textlen)+"'space =' preserve 'font-family =' tahoma 'font- size = '21 'Preenchimento =' vermelho 'stroke =' vermelho 'shift da linha de base =' linha de base '> "+por cento+"%</sext> "); adian <(math.pi*3/2))))))) { sfile.append ("<linha x1 = '"+middlex+"' y1 = '"+Middley+"' x2 = '"+(Middlex-math.cos (sita)*linelen)+"' y2 = '"+(Mthdley+ (Math.sin (SITA)*Linlen))+"Strong = '#000000'/>"); sita)*textlen)+"'y ='"+(math.sin (sita)*textlen)+"'space =' preserve 'font -Family =' tahoma 'font -size = '21' preench = 'vermelho' Stroke = 'Red' Baseline-Shift = 'Baseline'> "+por cento+"%</sext> "); radian> (Math.pi*3/2) && textradian <(math.pi*2)) {sfile. Anexe ("<linha x1 = '"+Middlex+"' y1 = '"+Middley+"' x2 = '"+(Middlex+Math.cos (sita)*linelen)+"' y2 = '"+(Middley+Math+Math+ .sin (SITA)*linelen)+"Stroke = '#000000' />"); .Cos (sita)*textlen)+"'y ='"+(math.sin (sita)*textlen))+"'space =' preservam 'font-family =' tahoma 'font-size =' 21 'preenchimento = 'RED' ASCENDO = 'RED' SHIFT = 'linha de base'>+porcentagem+"%"% </sext> "");} sfile.append ("/n"); com uma pintura é maior que 180 e 0 significa que o arco com menos de 180 (este lugar é mais importante) se (getradian (porcents [i])> math.pi) {sfile.append ("<caminho 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 'preencht ='"+colors [i]+"'/>" "" "" "" ");} else {sfile.append ("<caminho 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 'preencht =' "+cor [i]+" ' /");} sfile.append ( " /n");} n+= 50; 'largura =' 60 'altura = '30' preenchimento = '"+cores [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-família = '宋体' font-size = '28 'preencher =' "+cores [0]+" 'Stroke ='#000000 'stroke-destray =' 1,1 'shift de linha de base =' linha de base '> "+nomes [ i]+"</sext>"); .pi)/50;} // retorna ao duplo estático público em seno Getsin (Double Radian) {return Math.sin (Radian);} // Volte para Yu Xian Public Static Double Getcos (Double Radian) {retornar matemática .Cos (Radian); "One", "Disceler:"+Data [1]+"", "Linha:"+dados [2]+"", "+dados [3]+" 个 "," 母线: "+dados [4] +"个"}; ;} Catch (Exceção e) {E.PrintStackTrace ();}} dupla estática privada [] getPercent (int data []) {Double Sum = 0; int i = 0; i]/sum)*100;} retorna porcentões;} public static void CreateSvg (string filererealPath, Double [] porcentões, nomes de string []) SFILE.GETBYTES ("UTF-8"); bytefil);2. Java gera mapa de bolo SVG 3D.
(Isso pode gerar gráficos, mas imperfeitos, não modifiquei mais o código, porque acho que isso não vale a pena, e Jfreechart pode ser melhor. A função é mais forte, mas esses programas me fizeram conhecer o SVG mais. O que Alguns dos rótulos estão?) 3D.) O efeito do efeito gerado terá um efeito de falha. Ajuste: SVGDeveloper.
pacote 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 {CreateSvg (" f: /f.svg ", getPercent (dados );} Catch (Exceção e) {E.PrintStackTrace ();}} String estática Initialize (Double [] porcentagem) {Double Percents [] = {10,15,5,20,40, 10}; StringBuffer (); 'http://www.w3.org/2000/svg' "); sfile.append ("/n "); sfile.append (" xmlns = 'http://www.w.org/ 2000/svg' "); sfile.append ("/n "); sfile.append (" xmlns: xlink = 'http: //www.org/1999/xlink' "); n"); = 'padrão' "); sfile.append ("/n "); sfile.append (" versão = '1.1' width = 'altura =' 100% 'viewBox =' 0 0 1024 600 '> "); sfile. Appender ("/n"); (Caminho); * @param x0 origem x * @param y0 origem y * @param langR * @param shortr * @param fenshu * @return * / string estática c reeatepath (x0 duplo, y0 duplo, langr duplo, xortr duplo, percentes duplas [] ) {stringbuffer sfile = novo stringbuffer (); AVC = '#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 (porcents [i]); // O primeiro ventilador -como o primeiro fã, a soma do arco. +Radian); 3/2) {xbottom = x0; Shortr+tanradiano*tanradiano*LANGR*LANGR; // 底面的 x 坐标 ybottom = y0- (tanradiano*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 {// maior que o arco PI, ou seja, uma porcentagem de mais de 50% sfile.append ("<gry = '"+cor [i]+"'>"); "); sfile.append (" <caminho d = 'm "+x0+" "+y0+" l "+(x0+langr)+" ""+y0+"+langR+" "+shortr+" 0 1 0 "+xbottom+" "+ybottom+" z ' /> "); sfile.append (" /n "); sfile.append (" <caminho d =' m "+(x0+langr)+" "+(y0-50)+" A "+LANGR+" "+shortr+" 0 1 0 "+xbottom+" "+(ybottom-50)+" l "+xbottom+"+ybottom+"a"+langR+""+shortr+"0 1"+(x0++(x0+ LANGR)+"" Y0+"Z ' />"); "+(X0+langr)+" "+(y0-50)+" a "+lanngr+"+shortr+"0 1 0"+xbottom+"+(ybottom-50)+" z '/> "); sfile. Appender ("/n"); ]+"'>"); +Y0+"A"+LANGR+"" SHORTR+"0 0 0"+xbottom+""+ybottom+"z ' />"); X0+langr)+""+(y0-50)+"a"+langr+"" "+shortr+" 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"+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 {Double tanradian = Math.abs (Math.tan (Radian)) ;; Shortr*Shortr+Tanradian *Tanradiano*Langr*Langr; ybottom1 = y0- (tanradiano*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*shortr) /math.Sqrt (sqvalue) ;}} TRADIAN (Percents [i]) >> MATH.PI) {// Maior que o Pi Arc, ou seja, uma porcentagem de mais de 50% de sistema.out.println ("maior que Pi"); ("<gry = '"+cores [i]+"'>"); +xbottom+""+ybottom+"+lanngr+" "" "+shortr+" 0 1 0 "+xbottom1+" ""+ybottom1+"z ' />"); sfile.append (" /n"); sfile.append ("< Caminho 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" 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 ' />"); ; +ybottom1+"a"+lanngr+""+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"); ;} // retorna ao duplo duplo estático duplo estático (por cento) {return (porcentagem*math.pi)/50;} // retorna ao duplo estático do estado seno (Radian);} // Retorne à String public static duplo getCos (duplo radian) {retorna math.cos (radian);} private estático duplo [] getPercent (dados duplos []) {soma dupla = 0; [] = Novo duplo [data.length]; I ++) {Percents [i] = (Data [i]/SUM)*100;} Retornar porcentões;} public static void CreateSvg (String filereRealPath, Double [] Percents) {String Sfile = Initialize (Percents); byte [] bytefil = sfile.getbytes ("utf-8"); Fos.Write (BYTEFIL);3. Use Jfreechart para gerar dinamicamente os gráficos SVG:
Importar java.awt.rectânge; categorydataSet; */ Public class BarchartDemo {public static void main (string [] args) lança ioexception {categorydataSet DataSet = getDataSet (); "Gráfico de saída de frutas", // título do gráfico "fruta", // rótulo de exibição "rendimento", // as tags de exibição do conjunto de dados de eixo numérico, // conjunto de dados plotorientation.vertical, // direção do gráfico: transmissão horizontal e vertical , // se você deve exibir uma legenda (para diagramas de coluna simples, deve ser falsa), // se deve gerar uma ferramenta falsa // se o link URL é gerado); (0,0,400,300); Image jfreechart Chart = ChartFactory.CreateBarCart3D ("Fruit Outlet", // As tags de exibição "Output", // Display DataSeet, // Data Set Plotorientation.vertical, // Direção do gráfico: Horizont se deve gerar um link URL); jpg, 1, gráfico, 400, 300, null);} finalmente {try {fos_jpg.close ();} catch (Exceção e) {}} / ** * Obtenha um objeto de conjunto de dados simples para demonstração * * @return * / private staticdatasetaset () {) {) ydataset DataSet = novo DefaultCategoryDataset (); (200, "1", "Lychee"); "," Lychee "); retorna o conjunto de dados;} / *** Obtenha um conjunto de dados de combinação usado pela demonstração * * * @return * / categoria estática privadaDataSetasetDataset2 () {defaultCategoryDatasetaset = new DefaultCategoryDaset (); DataSet.ad Value (100, "Pequim", "Apple"); , "Pear"); Grape "); DataSet. AddValue (300," Guangzhou "," Grape "); DataSet.addvalue (400," Pequim "," Banana "); DataSet.addvalue (400," Shanghai "," Banana "); "," Banana "); DataSet.addValue (500," Pequim "," Litchi "); DataSet.addvalue (500," Shanghai "," Litchi ");"); JFrechart para um arquivo SVG. Gráfico, limites de retângulo, arquivo svgfile) lança ioeexception Crie um documento XML Domimimplementation Domimpl = GenericDomimMplementation.GetDomimMplementation (); / Desenhe o gráfico SVG. ;Ao usar isso, você precisa prestar atenção a dois pontos:
1. O próprio Jfreechart não pode gerar gráficos SVG, você precisa usar o BATIK.
Batik-awt-util.jar
batik-dom.jar
batik-svggen.jar
Batik-util.jar
batik-xml.jar
jfreechart -.0.0.jar
2. É possível gerar SVG Outro chamado Reneseis SVG Player, este o espectador suporta chinês.
O conteúdo acima é todo o conteúdo de bolos gerados por Java SVG e JFRECHART gerados por gráficos SVG.