简体   繁体   中英

Why setBaseSectionPaint doesn't work?

I have a pie chart. I need fill all section same color. In jfreechart guide, i found method setBaseSectionPaint , but it's didn't work. I used method setSectionPaint in cycle, but it's not right(excess program code). Why setBaseSectionPaint doesn't work?

private  JFreeChart createPieChart(PieDataset piedataset){
    JFreeChart jfreechart = ChartFactory.createPieChart("Select the desired dictionary:", piedataset,true, true, false);

    PiePlot pieplot = (PiePlot) jfreechart.getPlot();


    for (int i=0;i<piedataset.getItemCount();i++){  //excess program code
        pieplot.setSectionPaint(piedataset.getKey(i),new Color(54, 95, 196));
    }

    pieplot.setBaseSectionPaint(new Color(54, 95, 196)); //doesn't work
    return jfreechart;
}

The PiePlot method drawItem() , among others, invokes lookupSectionPaint() , which explains the algorithm used:

  • if getSectionPaint() is non-null, return it;
  • if getSectionPaint(int) is non-null return it;
  • if getSectionPaint(int) is null but autoPopulate is true , attempt to fetch a new paint from the drawing supplier ( Plot.getDrawingSupplier() );
  • if all else fails, return getBaseSectionPaint() .

Instead, try this approach, illustrated using org.jfree.chart.demo.PieChartDemo1 after omitting calls to setSectionPaint() :

//plot.setSectionPaint(…);
plot.setAutoPopulateSectionPaint(false);
plot.setBaseSectionPaint(Color.blue);

图片

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM