java - jfreechart customize piechart to show absolute values and percentages -


How is this compatible minimum code snippet example, which uses JFreeChart as FIP, value and percentage ? I could not remove this information from any code snippet on the Internet and neither from the GeFricket Manual. The code snippet only produces pie charts showing the pitch. Absolute values ​​in my case are also important, so I need to display them right under the percentage.

Here is the code: (Note that imports are lacking)

  Public class MyMinimalPieChartExample {public static zero main (string [] args ) {DefaultPieDataset Dataset = New DefaultPieDataset (); Dataset .setValue ("some data 1", 99); Dataset.set value ("some data 2", 77); // third adaption JFreeChart someChart = ChartFactory.createPieChart ("some chart header", dataset, true, true, wrong); PiePlot Invalid LegalRestPiePlot4 = (PiePlot) Some Chart.getPlot (); IllegalLegalRestPiePlot4.setSectionPaint ("some data 1", new color (0, 255, 0)); IllegalLegalRestPiePlot4.setSectionPaint ("some data 2", new color (255, 0, 0)); Piplet Plot 4 = (Piplet) Some Chats.Gate Plot (); Plot4.setExplodePercent ("some data 1", 0.4); Plot4.setSimpleLabels (true); PieSectionLabel Generator Generator = New StandardPieSectionLabelGenerator ("{0} = {2}", new decimal format ("0"), new decimal format ("0.00%"); plot4.setLabelGenerator (generator); {ChartUtilities.saveChartAsJPEG (new file (" C: /myMinimalPieChartExample.jpeg "), try some charts, 1200, 1000;} hold (exception e) {System.err.println (" could not write chart ");}}}}  < / Pre> 

Use messageFormat symbol {1} For full section value.

For details see.

pie Plot

  public Nick class MyMinimalPieChartExample {Personal Static Last String KEY1 = "Data 1"; Public Stable Last String KEY2 = "Data 2"; Public Static Zero Main (String [] Args) {DefaultPieDataset Dataset = New DefaultPieDataset (); Dataset.Set Values ​​(KEY1 , 99); dataset.set value (KEY2, 77); JFreeChart someChart = ChartFactory.createPieChart ("header", dataset, true, true, wrong); Pipelot plot = (pipelat) someChart.getPlot (); Plot.setSectionPaint (KEY1, Color.green); Plot.setSectionPaint (KEY2, Color.red); Plot.setExplodePercent (key1, 0.10); Plot.setSimpleLabels (true); PieSectionLabelGenerator gen = New StandardPieSectionLabelGenerator ("{0}: {1} ({2})", new decimal format ("0"), new decimal format ("0%")); Plot.setLabelGenerator (General); Jeff Frm = New Geoffram ("Test"); F.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); F.add (new ChatPanel (some charts) {@ Override public dimension gets accredited size) (Return new dimension (400, 300);}}); F.pack (); F.setLocationRelativeTo (zero); F.setVisible (true); }}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -