how to change pie chart colors of JFreeChart?

后端 未结 3 646
北恋
北恋 2021-01-18 06:30

how to customize the colors of JFreeChart graphic. lets see my java code :

private StreamedContent chartImage ;

public void init(){
    JFreeChart jfreech         


        
3条回答
  •  囚心锁ツ
    2021-01-18 07:14

    You can change the color of single pieces like this:

    JFreeChart chart = ChartFactory.createPieChart("title", createDataset(), true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("J+1", Color.black);
    plot.setSectionPaint("J-1", new Color(120, 0, 120));
    // or do this, if you are using an older version of JFreeChart:
    //plot.setSectionPaint(1, Color.black);
    //plot.setSectionPaint(3, new Color(120, 0, 120));
    

    So with your code, all the pies are colored automatically, after my code changes, the J-1 and J+1 have a fixed color, the rest gets automatically colored.

    Comparison

提交回复
热议问题