Skip to content
Snippets Groups Projects
Commit ba960b3e authored by Ludovic Apvrille's avatar Ludovic Apvrille
Browse files

Update on stats

parent 644fd6c7
No related branches found
No related tags found
No related merge requests found
......@@ -117,4 +117,6 @@ public class DataElement implements GenericTree {
} // Class
......@@ -47,6 +47,7 @@ import myutilsvg.SVGGeneration;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.statistics.HistogramDataset;
import org.jfree.data.statistics.HistogramType;
import ui.*;
......@@ -159,9 +160,17 @@ public class JFrameStatistics extends JFrame implements ActionListener, GenericT
return;
}
// Tab already exist?
String title = "Histogram of " + de.toString() + ": value";
showHistogram(de);
showPieChart(de);
}
public void showHistogram(DataElement de) {
String title = "Histogram of " + de.toString();
// Tab already exist?
if (mainPane.indexOfTab(title) > -1) {
mainPane.setSelectedIndex(mainPane.indexOfTab(title));
return;
......@@ -174,8 +183,53 @@ public class JFrameStatistics extends JFrame implements ActionListener, GenericT
JFreeChart histogram = ChartFactory.createHistogram("Histogram: " + de.toString(),
de.toString(), "Frequency", dataset);
// Adding histogram to tabbed pane
ChartPanel myChart = new ChartPanel(histogram);
// Adding histogram to tabbed pane
addChart(title, myChart);
}
@SuppressWarnings("unchecked")
public void showPieChart(DataElement de) {
String title = "PieChart of " + de.toString() ;
// Tab already exist?
if (mainPane.indexOfTab(title) > -1) {
mainPane.setSelectedIndex(mainPane.indexOfTab(title));
return;
}
DefaultPieDataset dataset = new DefaultPieDataset( );
HashMap<Double, Integer> map = new HashMap<>();
for(int i=0; i<de.data.length; i++) {
if (map.containsKey(de.data[i])) {
Integer myInt = map.get(de.data[i]);
map.put(de.data[i], new Integer(myInt.intValue()+1));
} else {
map.put(de.data[i], 0);
}
}
for(Double d: map.keySet()) {
dataset.setValue(d, map.get(d));
}
JFreeChart pieChart = ChartFactory.createPieChart(
title, // chart title
dataset, // data
true, // include legend
true,
false);
ChartPanel myChart = new ChartPanel(pieChart);
addChart(title, myChart);
}
public void addChart(String title, ChartPanel myChart) {
myChart.setMouseWheelEnabled(true);
mainPane.addTab(title, myChart);
ButtonTabComponent ctb = new ButtonTabComponent(mainPane);
......
......@@ -233,7 +233,7 @@ public class AvatarSimulationStatisticsPanel extends JPanel implements ActionLis
}
// Opening stat window
JFrameStatistics stats1 = new JFrameStatistics("Simulation stats", elts);
stats1.setSize(1200,800);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment