本文整理匯總了Java中org.jfree.chart.plot.PiePlot.setIgnoreZeroValues方法的典型用法代碼示例。如果您正苦於以下問題:Java PiePlot.setIgnoreZeroValues方法的具體用法?Java PiePlot.setIgnoreZeroValues怎麽用?Java PiePlot.setIgnoreZeroValues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jfree.chart.plot.PiePlot
的用法示例。
在下文中一共展示了PiePlot.setIgnoreZeroValues方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: PieChart
import org.jfree.chart.plot.PiePlot; //導入方法依賴的package包/類
public PieChart() {
DefaultPieDataset data = getDataSet();
JFreeChart chart = ChartFactory.createPieChart3D("水果產量", data, true, false, false);
//設置百分比
PiePlot pieplot = (PiePlot) chart.getPlot();
DecimalFormat df = new DecimalFormat("0.00%");//獲得一個DecimalFormat對象,主要是設置小數問題
NumberFormat nf = NumberFormat.getNumberInstance();//獲得一個NumberFormat對象
StandardPieSectionLabelGenerator sp1 = new StandardPieSectionLabelGenerator("{0} {2}", nf, df);//獲得StandardPieSectionLabelGenerator對象
pieplot.setLabelGenerator(sp1);//設置餅圖顯示百分比
//沒有數據的時候顯示的內容
pieplot.setNoDataMessage("無數據顯示");
pieplot.setCircular(false);
pieplot.setLabelGap(0.02D);
pieplot.setIgnoreNullValues(true);//設置不顯示空值
pieplot.setIgnoreZeroValues(true);//設置不顯示負值
frame1 = new ChartPanel(chart, true);
chart.getTitle().setFont(new Font("宋體", Font.BOLD, 20));//設置標題字體
PiePlot piePlot = (PiePlot) chart.getPlot();//獲取圖表區域對象
piePlot.setLabelFont(new Font("宋體", Font.BOLD, 10));//解決亂碼
chart.getLegend().setItemFont(new Font("黑體", Font.BOLD, 10));
}
示例2: testGetLegendItems
import org.jfree.chart.plot.PiePlot; //導入方法依賴的package包/類
/**
* Some checks for the getLegendItems() method.
*/
public void testGetLegendItems() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("Item 1", 1.0);
dataset.setValue("Item 2", 2.0);
dataset.setValue("Item 3", 0.0);
dataset.setValue("Item 4", null);
PiePlot plot = new PiePlot(dataset);
plot.setIgnoreNullValues(false);
plot.setIgnoreZeroValues(false);
LegendItemCollection items = plot.getLegendItems();
assertEquals(4, items.getItemCount());
// check that null items are ignored if requested
plot.setIgnoreNullValues(true);
items = plot.getLegendItems();
assertEquals(3, items.getItemCount());
// check that zero items are ignored if requested
plot.setIgnoreZeroValues(true);
items = plot.getLegendItems();
assertEquals(2, items.getItemCount());
// check that negative items are always ignored
dataset.setValue("Item 5", -1.0);
items = plot.getLegendItems();
assertEquals(2, items.getItemCount());
}
示例3: getMultiplePieChart
import org.jfree.chart.plot.PiePlot; //導入方法依賴的package包/類
private JFreeChart getMultiplePieChart( BaseChart chart, CategoryDataset[] dataSets )
{
JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart( chart.getName(), dataSets[0], TableOrder.BY_ROW,
!chart.isHideLegend(), false, false );
setBasicConfig( multiplePieChart, chart );
if ( multiplePieChart.getLegend() != null )
{
multiplePieChart.getLegend().setItemFont( SUB_TITLE_FONT );
}
MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
JFreeChart pieChart = multiplePiePlot.getPieChart();
pieChart.setBackgroundPaint( COLOR_TRANSPARENT );
pieChart.getTitle().setFont( SUB_TITLE_FONT );
PiePlot piePlot = (PiePlot) pieChart.getPlot();
piePlot.setBackgroundPaint( COLOR_TRANSPARENT );
piePlot.setOutlinePaint( COLOR_TRANSPARENT );
piePlot.setLabelFont( LABEL_FONT );
piePlot.setLabelGenerator( new StandardPieSectionLabelGenerator( "{2}" ) );
piePlot.setSimpleLabels( true );
piePlot.setIgnoreZeroValues( true );
piePlot.setIgnoreNullValues( true );
piePlot.setShadowXOffset( 0d );
piePlot.setShadowYOffset( 0d );
for ( int i = 0; i < dataSets[0].getColumnCount(); i++ )
{
piePlot.setSectionPaint( dataSets[0].getColumnKey( i ), COLORS[(i % COLORS.length)] );
}
return multiplePieChart;
}
示例4: testGetLegendItems
import org.jfree.chart.plot.PiePlot; //導入方法依賴的package包/類
/**
* Some checks for the getLegendItems() method.
*/
public void testGetLegendItems() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("Item 1", 1.0);
dataset.setValue("Item 2", 2.0);
dataset.setValue("Item 3", 0.0);
dataset.setValue("Item 4", null);
PiePlot plot = new PiePlot(dataset);
plot.setIgnoreNullValues(false);
plot.setIgnoreZeroValues(false);
LegendItemCollection items = plot.getLegendItems();
assertEquals(4, items.getItemCount());
// check that null items are ignored if requested
plot.setIgnoreNullValues(true);
items = plot.getLegendItems();
assertEquals(3, items.getItemCount());
// check that zero items are ignored if requested
plot.setIgnoreZeroValues(true);
items = plot.getLegendItems();
assertEquals(2, items.getItemCount());
// check that negative items are always ignored
dataset.setValue("Item 5", -1.0);
items = plot.getLegendItems();
assertEquals(2, items.getItemCount());
}
示例5: renderChartToFile
import org.jfree.chart.plot.PiePlot; //導入方法依賴的package包/類
private Image renderChartToFile(TotalPaymentSummaryReportResponse response, File chartFile) throws IOException,
BadElementException, MalformedURLException {
// For generating pie chart for total payments(example for total deposits) perform following:
// Create the dataset
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("Pre 10/82 Deposit", response.getTotalDepositsPre1082());
dataset.setValue("Pre 10/82 Redeposit", response.getTotalRedepositsPre1082());
dataset.setValue("CSRS: Post 9/82 Deposit", response.getCsrsDepositsPost982());
dataset.setValue("FERS Postal", response.getFersPostalDepositsPost982());
dataset.setValue("FERS Non Postal", response.getFersNonPostalDepositsPost982());
dataset.setValue("Post 9/82 Deposit", response.getTotalDepositsPost982());
dataset.setValue("Post 9/82 Redeposit", response.getTotalRedepositsPost982());
// Set following data
// Create the chart
JFreeChart chart = ChartFactory.createPieChart("Total Payments", dataset, true, true, false);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setLabelFont(new Font("Helvetica", 0, 10));
plot.setBackgroundPaint(Color.white);
plot.setIgnoreZeroValues(false);
plot.setOutlineVisible(false);
chart.getTitle().setFont(new Font("Helvetica", 1, 14));
LegendTitle legend = chart.getLegend();
legend.setItemFont(new Font("Helvetica", 0, 10));
legend.setPosition(RectangleEdge.RIGHT);
ChartUtilities.saveChartAsPNG(chartFile, chart, chartWidth, chartHeight);
Image image = Image.getInstance(chartFile.getAbsolutePath());
return image;
}
開發者ID:NASA-Tournament-Lab,項目名稱:CoECI-OPM-Service-Credit-Redeposit-Deposit-Application,代碼行數:35,代碼來源:TotalPaymentSummaryReportService.java
示例6: init
import org.jfree.chart.plot.PiePlot; //導入方法依賴的package包/類
/**
* 創建餅狀圖的步驟如下: 1、創建一個餅狀的實例,注意傳參的格式,還有需要注意的是此時的數據集應該是defaultPieDataset,
* 而不是CategoryDataset格式 2、獲得餅狀圖的所在區域 3、設置兩個格式化的數據格式,為後麵的床架餅狀圖的實例做基礎
* 4、細節方麵是對無數據、零值、負值等情況的處理 5、最後就是設置在出現漢字的地方進行字體內容的設置了(同樣的,這是為了防止出現亂碼的狀況)
*/
public void init() {
DefaultPieDataset dataset = getDataset();
JFreeChart chart = ChartFactory.createPieChart3D("The proportion of the book", dataset, true, false, false);
PiePlot piePlot = (PiePlot) chart.getPlot();
DecimalFormat df = new DecimalFormat("0.00%");
NumberFormat nf = NumberFormat.getInstance();
// 獲得StandardPieSectionLabelGenerator對象,生成的格式,{0}表示section名,
StandardPieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{0} {2}",
// {1}表示section的值,{2}表示百分比。可以自定義
nf, df);
piePlot.setLabelGenerator(generator);// 設置百分比
piePlot.setLabelFont(new Font("黑體", Font.ITALIC, 20));
// 當餅狀圖內沒有有數據時,作如下數據中設置
piePlot.setNoDataMessage("此時並沒有任何數據可用");
piePlot.setCircular(false);
piePlot.setLabelGap(0.02D);
piePlot.setIgnoreNullValues(true);// 設置不顯示空位
piePlot.setIgnoreZeroValues(true);// 設置不顯示負值或零值
panel = new ChartPanel(chart, true);
chart.getTitle().setFont(new Font("微軟雅黑", Font.PLAIN, 25));
chart.getLegend().setItemFont(new Font("微軟雅黑", Font.PLAIN, 16));
File dir = new File("images\\");
if (!dir.exists()) {
dir.mkdir();
}
String fName = String.valueOf(System.currentTimeMillis()) + "pie.png";
File file = new File("images\\", fName);
try {
ChartUtilities.saveChartAsPNG(file, chart, 550, 400);
} catch (IOException e) {
e.printStackTrace();
}
}