[英]Partition pie chart into equal parts jfreechart
I have a data source in which there are three departments and each department has equal employees that are 8. I want to make a pie chart using jFreeChart such that first we partition the pie into 3 equal parts for departments that is 120' for each department. 我有一个数据源,其中有三个部门,每个部门有8个相等的雇员。我想使用jFreeChart制作饼图,这样我们首先将饼分为3个相等的部分,每个部门120' 。 Then in these partitions I want to show the sales of each employee.
然后在这些分区中,我要显示每个员工的销售额。 How can I do this in jFreeChart.
我如何在jFreeChart中做到这一点。
PieChartDemo1
is a good starting point; PieChartDemo1
是一个很好的起点; focus on createDataset()
; 专注于
createDataset()
; the full source is included in the distribution. 完整的源包含在分发中。
Addendum: How to further create partitions? 附录: 如何进一步创建分区?
Ah, you want to sub-divide each 120° partition. 嗯,您想细分每个120°分区。
DefaultPieDataset
doesn't support a hierarchical structure directly, but you can use color in the PiePlot
to highlight the grouping. DefaultPieDataset
不直接支持层次结构,但是您可以在PiePlot
使用颜色突出显示分组。 Create related colors using Color.getHSBColor()
, as shown here , and use setSectionPaint()
to apply the colors accordingly. 创建使用相关的颜色
Color.getHSBColor()
如图所示这里 ,并使用setSectionPaint()
据此适用的颜色。
public class PieChart extends JFrame {
private PieDataset createDataset() {
DefaultPieDataset result = new DefaultPieDataset();
result.setValue("department1", 33.33);
result.setValue("department2", 33.33);
result.setValue("department3", 33.33);
return result;
}
private JFreeChart createChart(PieDataset dataset, String title) {
JFreeChart chart = ChartFactory.createPieChart3D(title, // chart title
dataset, // data
true, // include legend
true,
false);
PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setStartAngle(290);
plot.setDirection(Rotation.CLOCKWISE);
plot.setForegroundAlpha(0.5f);
return chart;
}
}
public static void main(String[] args) {
PieChart demo = new PieChart("Comparison", "Which operating system are you using?");
demo.pack();
demo.setVisible(true);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.