Vous êtes sur la page 1sur 5

/* * To change this template, choose Tools * and open the template in the editor.

*/ package pruebasGra; import import import import import import import import import import import import import import import

Templates

ConsultasBDHospital.Prueba; Indicadores.ClassIndicadores; Indicadores.Ejecucion; Indicadores.MapIndicadores; Persistencia.Movimientoindicadores; com.icesoft.faces.component.ext.HtmlSelectOneMenu; javax.faces.event.ActionEvent; org.krysalis.jcharts.axisChart.AxisChart; org.krysalis.jcharts.chartData.AxisChartDataSet; org.krysalis.jcharts.chartData.DataSeries; org.krysalis.jcharts.properties.AxisProperties; org.krysalis.jcharts.properties.ChartProperties; org.krysalis.jcharts.properties.LegendProperties; org.krysalis.jcharts.properties.LineChartProperties; org.krysalis.jcharts.properties.PointChartProperties;

import org.krysalis.jcharts.types.ChartType; import com.icesoft.faces.component.outputchart.OutputChart; import import import import import import import import import import import import import import java.awt.Color; java.awt.Font; java.awt.Paint; java.awt.Shape; java.awt.Stroke; java.math.BigDecimal; java.math.RoundingMode; java.util.Calendar; java.util.Date; java.util.GregorianCalendar; java.util.HashMap; java.util.List; javax.faces.event.ValueChangeEvent; org.krysalis.jcharts.properties.util.ChartFont;

public class Grafica extends graficaAbstractaxD { private String clickedValue; private static AxisChart axisChart; private ChartFont fuentex = null; private ChartFont fuenteTitulo = null; private ChartFont fuenteLeyenda = null; ChartProperties chartProperties = null; AxisProperties axisProperties = null; OutputChart chart = null; Prueba p = null; DataSeries dataSeries = null; Stroke[] strokes = {LineChartProperties.DEFAULT_LINE_STROKE, LineChartProper ties.DEFAULT_LINE_STROKE, LineChartProperties.DEFAULT_LINE_STROKE};

Shape[] shapes = {PointChartProperties.SHAPE_CIRCLE, PointChartProperties.SH APE_TRIANGLE, PointChartProperties.SHAPE_DIAMOND}; public Grafica() { p = new Prueba(); fuentex = new ChartFont(new Font("Verdana", Font.PLAIN, 12), Color.BLACK ); fuenteTitulo = new ChartFont(new Font("Verdana", Font.BOLD, 12), Color.B LACK); fuenteLeyenda = new ChartFont(new Font("Verdana", Font.ITALIC, 12), Colo r.BLACK); chartProperties = new ChartProperties(); axisProperties = new AxisProperties(); chart = new OutputChart(); } private HtmlSelectOneMenu cbAnos12 = new HtmlSelectOneMenu(); public HtmlSelectOneMenu getCbAnos12() { return cbAnos12; } public void setCbAnos12(HtmlSelectOneMenu hsom) { this.cbAnos12 = hsom; } private String ano = "2011"; public String getAno() { return ano; } public void setAno(String ano) { this.ano = ano; } public void action(ActionEvent event) { if (event.getSource() instanceof OutputChart) { chart = (OutputChart) event.getSource(); clickedValue = ""; if (chart.getClickedImageMapArea().getXAxisLabel() != null) { setClickedValue(chart.getClickedImageMapArea().getXAxisLabel() + " : " + chart.getClickedImageMapArea().getValue()); } renderOnSubmit = false; } } public String getClickedValue() { return clickedValue; } public void setClickedValue(String clickedValue) { this.clickedValue = clickedValue; } public boolean newChart(OutputChart component) { if (axisChart == null generarGrafica(); component.getChart() == null) {

} if (b1 == true) { generarGrafica(); b1 = false; } component.setChart(axisChart); return renderOnSubmit; } public int obtenerDia(int ano, int mes) { Calendar cal = GregorianCalendar.getInstance(); cal.set(ano, mes, 1); return cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); } public int oYear() { int lmes = 0; Date d = new Date(); if (String.valueOf(d.getYear() + 1900).equals(this.getAno())) { lmes = d.getMonth() + 1; return lmes; } else { lmes = 12; return lmes; } } public double[][] generarDatos(int id) { String ano1 = "2011"; int lmes = this.oYear(); double[][] data = null; MapIndicadores map = new MapIndicadores(); Ejecucion eje = new Ejecucion(); HashMap mapa = map.mapaIndicadores; ClassIndicadores cli = (ClassIndicadores) mapa.get(id); switch (cli.getIdbd()) { case 1: data = new double[3][lmes]; for (int i = 0; i < 3; i++) { for (int j = 0; j < lmes; j++) { if (i == 0) { int dia = this.obtenerDia(Integer.parseInt(ano1), j) ; data[0][j] = eje.pruebaSQL(mapa, id, ano1, String.va lueOf(j + 1), String.valueOf(dia)); } if (i == 1) { data[1][j] = 30; } if (i == 2) { data[2][j] = 13; } } } break; case 2: List l1 = eje.obtenerConsulta(cli.getNumerador(), id); data = new double[3][6]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 6; j++) {

Movimientoindicadores movi = (Movimientoindicadores) l1. get(j); double max = 0; if (i == 0) { int u = 1; if (movi.getIndicadores().getUnidad().equals("Relaci on porcentual")) { u = 100; } if (movi.getIndicadores().getUnidad().equals("Tasa p or Mil")) { u = 1000; } data[0][j] = Double.parseDouble(this.redondear( (mov i.getNnumerador() / movi.getNdenominador()) * u).toString()); } if (i == 1) { data[1][j] = max; } }

} } return data; } public BigDecimal redondear(double d) { String val = d + ""; BigDecimal big = new BigDecimal(val); big = big.setScale(2, RoundingMode.HALF_UP); return big; } boolean b1 = false; public void cbAnos12_processValueChange(ValueChangeEvent vce) { if (!getAno().equals(vce.getNewValue().toString())) { setAno(vce.getNewValue().toString()); adicionarDatos(); b1 = true; } else { b1 = false; } } public String[] generarTitulosx() { int lmes = 6; String[] xAxisLabels = new String[lmes]; for (int i = 0; i < lmes; i++) { xAxisLabels[i] = this.vMeses()[i]; } return xAxisLabels; }

