how to change pie chart colors of JFreeChart?

后端 未结 3 649
北恋
北恋 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:04

    You can customize the colors according to the labels while getting the data from the dataset:

    // Add custom colors
            PiePlot plot = (PiePlot) chart.getPlot();
    
            for (int i = 0; i < dataset.getItemCount(); i++) {
                if(dataset.getKey(i).equals("J+1")){ 
                    plot.setSectionPaint(i, Color.black);
                }
            }
    

    You can also use a switch-case statement or the one you prefer.

提交回复
热议问题