|
<% @ Page contentType = "text/html; charset = GBK" %>
<% @ Page
Import = "org. jfree. chart. *, org. jfree. chart. plot. PiePlot,
Org. jfree. data. general. DefaultPieDataset,
Org. jfree. chart. servlet. ServletUtilities,
Java. awt. *, org. jfree. chart. title. TextTitle "%>
<% @ Page
Import = "org. jfree. chart. labels. StandardPieSectionLabelGenerator" %>
<% @ Page import = "java. text. NumberFormat" %>
<% @ Page import = "java. text. DecimalFormat" %>
<%
// Set the dataset
DefaultPieDataset dataset = new DefaultPieDataset ();
Dataset. setValue ("junior high school senior programmer", 0.52 );
Dataset. setValue ("project manager", 0.1 );
Dataset. setValue ("system Analytics", 0.1 );
Dataset. setValue ("software architect", 0.1 );
Dataset. setValue ("other", 0.18 );
// Generate a JFreeChart object through the factory class
JFreeChart chart = ChartFactory. createPieChart3D ("IT industry career distribution chart ",
Dataset, true, false, false );
PiePlot pieplot = (PiePlot) chart. getPlot ();
// A highlighted pie chart has not been found on the Internet for a long time. Thank you for your guidance. <? What if I find a solution later?>
// Pieplot. setExplodePercent ("A", 0.3D); // The fried pie chart has some problems.
// DecimalFormat:
// NumberFormat:
// StandardPieSectionLabelGenerator:
// SetLabelGenerator ():
DecimalFormat df = new DecimalFormat ("0.00%"); // Obtain a DecimalFormat object, mainly for decimal setting
NumberFormat nf = NumberFormat. getNumberInstance (); // Obtain a NumberFormat object
StandardPieSectionLabelGenerator sp = new StandardPieSectionLabelGenerator (
"{0} {2}", nf, df); // Obtain the StandardPieSectionLabelGenerator object
Pieplot. setLabelGenerator (sp); // you can specify the percentage of a pie chart.
// Content displayed when no data exists
Pieplot. setNoDataMessage ("no data display ");
Pieplot. setCircular (false );
Pieplot. setLabelGap (0.02D );
Pieplot. setIgnoreNullValues (true); // The setting does not display null values.
Pieplot. setIgnoreZeroValues (true); // set not to display negative values
// Title text garbled IT industry career distribution chart
TextTitle textTitle = chart. getTitle ();
TextTitle. setFont (new Font ("", Font. PLAIN, 20 ));
// Garbled text on the pie
PiePlot plot = (PiePlot) chart. getPlot ();
Plot. setLabelFont (new Font ("", Font. PLAIN, 12 ));
// Five descriptions of the legend text garbled pie chart
Chart. getLegend (). setItemFont (new Font ("", Font. PLAIN, 12 ));
String filename = ServletUtilities. saveChartAsPNG (Charts, 500,300,
Null, session );
String graphURL = request. getContextPath ()
+ "/DisplayChart? Filename = "+ filename;
%>
<Html>
<Head>
<Title> Pie Chart 2 (add a percentage and highlight a block) </title>
</Head>
<Body>
" width = 500 height = 300 border = 0
Usemap = "# <% = filename %>">
</Body>
</Html> |