Pretty pie charts in JFreechart

我的未来我决定 提交于 2019-12-02 16:09:23

问题


Is it possible to get complex, beautiful colors for pie charts in JFreechart? I mean how can I achieve the colors like the image shown in the link?

Is it possible using the RGB format, or do you need to use a different format? How can we do it. thank you for your help


回答1:


You can specify the color using RGB values for each slice of the pie with PiePlot.setSectionPaint.

Here is an example :

  DefaultPieDataset result = new DefaultPieDataset();
  result.setValue("1", 40.);
  result.setValue("2", 30.);
  result.setValue("3", 20.);
  result.setValue("4", 10.);
  JFreeChart chart = ChartFactory.createPieChart3D("", result, true, true, false);
  PiePlot3D plot = (PiePlot3D) chart.getPlot();
  plot.setBackgroundPaint(new Color(255, 255, 255, 0));
  plot.setSectionPaint("1", new Color(31, 73, 125));
  plot.setSectionPaint("2", new Color(192, 80, 77));
  plot.setSectionPaint("3", new Color(155, 187, 89));
  plot.setSectionPaint("4", new Color(128, 100, 162));



回答2:


You can use setDrawingSupplier() to supply a custom palette, as shown here, or override lookupSectionPaint() to return any desired Paint, as shown here for getItemPaint().

You'd have to experiment with the outline stroke to approximate the highlight.



来源:https://stackoverflow.com/questions/14819336/pretty-pie-charts-in-jfreechart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!