-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPieModel.java
62 lines (52 loc) · 1.75 KB
/
PieModel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package beta;
import java.awt.Color;
import java.awt.Font;
import java.text.NumberFormat;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
public class PieModel {
String _level;
private int _fails;
private int _correct;
public PieModel(int correct, int fails, String level) {
_level = level;
_fails = fails;
_correct = correct;
}
protected JPanel getPieChart() {
JFreeChart chart = PieChart(pieData());
return new ChartPanel(chart);
}
private PieDataset pieData(){
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("Correct", new Double(_correct));
dataset.setValue("Incorrect", new Double(_fails));
return dataset;
}
private JFreeChart PieChart(PieDataset dataset){
//Creates the pie chart and sets its axis and colours
JFreeChart pieChart = ChartFactory.createPieChart(
"Accuracy for " + _level,
dataset,
true,
true,
false);
pieChart.getTitle().setFont(new Font("SansSerif", Font.ITALIC, 20));
pieChart.getTitle().setPaint(new Color(51, 47, 47));
pieChart.setBackgroundPaint(new Color(255,255,152));
PiePlot plot = (PiePlot) pieChart.getPlot();
plot.setBackgroundPaint(new Color(255,255,152));
plot.setSectionPaint("Correct", new Color(83, 104, 120, 255));
plot.setSectionPaint("Incorrect",new Color(255, 84, 83, 255));
plot.setLabelGenerator(new StandardPieSectionLabelGenerator(
"{0}: {1} ({2})", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()
));
return pieChart;
}
}