private String[] vMeses() { String[] meses = new String[12]; meses[0] = "Enero"; meses[1] = "Febrero"; meses[2] = "Marzo"; meses[3] = "Abril"; meses[4] = "Mayo"; meses[5] = "Junio"; meses[6] = "Julio"; meses[7] = "Agosto"; meses[8] = "Septiembre"; meses[9] = "Octubre"; meses[10] = "Noviembre"; meses[11] = "Diciembre"; return meses; } Paint[] paints = null; LineChartProperties lineChartProperties = null; AxisChartDataSet axisChartDataSet = null; String[] legendLabels1 = null; public void generarGrafica() { try { String titulosmeses = "Meses"; String tituloy = "Valor"; String titulo = "OPORTUNIDAD MEDICINA INTERNA AO " + getAno(); String[] titulosx = generarTitulosx(); double[][] datos = generarDatos(128); legendLabels1 = new String[]{"INDICADOR", "ESTANDAR 056", "ESTANDAR 0386"}; paints = new Paint[]{new Color(0x0D4274), new Color(0xF78208), new C olor(0xF12842)}; lineChartProperties = new LineChartProperties(strokes, shapes); dataSeries = new DataSeries(titulosx, titulosmeses, tituloy, titulo) ; axisChartDataSet = new AxisChartDataSet(datos, legendLabels1, paints , ChartType.LINE, lineChartProperties); dataSeries.addIAxisPlotDataSet(axisChartDataSet); axisProperties.getXAxisProperties().setAxisTitleChartFont(fuentex); axisProperties.getYAxisProperties().setAxisTitleChartFont(fuentex); chartProperties.setTitleFont(fuenteTitulo); LegendProperties legendProperties = new LegendProperties(); legendProperties.setChartFont(fuenteLeyenda); axisChart = new AxisChart(dataSeries, chartProperties, axisPropertie s, legendProperties, 800, 400); renderOnSubmit = true; } catch (Exception e) { e.printStackTrace(); } } @Override public void adicionarDatos() { renderOnSubmit = true; } }