-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats_general.java
96 lines (87 loc) · 3.19 KB
/
stats_general.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.awt.Color;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.*;
import org.jfree.chart.*;
import org.jfree.chart.labels.PieSectionLabelGenerator;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.util.Rotation;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
public class stats_general extends JFrame{
int posX;
int posY;
public stats_general(String title,String title2,String[][]arr) {
initUI(title, title2,arr);
}
public void initUI(String title, String chartTitle,String[][]arr) {
setTitle("İstatistikler");
setForeground(Color.WHITE);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(null);
JPanel panel = new JPanel();
panel.setBounds(0, 0, 605, 370);
getContentPane().add(panel);
//move window
this.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e){
posX=e.getX();
posY=e.getY();
}
});
this.addMouseMotionListener(new MouseAdapter(){
public void mouseDragged(MouseEvent evt){
setLocation (evt.getXOnScreen()-posX,evt.getYOnScreen()-posY);
}
});
//move window
PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator(
"{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0.0%"));
PieDataset mezun_bolum_dataset = createDataset(arr);
JFreeChart mezun_bolum_chart = createChart(mezun_bolum_dataset, chartTitle,gen);
ChartPanel mezun_bolum_chartPanel = new ChartPanel(mezun_bolum_chart);
panel.add(mezun_bolum_chartPanel);
mezun_bolum_chartPanel.setPreferredSize(new java.awt.Dimension(600, 370));
mezun_bolum_chartPanel.addChartMouseListener(new ChartMouseListener() {
@Override
public void chartMouseClicked(ChartMouseEvent event) {
}
@Override
public void chartMouseMoved(ChartMouseEvent event) {
}
});
JButton btnGeri = new JButton("Geri");
btnGeri.setBounds(485, 375, 89, 23);
getContentPane().add(btnGeri);
btnGeri.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
dispose();
}
});
panel.setBackground(Color.white);
getContentPane().setBackground(Color.WHITE);
}
private PieDataset createDataset(String [][]arr) {
DefaultPieDataset set = new DefaultPieDataset();
for(int x=0;x<arr.length;x++) {
set.setValue(arr[x][0], Integer.parseInt(arr[x][1]));
}
return set;
}
private JFreeChart createChart(PieDataset dataset, String title,PieSectionLabelGenerator w) {
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.9f);
plot.setLabelGenerator(w);
return chart;
}
}