Skip to content
Snippets Groups Projects

Rama5

Merged
ginquinrequested to merge
rama5 into master
7 files
+ 216
658
Compare changes
  • Side-by-side
  • Inline

Files

@@ -5,7 +5,6 @@ import java.util.List;
import java.util.Map;
import org.carewebframework.ui.highcharts.Axis;
import org.carewebframework.ui.highcharts.AxisLabelOptions;
import org.carewebframework.ui.highcharts.Chart;
import org.carewebframework.ui.highcharts.DataPoint;
import org.carewebframework.ui.highcharts.Series;
@@ -19,6 +18,7 @@ import org.zkoss.zkplus.spring.DelegatingVariableResolver;
import es.uva.inf.tfg.ginquin.smellswisdom.domain.TypeOfApproach;
import es.uva.inf.tfg.ginquin.smellswisdom.services.ApproachService;
import es.uva.inf.tfg.ginquin.smellswisdom.utility.Utilities;
@VariableResolver(DelegatingVariableResolver.class)
public class StatisticsApproachesController extends SelectorComposer<Component> {
@@ -45,28 +45,29 @@ public class StatisticsApproachesController extends SelectorComposer<Component>
super.doAfterCompose(comp);
String title="";
String cYAxes="";
//gráfico burbujas
Map<Integer,Map<String,Integer>> datos0= approachService.getStatiticsApproaches();
title = Labels.getLabel("statisticsApproaches.title0");
createBubbleChart("asdasdas", "", chart0, datos0);
createBubbleChart(title, "", chart0, datos0);
Map<String,Integer> datos =null;
//gráfico circular
datos=approachService.getStatiticsDegreeOfAutomation();
title= Labels.getLabel("statisticsApproaches.title1");
createPieChart(title, chart1, datos);
Utilities.createPieChart(title, chart1, datos);
//gráfico lineas y barras
datos=approachService.getStatiticsRelatedActivity();
title= Labels.getLabel("statisticsApproaches.title2");
createBarLineChart(title, "", chart2, datos);
cYAxes=Labels.getLabel("graphic.activityFrequency");
Utilities.createBarLineChart(title, "",cYAxes, chart2, datos);
//gráfico circular
datos=approachService.getStatiticsTypeofArtefacts();
title= Labels.getLabel("statisticsApproaches.title3");
createPieChart(title, chart3, datos);
Utilities.createPieChart(title, chart3, datos);
}
/**
@@ -111,123 +112,12 @@ public class StatisticsApproachesController extends SelectorComposer<Component>
point.dataLabels.enabled=true;
point.dataLabels.formatter= "{return "+entry.getValue()+"}";
point.dataLabels.y=10;
point.marker.radius=entry.getValue();
int radius = entry.getValue()<7?6:entry.getValue();
point.marker.radius=radius;
}
}
compChart.run();
}
/**
* Permite crear un gráfico circular.
* @param title titulo del gráfico
* @param compChart componente gráfico donde pintarlo.
* @param datos datos con los que realizar el gráfico.
*/
private void createPieChart(String title,Chart compChart, Map<String, Integer> datos) {
compChart.setType("pie");
compChart.setTitle(title);
compChart.options.plotOptions.allowPointSelect=true;
compChart.options.plotOptions.cursor="pointer";
compChart.options.plotOptions.showInLegend=true;
compChart.options.plotOptions.dataLabels.
formatter="{return this.point.name+': '+Highcharts.numberFormat(this.percentage, 2)+'%'}";
//dividimos el mapa de datos.
List<String> keys = new ArrayList<String>();
List<Integer> data = new ArrayList<Integer>();
for (Map.Entry<String, Integer> entry : datos.entrySet()) {
keys.add(entry.getKey());
data.add(entry.getValue());
}
//series para el gráfico
Series series = compChart.addSeries();
series.name = Labels.getLabel("graphic.total");
for (int j = 0; j < data.size(); j++) {
DataPoint dataPoint = series.addDataPoint(data.get(j).doubleValue());
dataPoint.name=keys.get(j);
}
compChart.run();
}
/**
* Permite crear un gráfico de lineas y barras.
*
* @param title titulo del gráfico
* @param subTitle subtitulo del gráfico
* @param compChart componente gráfico donde pintarlo.
* @param datos datos con los que realizar el gráfico.
*/
private void createBarLineChart(String title, String subTitle, Chart compChart, Map<String, Integer> datos) {
compChart.setTitle(title);
compChart.setSubtitle(subTitle);
// dividimos el mapa de datos.
List<String> keys = new ArrayList<String>();
List<Integer> data = new ArrayList<Integer>();
double n = 0f;// numero total de datos.
for (Map.Entry<String, Integer> entry : datos.entrySet()) {
keys.add(entry.getKey());
data.add(entry.getValue());
n += entry.getValue();
}
String titleAxis = "";
String nameSeries = "";
// Creamos las x axis
Axis xAxis = compChart.getXAxis();
xAxis.categories.addAll(keys);
titleAxis = Labels.getLabel("graphic.activityFrequency");
// primer yAxis
Axis yAxis = compChart.getYAxis();
yAxis.title.text = titleAxis;
nameSeries = Labels.getLabel("graphic.frequency");
// serie para el primer yAxis
Series series = compChart.addSeries("column");
series.name = nameSeries;
series.yAxis = 0;
for (int j = 0; j < data.size(); j++) {
series.addDataPoint(j, data.get(j).doubleValue());
}
titleAxis = Labels.getLabel("graphic.cumuPercent");
// segundo yAxis
Axis yAxis1 = compChart.addYAxis();
yAxis1.title.text = titleAxis;
yAxis1.opposite = true;
yAxis1.min = 0d;
yAxis1.max = 100d;
// labels para segundo yAxis
AxisLabelOptions label = new AxisLabelOptions();
label.formatter = "{return this.value+'%'}";
yAxis1.labels = label;
nameSeries = Labels.getLabel("graphic.cumulative");
// serie para el seungo yAxis
Series series1 = compChart.addSeries("spline");
series1.name = nameSeries;
series1.yAxis = 1;
series1.plotOptions.tooltip.valueSuffix = " %";
series1.plotOptions.tooltip.valueDecimals = 2;
double cumulativeFrequency = 0.0;
for (int j = 0; j < data.size(); j++) {
cumulativeFrequency += data.get(j).doubleValue();
series1.addDataPoint(j, (cumulativeFrequency / n) * 100d);
}
compChart.options.tooltip.crosshairs = true;
compChart.options.tooltip.shared = true;
compChart.run();
}
}
Loading