List of usage examples for org.jfree.chart.axis CategoryAxis setCategoryLabelPositions
public void setCategoryLabelPositions(CategoryLabelPositions positions)
From source file:Output.SplitChart.java
public void drawLSEFixedDemandData(int[] selectIndex) { this.chartTitle = "24 Hour LSE Fixed Demand (Load Profile)"; Object[][] lseData = this.amesFrame.getLSEData(); this.dataset = new XYSeriesCollection(); DefaultCategoryDataset dataset3D = new DefaultCategoryDataset(); if ((selectIndex.length < 1) || (selectIndex[0] == 0)) { for (Object[] element : lseData) { XYSeries series = new XYSeries((String) element[0]); for (int j = 0; j < 24; j++) { series.add(j, Support.parseDouble(element[j + 3].toString())); }/* w w w . j a v a 2s .c om*/ this.dataset.addSeries(series); } } else { int iDataNumber = selectIndex.length; for (int i = 0; i < iDataNumber; i++) { XYSeries series = new XYSeries((String) lseData[selectIndex[i] - 1][0]); for (int j = 0; j < 24; j++) { if (iDataNumber == 1) { String temp = " " + j; dataset3D.addValue(Support.parseDouble(lseData[selectIndex[i] - 1][j + 3].toString()), lseData[selectIndex[i] - 1][0].toString(), temp); } else { series.add(j, Support.parseDouble(lseData[selectIndex[i] - 1][j + 3].toString())); } } if (iDataNumber != 1) { this.dataset.addSeries(series); } } } if ((selectIndex.length == 1) && (selectIndex[0] != 0)) { this.chartTitle = (String) (lseData[selectIndex[0] - 1][0]); this.chartTitle = this.chartTitle + " 24 Hour Fixed Demand (Load Profile)"; this.chart = ChartFactory.createBarChart3D(this.chartTitle, // chart title "Hour", // domain axis label "Power (MWs)", // range axis label dataset3D, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); final CategoryPlot plot = this.chart.getCategoryPlot(); final CategoryAxis axis = plot.getDomainAxis(); axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0)); final CategoryItemRenderer renderer = plot.getRenderer(); renderer.setItemLabelsVisible(true); final BarRenderer r = (BarRenderer) renderer; r.setMaximumBarWidth(0.05); } else { // create the chart... this.chart = ChartFactory.createXYLineChart(this.chartTitle, // chart title "Hour", // x axis label "Power (MWs)", // y axis label this.dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); this.chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final XYPlot plot = this.chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.blue); plot.setRangeGridlinePaint(Color.blue); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00")); renderer.setToolTipGenerator(generator); plot.setRenderer(renderer); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xAxis.setRange(0, 23.5); } this.chart.getTitle().setFont(this.font); this.chartPanel.setChart(this.chart); }
From source file:Output.SplitChart.java
public void drawGeneratorData(int[] selectIndex) { DefaultCategoryDataset dataset3D = new DefaultCategoryDataset(); String xLabel = "Power (MWs)"; this.dataset = new XYSeriesCollection(); boolean bDraw3D = true; Object[][] genData = this.amesFrame.getGeneratorData(); int iGenNumber = genData.length; if ((selectIndex.length < 1) || (selectIndex[0] == 0)) { for (int i = 0; i < iGenNumber; i++) { String genName = (String) genData[i][0]; dataset3D.addValue((Math.round(Support.parseDouble(genData[i][6].toString()) * 1000)) / 1000.0, "capL (MW)", genName); dataset3D.addValue((Math.round(Support.parseDouble(genData[i][7].toString()) * 1000)) / 1000.0, "capU (MW)", genName); }// w w w. ja v a 2s . com } else { int iDataNumber = selectIndex.length; if (iDataNumber > 1) { for (int i = 0; i < iDataNumber; i++) { String genName = (String) genData[selectIndex[i] - 1][0]; dataset3D.addValue( (Math.round(Support.parseDouble(genData[selectIndex[i] - 1][6].toString()) * 1000)) / 1000.0, "capL (MW)", genName); dataset3D.addValue( (Math.round(Support.parseDouble(genData[selectIndex[i] - 1][7].toString()) * 1000)) / 1000.0, "capU (MW)", genName); } } else { // only select one GenCo XYSeries series = new XYSeries("True"); int genIndex = selectIndex[0] - 1; this.chartTitle = (String) genData[genIndex][0] + "'s True Marginal Cost Function"; double da = Support.parseDouble(genData[genIndex][4].toString()); double db = Support.parseDouble(genData[genIndex][5].toString()); double dMinCap = Support.parseDouble(genData[genIndex][6].toString()); double dMaxCap = Support.parseDouble(genData[genIndex][7].toString()); double dStart = da + (2.0 * db * dMinCap); double dEnd = da + (2.0 * db * dMaxCap); series.add(dMinCap, dStart); series.add(dMaxCap, dEnd); this.dataset.addSeries(series); bDraw3D = false; } } if (bDraw3D) { this.chart = ChartFactory.createBarChart3D("GenCo Lower and Upper Operating Limits", // chart title "", // domain axis label "Capacities (MWs)", // range axis label dataset3D, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); final CategoryPlot plot = this.chart.getCategoryPlot(); final CategoryAxis axis = plot.getDomainAxis(); axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0)); final CategoryItemRenderer renderer = plot.getRenderer(); renderer.setItemLabelsVisible(true); final BarRenderer r = (BarRenderer) renderer; r.setMaximumBarWidth(0.05); } else { // create the chart... this.chart = ChartFactory.createXYLineChart(this.chartTitle, // chart title xLabel, // x axis label "Price ($/MWh)", // y axis label this.dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); this.chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final XYPlot plot = this.chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.blue); plot.setRangeGridlinePaint(Color.blue); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00")); renderer.setToolTipGenerator(generator); plot.setRenderer(renderer); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } this.chart.getTitle().setFont(this.font); this.chartPanel.setChart(this.chart); }
From source file:Output.SplitChart.java
public void drawLSESurplusData(String outputTimeTypeSelect, int iStartTime, int iEndTime, int[] selectIndex) { String[] names = { "LSE Name", "Day Index", "Surplus ($/H)" }; this.chartTitle = "LSE Daily Net Earnings"; ArrayList lseAgentSurplusByDay = this.amesFrame.getAMESMarket().getLSEAgentSurplusByDay(); boolean draw3DChart = false; this.dataset = new XYSeriesCollection(); DefaultCategoryDataset dataset3D = new DefaultCategoryDataset(); Object[][] lseHybridData = this.amesFrame.getLSEHybridDemandData(); int iLSENumber = lseHybridData.length; if ((selectIndex.length < 1) || (selectIndex[0] == 0)) { if (outputTimeTypeSelect.equalsIgnoreCase("Entire Run")) { int iDayNumber = lseAgentSurplusByDay.size(); double[][] lseSurplus; this.chartTitle = this.chartTitle + "\n " + "for Entire Run"; for (int i = 0; i < iLSENumber; i++) { String lseName = (String) lseHybridData[i][0]; XYSeries series1 = new XYSeries(lseName + " Surplus"); for (int iDay = 0; iDay < iDayNumber; iDay++) { lseSurplus = (double[][]) lseAgentSurplusByDay.get(iDay); series1.add(iDay + 1, (Math.round(lseSurplus[i][0] * 1000)) / 1000.0); }/*www.java2 s . co m*/ this.dataset.addSeries(series1); } } else if (outputTimeTypeSelect.equalsIgnoreCase("Start to End Day")) { int iDayNumber = (iEndTime - iStartTime) + 1; double[][] lseSurplus; this.chartTitle = this.chartTitle + "\n " + "From Day " + iStartTime + " to Day " + iEndTime; for (int i = 0; i < iLSENumber; i++) { String lseName = (String) lseHybridData[i][0]; XYSeries series1 = new XYSeries(lseName + " Surplus"); for (int iDay = iStartTime - 1; iDay < iEndTime; iDay++) { lseSurplus = (double[][]) lseAgentSurplusByDay.get(iDay); series1.add(iDay + 1, (Math.round(lseSurplus[i][0] * 1000)) / 1000.0); } this.dataset.addSeries(series1); } } } else { int iDataNumber = selectIndex.length; int iField = names.length; if (outputTimeTypeSelect.equalsIgnoreCase("Entire Run")) { int iDayNumber = lseAgentSurplusByDay.size(); double[][] lseSurplus; this.chartTitle = this.chartTitle + "\n " + "for Entire Run"; for (int i = 0; i < iDataNumber; i++) { String lseName = (String) lseHybridData[selectIndex[i] - 1][0]; XYSeries series1 = new XYSeries(lseName + " Surplus"); for (int iDay = 0; iDay < iDayNumber; iDay++) { lseSurplus = (double[][]) lseAgentSurplusByDay.get(iDay); series1.add(iDay + 1, (Math.round(lseSurplus[selectIndex[i] - 1][0] * 1000)) / 1000.0); } this.dataset.addSeries(series1); } } else if (outputTimeTypeSelect.equalsIgnoreCase("Start to End Day")) { int iDayNumber = (iEndTime - iStartTime) + 1; double[][] lseSurplus; this.chartTitle = this.chartTitle + "\n " + "From Day " + iStartTime + " to Day " + iEndTime; for (int i = 0; i < iDataNumber; i++) { String lseName = (String) lseHybridData[selectIndex[i] - 1][0]; XYSeries series1 = new XYSeries(lseName + " Surplus"); for (int iDay = iStartTime - 1; iDay < iEndTime; iDay++) { lseSurplus = (double[][]) lseAgentSurplusByDay.get(iDay); series1.add(iDay + 1, (Math.round(lseSurplus[selectIndex[i] - 1][0] * 1000)) / 1000.0); } this.dataset.addSeries(series1); } } } if (draw3DChart) { this.chart = ChartFactory.createBarChart3D(this.chartTitle, // chart title "Value Category", // domain axis label "Value", // range axis label dataset3D, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); final CategoryPlot plot = this.chart.getCategoryPlot(); final CategoryAxis axis = plot.getDomainAxis(); axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0)); final CategoryItemRenderer renderer = plot.getRenderer(); renderer.setItemLabelsVisible(true); final BarRenderer r = (BarRenderer) renderer; r.setMaximumBarWidth(0.05); } else { // create the chart... this.chart = ChartFactory.createXYLineChart(this.chartTitle, // chart title "Day", // x axis label "Value", // y axis label this.dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); this.chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final XYPlot plot = this.chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.blue); plot.setRangeGridlinePaint(Color.blue); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00")); renderer.setToolTipGenerator(generator); plot.setRenderer(renderer); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } this.chart.getTitle().setFont(this.font); this.chartPanel.setChart(this.chart); }
From source file:Output.SplitChart.java
public void drawGeneratorProfitAndNetEarningsData(String outputTimeTypeSelect, int iStartTime, int iEndTime, int[] selectIndex, boolean bProfit) { if (bProfit) { this.chartTitle = "GenCo Daily Profits"; } else {//from w ww. ja v a2 s . c o m this.chartTitle = "GenCo Daily Net Earnings"; } ArrayList genAgentProfitAndNetGainByDay = this.amesFrame.getAMESMarket().getGenAgentProfitAndNetGainByDay(); boolean draw3DChart = false; this.dataset = new XYSeriesCollection(); DefaultCategoryDataset dataset3D = new DefaultCategoryDataset(); Object[][] genData = this.amesFrame.getGeneratorData(); int iGenNumber = genData.length; if ((selectIndex.length < 1) || (selectIndex[0] == 0)) { if (outputTimeTypeSelect.equalsIgnoreCase("Entire Run")) { int iDayNumber = genAgentProfitAndNetGainByDay.size(); double[][] genProfit; this.chartTitle = this.chartTitle + "\n " + "for Entire Run"; for (int i = 0; i < iGenNumber; i++) { String genName = (String) genData[i][0]; XYSeries series1; series1 = new XYSeries(genName); for (int iDay = 0; iDay < iDayNumber; iDay++) { genProfit = (double[][]) genAgentProfitAndNetGainByDay.get(iDay); if (bProfit) { series1.add(iDay + 1, (Math.round(genProfit[i][0] * 1000)) / 1000.0); } else { series1.add(iDay + 1, (Math.round(genProfit[i][1] * 1000)) / 1000.0); } } this.dataset.addSeries(series1); } } else if (outputTimeTypeSelect.equalsIgnoreCase("Start to End Day")) { int iDayNumber = (iEndTime - iStartTime) + 1; double[][] genProfit; this.chartTitle = this.chartTitle + "\n " + "From Day " + iStartTime + " to Day " + iEndTime; for (int i = 0; i < iGenNumber; i++) { String genName = (String) genData[i][0]; XYSeries series1; series1 = new XYSeries(genName); for (int iDay = iStartTime - 1; iDay < iEndTime; iDay++) { genProfit = (double[][]) genAgentProfitAndNetGainByDay.get(iDay); if (bProfit) { series1.add(iDay + 1, (Math.round(genProfit[i][0] * 1000)) / 1000.0); } else { series1.add(iDay + 1, (Math.round(genProfit[i][1] * 1000)) / 1000.0); } } this.dataset.addSeries(series1); } } } else { int iDataNumber = selectIndex.length; if (outputTimeTypeSelect.equalsIgnoreCase("Entire Run")) { int iDayNumber = genAgentProfitAndNetGainByDay.size(); double[][] genProfit; this.chartTitle = this.chartTitle + "\n " + "for Entire Run"; for (int i = 0; i < iDataNumber; i++) { String genName = (String) genData[selectIndex[i] - 1][0]; XYSeries series1; series1 = new XYSeries(genName); for (int iDay = 0; iDay < iDayNumber; iDay++) { genProfit = (double[][]) genAgentProfitAndNetGainByDay.get(iDay); if (bProfit) { series1.add(iDay + 1, (Math.round(genProfit[selectIndex[i] - 1][0] * 1000)) / 1000.0); } else { series1.add(iDay + 1, (Math.round(genProfit[selectIndex[i] - 1][1] * 1000)) / 1000.0); } } this.dataset.addSeries(series1); } } else if (outputTimeTypeSelect.equalsIgnoreCase("Start to End Day")) { int iDayNumber = (iEndTime - iStartTime) + 1; double[][] genProfit; this.chartTitle = this.chartTitle + "\n " + "From Day " + iStartTime + " to Day " + iEndTime; for (int i = 0; i < iDataNumber; i++) { String genName = (String) genData[selectIndex[i] - 1][0]; XYSeries series1; series1 = new XYSeries(genName); for (int iDay = iStartTime - 1; iDay < iEndTime; iDay++) { genProfit = (double[][]) genAgentProfitAndNetGainByDay.get(iDay); if (bProfit) { series1.add(iDay + 1, (Math.round(genProfit[selectIndex[i] - 1][0] * 1000)) / 1000.0); } else { series1.add(iDay + 1, (Math.round(genProfit[selectIndex[i] - 1][1] * 1000)) / 1000.0); } } this.dataset.addSeries(series1); } } } if (draw3DChart) { this.chart = ChartFactory.createBarChart3D(this.chartTitle, // chart title "Value Category", // domain axis label "Value ($/D)", // range axis label dataset3D, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); final CategoryPlot plot = this.chart.getCategoryPlot(); final CategoryAxis axis = plot.getDomainAxis(); axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0)); final CategoryItemRenderer renderer = plot.getRenderer(); renderer.setItemLabelsVisible(true); final BarRenderer r = (BarRenderer) renderer; r.setMaximumBarWidth(0.05); } else { // create the chart... this.chart = ChartFactory.createXYLineChart(this.chartTitle, // chart title "Day", // x axis label "Money ($/D)", // y axis label this.dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); this.chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final XYPlot plot = this.chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.blue); plot.setRangeGridlinePaint(Color.blue); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00")); renderer.setToolTipGenerator(generator); plot.setRenderer(renderer); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } this.chart.getTitle().setFont(this.font); this.chartPanel.setChart(this.chart); }
From source file:controller.ChartAndGraphServlet.java
/** * Creates the appropriate chart for the patient history page or the * statistics page. Line charts are created to display a longitudinal view * of patient results on the history page. The statistics page includes pie * charts, bar charts, histograms, and box and whisker charts. * * @param request servlet request/* w ww . j a va 2 s . co m*/ * @param response servlet response * @throws IOException */ public void getChart(HttpServletRequest request, HttpServletResponse response) throws IOException { HttpSession session = request.getSession(); response.setContentType("image/png"); OutputStream outputStream = response.getOutputStream(); final int widthIncreaseThreshold = 18; final int incrementalIncreaseThreshold = 22; final int incrementalIncreaseInPixels = 45; final int treatmentClassUnknownIndex = 6; int width = 640; int height = 450; int bigWidth = 780; ReferenceContainer rc = (ReferenceContainer) session.getServletContext().getAttribute("references"); HealthyTargetReference htr = rc.getHealthyTargets(); String action = request.getParameter("action"); switch (action) { case "a1c": { ArrayList<A1cResult> a1cHistory = (ArrayList<A1cResult>) session .getAttribute(SessionObjectUtility.A1C_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = a1cHistory.size() - 1; i > -1; i--) { dataset.addValue(a1cHistory.get(i).getValue(), "A1C", a1cHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.A1C_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("A1C History", "dates", "A1C", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getA1c().getUpperBound(); BigDecimal lower = htr.getA1c().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (a1cHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (a1cHistory.size() > incrementalIncreaseThreshold) { int increments = a1cHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "psa": { ArrayList<ContinuousResult> psaHistory = (ArrayList<ContinuousResult>) session .getAttribute(SessionObjectUtility.PSA_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = psaHistory.size() - 1; i > -1; i--) { dataset.addValue(psaHistory.get(i).getValue(), "PSA", psaHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.PSA_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("PSA History", "dates", "PSA", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getPsa().getUpperBound(); BigDecimal lower = htr.getPsa().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (psaHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (psaHistory.size() > incrementalIncreaseThreshold) { int increments = psaHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "alt": { ArrayList<ContinuousResult> altHistory = (ArrayList<ContinuousResult>) session .getAttribute(SessionObjectUtility.ALT_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = altHistory.size() - 1; i > -1; i--) { dataset.addValue(altHistory.get(i).getValue(), "ALT", altHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.ALT_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("ALT History", "dates", "ALT", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getAlt().getUpperBound(); BigDecimal lower = htr.getAlt().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (altHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (altHistory.size() > incrementalIncreaseThreshold) { int increments = altHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "ast": { ArrayList<ContinuousResult> astHistory = (ArrayList<ContinuousResult>) session .getAttribute(SessionObjectUtility.AST_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = astHistory.size() - 1; i > -1; i--) { dataset.addValue(astHistory.get(i).getValue(), "AST", astHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.AST_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("AST History", "dates", "AST", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getAst().getUpperBound(); BigDecimal lower = htr.getAst().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (astHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (astHistory.size() > incrementalIncreaseThreshold) { int increments = astHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "bp": { ArrayList<BloodPressureResult> bpHistory = (ArrayList<BloodPressureResult>) session .getAttribute(SessionObjectUtility.BP_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = bpHistory.size() - 1; i > -1; i--) { dataset.addValue(bpHistory.get(i).getSystolicValue(), "systolic", bpHistory.get(i).getDate()); dataset.addValue(bpHistory.get(i).getDiastolicValue(), "diastolic", bpHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.BP_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("Blood Pressure History", "dates", "blood pressure", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upperSystole = htr.getBloodPressureSystole().getUpperBound(); BigDecimal upperDiastole = htr.getBloodPressureDiastole().getUpperBound(); if (upperSystole != null) { ValueMarker marker = new ValueMarker(upperSystole.doubleValue()); marker.setPaint(Color.MAGENTA); plot.addRangeMarker(marker); } if (upperDiastole != null) { ValueMarker marker = new ValueMarker(upperDiastole.doubleValue()); marker.setPaint(Color.BLUE); plot.addRangeMarker(marker); } if (bpHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (bpHistory.size() > incrementalIncreaseThreshold) { int increments = bpHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "bmi": { ArrayList<ContinuousResult> bmiHistory = (ArrayList<ContinuousResult>) session .getAttribute(SessionObjectUtility.BMI_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = bmiHistory.size() - 1; i > -1; i--) { dataset.addValue(bmiHistory.get(i).getValue(), "BMI", bmiHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.BMI_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("BMI History", "dates", "BMI", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getBmi().getUpperBound(); BigDecimal lower = htr.getBmi().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (bmiHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (bmiHistory.size() > incrementalIncreaseThreshold) { int increments = bmiHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "creatinine": { ArrayList<ContinuousResult> creatinineHistory = (ArrayList<ContinuousResult>) session .getAttribute(SessionObjectUtility.CREATININE_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = creatinineHistory.size() - 1; i > -1; i--) { dataset.addValue(creatinineHistory.get(i).getValue(), "creatinine", creatinineHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.CREATININE_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("Creatinine History", "dates", "creatinine", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getCreatinine().getUpperBound(); BigDecimal lower = htr.getCreatinine().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (creatinineHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (creatinineHistory.size() > incrementalIncreaseThreshold) { int increments = creatinineHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "egfr": { ArrayList<ContinuousResult> egfrHistory = (ArrayList<ContinuousResult>) session .getAttribute(SessionObjectUtility.EGFR_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = egfrHistory.size() - 1; i > -1; i--) { dataset.addValue(egfrHistory.get(i).getValue(), "eGFR", egfrHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.EGFR_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("eGFR History", "dates", "eGFR", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getEgfr().getUpperBound(); BigDecimal lower = htr.getEgfr().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (egfrHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (egfrHistory.size() > incrementalIncreaseThreshold) { int increments = egfrHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "glucose": { ArrayList<ContinuousResult> glucoseHistory = (ArrayList<ContinuousResult>) session .getAttribute(SessionObjectUtility.GLUCOSE_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = glucoseHistory.size() - 1; i > -1; i--) { dataset.addValue(glucoseHistory.get(i).getValue(), "glucose", glucoseHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.GLUCOSE_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("Glucose History", "dates", "glucose", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getGlucoseAc().getUpperBound(); BigDecimal lower = htr.getGlucoseAc().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (glucoseHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (glucoseHistory.size() > incrementalIncreaseThreshold) { int increments = glucoseHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "hdl": { ArrayList<ContinuousResult> hdlHistory = (ArrayList<ContinuousResult>) session .getAttribute(SessionObjectUtility.HDL_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = hdlHistory.size() - 1; i > -1; i--) { dataset.addValue(hdlHistory.get(i).getValue(), "HDL", hdlHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.HDL_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /*get the chart */ JFreeChart chart = ChartFactory.createLineChart("HDL History", "dates", "HDL", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upperFemale = htr.getHdlFemale().getUpperBound(); BigDecimal lowerFemale = htr.getHdlFemale().getLowerBound(); BigDecimal upperMale = htr.getHdlMale().getUpperBound(); BigDecimal lowerMale = htr.getHdlMale().getLowerBound(); if (upperFemale != null) { ValueMarker marker = new ValueMarker(upperFemale.doubleValue()); marker.setPaint(Color.MAGENTA); plot.addRangeMarker(marker); } if (lowerFemale != null) { ValueMarker marker = new ValueMarker(lowerFemale.doubleValue()); marker.setPaint(Color.MAGENTA); plot.addRangeMarker(marker); } if (upperMale != null) { ValueMarker marker = new ValueMarker(upperMale.doubleValue()); marker.setPaint(Color.BLUE); plot.addRangeMarker(marker); } if (lowerMale != null) { ValueMarker marker = new ValueMarker(lowerMale.doubleValue()); marker.setPaint(Color.BLUE); plot.addRangeMarker(marker); } if (hdlHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (hdlHistory.size() > incrementalIncreaseThreshold) { int increments = hdlHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "ldl": { ArrayList<LdlResult> ldlHistory = (ArrayList<LdlResult>) session .getAttribute(SessionObjectUtility.LDL_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = ldlHistory.size() - 1; i > -1; i--) { dataset.addValue(ldlHistory.get(i).getValue(), "LDL", ldlHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.LDL_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("LDL History", "dates", "LDL", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getLdl().getUpperBound(); BigDecimal lower = htr.getLdl().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (ldlHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (ldlHistory.size() > incrementalIncreaseThreshold) { int increments = ldlHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "compliance": { ArrayList<ContinuousResult> complianceHistory = (ArrayList<ContinuousResult>) session .getAttribute(SessionObjectUtility.COMPLIANCE_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = complianceHistory.size() - 1; i > -1; i--) { dataset.addValue(complianceHistory.get(i).getValue(), "compliance", complianceHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.COMPLIANCE_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("Compliance History", "dates", "compliance", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); if (complianceHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (complianceHistory.size() > incrementalIncreaseThreshold) { int increments = complianceHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "physicalActivity": { ArrayList<DiscreteResult> physicalActivityHistory = (ArrayList<DiscreteResult>) session .getAttribute(SessionObjectUtility.PHYSICAL_ACTIVITY_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = physicalActivityHistory.size() - 1; i > -1; i--) { dataset.addValue(physicalActivityHistory.get(i).getValue(), "physical activity", physicalActivityHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.PHYSICAL_ACTIVITY_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("Physical Activity History", "dates", "min per wk", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getPhysicalActivity().getUpperBound(); BigDecimal lower = htr.getPhysicalActivity().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (physicalActivityHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (physicalActivityHistory.size() > incrementalIncreaseThreshold) { int increments = physicalActivityHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "psychological": { ArrayList<PsychologicalScreeningResult> psychologicalHistory = (ArrayList<PsychologicalScreeningResult>) session .getAttribute(SessionObjectUtility.PSYCHOLOGICAL_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = psychologicalHistory.size() - 1; i > -1; i--) { dataset.addValue(psychologicalHistory.get(i).getScore(), "PHQ9 score", psychologicalHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.PSYCHOLOGICAL_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("Psychological Screening History", "dates", "score", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); if (psychologicalHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (psychologicalHistory.size() > incrementalIncreaseThreshold) { int increments = psychologicalHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "t4": { ArrayList<ContinuousResult> t4History = (ArrayList<ContinuousResult>) session .getAttribute(SessionObjectUtility.T4_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = t4History.size() - 1; i > -1; i--) { dataset.addValue(t4History.get(i).getValue(), "T4", t4History.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.T4_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("T4 History", "dates", "T4", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getT4().getUpperBound(); BigDecimal lower = htr.getT4().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (t4History.size() > widthIncreaseThreshold) { width = bigWidth; } if (t4History.size() > incrementalIncreaseThreshold) { int increments = t4History.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "triglycerides": { ArrayList<ContinuousResult> triglyceridesHistory = (ArrayList<ContinuousResult>) session .getAttribute(SessionObjectUtility.TRIGLYCERIDES_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = triglyceridesHistory.size() - 1; i > -1; i--) { dataset.addValue(triglyceridesHistory.get(i).getValue(), "triglycerides", triglyceridesHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.TRIGLYCERIDES_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("Triglycerides History", "dates", "triglycerides", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getTriglycerides().getUpperBound(); BigDecimal lower = htr.getTriglycerides().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (triglyceridesHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (triglyceridesHistory.size() > incrementalIncreaseThreshold) { int increments = triglyceridesHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "tsh": { ArrayList<TshResult> tshHistory = (ArrayList<TshResult>) session .getAttribute(SessionObjectUtility.TSH_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = tshHistory.size() - 1; i > -1; i--) { dataset.addValue(tshHistory.get(i).getValue(), "TSH", tshHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.TSH_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("TSH History", "dates", "TSH", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getTsh().getUpperBound(); BigDecimal lower = htr.getTsh().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (tshHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (tshHistory.size() > incrementalIncreaseThreshold) { int increments = tshHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "uacr": { ArrayList<ContinuousResult> uacrHistory = (ArrayList<ContinuousResult>) session .getAttribute(SessionObjectUtility.UACR_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = uacrHistory.size() - 1; i > -1; i--) { dataset.addValue(uacrHistory.get(i).getValue(), "UACR", uacrHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.UACR_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("UACR History", "dates", "UACR", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upper = htr.getUacr().getUpperBound(); BigDecimal lower = htr.getUacr().getLowerBound(); if (upper != null) { ValueMarker marker = new ValueMarker(upper.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (lower != null) { ValueMarker marker = new ValueMarker(lower.doubleValue()); marker.setPaint(Color.YELLOW); plot.addRangeMarker(marker); } if (uacrHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (uacrHistory.size() > incrementalIncreaseThreshold) { int increments = uacrHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "waist": { ArrayList<ContinuousResult> waistHistory = (ArrayList<ContinuousResult>) session .getAttribute(SessionObjectUtility.WAIST_GRAPH_POINTS); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); /* add the data */ for (int i = waistHistory.size() - 1; i > -1; i--) { dataset.addValue(waistHistory.get(i).getValue(), "waist", waistHistory.get(i).getDate()); } /* remove reference */ session.setAttribute(SessionObjectUtility.WAIST_GRAPH_POINTS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createLineChart("Waist History", "dates", "waist", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); /* angle the x-axis labels */ CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); /* show the healthy target boundaries */ BigDecimal upperFemale = htr.getWaistFemale().getUpperBound(); BigDecimal lowerFemale = htr.getWaistFemale().getLowerBound(); BigDecimal upperMale = htr.getWaistMale().getUpperBound(); BigDecimal lowerMale = htr.getWaistMale().getLowerBound(); if (upperFemale != null) { ValueMarker marker = new ValueMarker(upperFemale.doubleValue()); marker.setPaint(Color.MAGENTA); plot.addRangeMarker(marker); } if (lowerFemale != null) { ValueMarker marker = new ValueMarker(lowerFemale.doubleValue()); marker.setPaint(Color.MAGENTA); plot.addRangeMarker(marker); } if (upperMale != null) { ValueMarker marker = new ValueMarker(upperMale.doubleValue()); marker.setPaint(Color.BLUE); plot.addRangeMarker(marker); } if (lowerMale != null) { ValueMarker marker = new ValueMarker(lowerMale.doubleValue()); marker.setPaint(Color.BLUE); plot.addRangeMarker(marker); } if (waistHistory.size() > widthIncreaseThreshold) { width = bigWidth; } if (waistHistory.size() > incrementalIncreaseThreshold) { int increments = waistHistory.size() % incrementalIncreaseThreshold; for (int i = 0; i < increments; i++) { width += incrementalIncreaseInPixels; } } ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "agedemographics": { DemographicData demographicData = (DemographicData) session .getAttribute(SessionObjectUtility.AGE_DEMOGRAPHICS_GRAPH_DATA); HistogramDataset dataset = new HistogramDataset(); ArrayList<Integer> ages = demographicData.getAges(); if (ages.size() > 0) { double[] vector = new double[ages.size()]; for (int i = 0; i < vector.length; i++) { vector[i] = ages.get(i); } /* add the data */ dataset.addSeries("number of patients", vector, 10); /* remove reference */ session.setAttribute(SessionObjectUtility.AGE_DEMOGRAPHICS_GRAPH_DATA, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createHistogram("Age Distribution", "age", "number of patients", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); XYPlot plot = chart.getXYPlot(); final XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); /* creating a shadow */ renderer.setShadowXOffset(4.0); renderer.setShadowYOffset(1.5); renderer.setShadowVisible(true); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); } break; } case "genderdemographics": { DemographicData demographicData = (DemographicData) session .getAttribute(SessionObjectUtility.GENDER_DEMOGRAPHICS_GRAPH_DATA); DefaultPieDataset dataset = new DefaultPieDataset(); /* add the data */ dataset.setValue("female", demographicData.getPercentFemale()); dataset.setValue("male", demographicData.getPercentMale()); /* remove reference */ session.setAttribute(SessionObjectUtility.GENDER_DEMOGRAPHICS_GRAPH_DATA, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createPieChart3D("Gender", dataset, legend, tooltips, urls); final PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(90); plot.setForegroundAlpha(0.60f); plot.setInteriorGap(0.02); PieSectionLabelGenerator labels = new StandardPieSectionLabelGenerator("{0}: ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot.setLabelGenerator(labels); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "racedemographics": { DemographicData demographicData = (DemographicData) session .getAttribute(SessionObjectUtility.RACE_DEMOGRAPHICS_GRAPH_DATA); DefaultPieDataset dataset = new DefaultPieDataset(); /* add the data */ dataset.setValue("White", demographicData.getPercentWhite()); dataset.setValue("African American", demographicData.getPercentAfricanAmerican()); dataset.setValue("Asian/Pacific Islander", demographicData.getPercentAsian()); dataset.setValue("American Indian/Alaska Native", demographicData.getPercentIndian()); dataset.setValue("Hispanic", demographicData.getPercentHispanic()); dataset.setValue("Middle Eastern", demographicData.getPercentMiddleEastern()); dataset.setValue("Other", demographicData.getPercentOther()); /* remove reference */ session.setAttribute(SessionObjectUtility.RACE_DEMOGRAPHICS_GRAPH_DATA, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createPieChart3D("Race", dataset, legend, tooltips, urls); final PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(90); plot.setForegroundAlpha(0.60f); plot.setInteriorGap(0.02); PieSectionLabelGenerator labels = new StandardPieSectionLabelGenerator("{0}: ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot.setLabelGenerator(labels); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "lasta1c": { Stats glycemicStats = (Stats) session.getAttribute(SessionObjectUtility.LAST_A1C_DATA); HistogramDataset dataset = new HistogramDataset(); ArrayList<CategoricalValue> lastA1cValues = new ArrayList<>(); if (glycemicStats.getGroups() != null) { int i; for (i = 0; i < glycemicStats.getGroups().size(); i++) { if (glycemicStats.getGroups().get(i) != null) { lastA1cValues.addAll(glycemicStats.getGroups().get(i)); } } } if (lastA1cValues.size() > 0) { double[] vector = new double[lastA1cValues.size()]; for (int i = 0; i < vector.length; i++) { vector[i] = lastA1cValues.get(i).getValue().doubleValue(); } /* add the data */ dataset.addSeries("number of patients", vector, 15); /* remove reference */ session.setAttribute(SessionObjectUtility.LAST_A1C_DATA, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createHistogram("Most Recent A1C Values", "last A1C(%)", "number of patients", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); XYPlot plot = chart.getXYPlot(); final XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); /* creating a shadow */ renderer.setShadowXOffset(4.0); renderer.setShadowYOffset(1.5); renderer.setShadowVisible(true); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); } break; } case "lasta1cbyclassattendance": { final int topGroupIndex = 4; Stats glycemicStats = (Stats) session.getAttribute(SessionObjectUtility.LAST_A1C_BY_CLASS_DATA); DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); if (glycemicStats.getGroups() != null) { for (int i = 0; i < glycemicStats.getGroups().size(); i++) { if ((glycemicStats.getGroups().get(i) != null) && (!glycemicStats.getGroups().get(i).isEmpty())) { List values = new ArrayList(); for (CategoricalValue cv : glycemicStats.getGroups().get(i)) { values.add(cv.getValue()); } if (i == topGroupIndex) { dataset.add(BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values), "last A1C(%)", "5 or more"); } else { dataset.add(BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values), "last A1C(%)", i + 1); } } } } /* remove reference */ session.setAttribute(SessionObjectUtility.LAST_A1C_BY_CLASS_DATA, null); CategoryAxis domainAxis = new CategoryAxis("number of classes attended"); NumberAxis rangeAxis = new NumberAxis("last A1C(%)"); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart("Most Recent A1C by Classes Attended", plot); renderer.setMeanVisible(false); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "lastbmimales": { Stats bmiMalesStats = (Stats) session.getAttribute(SessionObjectUtility.LAST_BMI_MALES_DATA); HistogramDataset dataset = new HistogramDataset(); ArrayList<CategoricalValue> lastBmiMalesValues = new ArrayList<>(); if ((bmiMalesStats.getGroups() != null) && (!bmiMalesStats.getGroups().isEmpty())) { for (int i = 0; i < bmiMalesStats.getGroups().size(); i++) { if (bmiMalesStats.getGroups().get(i) != null) { lastBmiMalesValues.addAll(bmiMalesStats.getGroups().get(i)); } } } if (lastBmiMalesValues.size() > 0) { double[] vector = new double[lastBmiMalesValues.size()]; for (int i = 0; i < vector.length; i++) { vector[i] = lastBmiMalesValues.get(i).getValue().doubleValue(); } /* add the data */ dataset.addSeries("number of patients", vector, 15); /* remove reference */ session.setAttribute(SessionObjectUtility.LAST_BMI_MALES_DATA, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createHistogram("Most Recent BMI Values for Males", "last BMI", "number of patients", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); XYPlot plot = chart.getXYPlot(); final XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); /* creating a shadow */ renderer.setShadowXOffset(4.0); renderer.setShadowYOffset(1.5); renderer.setShadowVisible(true); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); } break; } case "lastbmifemales": { Stats bmiFemalesStats = (Stats) session.getAttribute(SessionObjectUtility.LAST_BMI_FEMALES_DATA); HistogramDataset dataset = new HistogramDataset(); ArrayList<CategoricalValue> lastBmiFemalesValues = new ArrayList<>(); if ((bmiFemalesStats.getGroups() != null) && (!bmiFemalesStats.getGroups().isEmpty())) { for (int i = 0; i < bmiFemalesStats.getGroups().size(); i++) { if (bmiFemalesStats.getGroups().get(i) != null) { lastBmiFemalesValues.addAll(bmiFemalesStats.getGroups().get(i)); } } } if (lastBmiFemalesValues.size() > 0) { double[] vector = new double[lastBmiFemalesValues.size()]; for (int i = 0; i < vector.length; i++) { vector[i] = lastBmiFemalesValues.get(i).getValue().doubleValue(); } /* add the data */ dataset.addSeries("number of patients", vector, 15); /* remove reference */ session.setAttribute(SessionObjectUtility.LAST_BMI_FEMALES_DATA, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createHistogram("Most Recent BMI Values for Females", "last BMI", "number of patients", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); XYPlot plot = chart.getXYPlot(); final XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); /* creating a shadow */ renderer.setShadowXOffset(4.0); renderer.setShadowYOffset(1.5); renderer.setShadowVisible(true); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); } break; } case "lastbmimalesbyclassattendance": { final int topGroupIndex = 4; Stats bmiMalesStats = (Stats) session.getAttribute(SessionObjectUtility.LAST_BMI_MALES_BY_CLASS_DATA); DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); if (bmiMalesStats.getGroups() != null) { for (int i = 0; i < bmiMalesStats.getGroups().size(); i++) { if ((bmiMalesStats.getGroups().get(i) != null) && (!bmiMalesStats.getGroups().get(i).isEmpty())) { List values = new ArrayList(); for (CategoricalValue cv : bmiMalesStats.getGroups().get(i)) { values.add(cv.getValue()); } if (i == topGroupIndex) { dataset.add(BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values), "last BMI (males)", "5 or more"); } else { dataset.add(BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values), "last BMI (males)", i + 1); } } } } /* remove reference */ session.setAttribute(SessionObjectUtility.LAST_BMI_MALES_BY_CLASS_DATA, null); CategoryAxis domainAxis = new CategoryAxis("number of classes attended"); NumberAxis rangeAxis = new NumberAxis("last BMI (males)"); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart("Most Recent BMI for Males by Classes Attended", plot); renderer.setMeanVisible(false); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "lastbmifemalesbyclassattendance": { final int topGroupIndex = 4; Stats bmiFemalesStats = (Stats) session .getAttribute(SessionObjectUtility.LAST_BMI_FEMALES_BY_CLASS_DATA); DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); if (bmiFemalesStats.getGroups() != null) { for (int i = 0; i < bmiFemalesStats.getGroups().size(); i++) { if ((bmiFemalesStats.getGroups().get(i) != null) && (!bmiFemalesStats.getGroups().get(i).isEmpty())) { List values = new ArrayList(); for (CategoricalValue cv : bmiFemalesStats.getGroups().get(i)) { values.add(cv.getValue()); } if (i == topGroupIndex) { dataset.add(BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values), "last BMI (females)", "5 or more"); } else { dataset.add(BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values), "last BMI (females)", i + 1); } } } } /* remove reference */ session.setAttribute(SessionObjectUtility.LAST_BMI_FEMALES_BY_CLASS_DATA, null); CategoryAxis domainAxis = new CategoryAxis("number of classes attended"); NumberAxis rangeAxis = new NumberAxis("last BMI (females)"); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart("Most Recent BMI for Females by Classes Attended", plot); renderer.setMeanVisible(false); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "lasta1cbytreatment": { final int firstIndex = 0; Stats glycemicStats = (Stats) session.getAttribute(SessionObjectUtility.LAST_A1C_BY_TREATMENT); DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); if (glycemicStats.getGroups() != null) { for (int i = 0; i < glycemicStats.getGroups().size(); i++) { if ((glycemicStats.getGroups().get(i) != null) && (!glycemicStats.getGroups().get(i).isEmpty())) { String category = glycemicStats.getGroups().get(i).get(firstIndex) != null ? glycemicStats.getGroups().get(i).get(firstIndex).getCategory() : ""; List values = new ArrayList(); for (CategoricalValue cv : glycemicStats.getGroups().get(i)) { values.add(cv.getValue()); } dataset.add(BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values), "last A1C(%)", category); } } } /* remove reference */ session.setAttribute(SessionObjectUtility.LAST_A1C_BY_TREATMENT, null); CategoryAxis domainAxis = new CategoryAxis("treatment class"); NumberAxis rangeAxis = new NumberAxis("last A1C(%)"); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart("Most Recent A1C by Treatment Class", plot); renderer.setMeanVisible(false); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "treatmentclasscounts": { int treatmentClassCountsIndex = 1; Stats treatmentData = (Stats) session.getAttribute(SessionObjectUtility.CLASS_COUNTS_TREATMENT_STATS); DefaultPieDataset dataset = new DefaultPieDataset(); /* add the treatment data to the dataset */ for (int i = 0; i < treatmentClassUnknownIndex + 1; i++) { dataset.setValue(treatmentData.getGroups().get(treatmentClassCountsIndex).get(i).getCategory(), treatmentData.getGroups().get(treatmentClassCountsIndex).get(i).getValue()); } /* remove reference */ session.setAttribute(SessionObjectUtility.CLASS_COUNTS_TREATMENT_STATS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; /* get the chart */ JFreeChart chart = ChartFactory.createPieChart3D("Treatment Class", dataset, legend, tooltips, urls); final PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(90); plot.setForegroundAlpha(0.60f); plot.setInteriorGap(0.02); PieSectionLabelGenerator labels = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot.setLabelGenerator(labels); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); break; } case "treatmentgenderclasscounts": { int maleClassCountsIndex = 2; int femaleClassCountsIndex = 3; Stats treatmentData = (Stats) session .getAttribute(SessionObjectUtility.GENDER_CLASS_COUNTS_TREATMENT_STATS); final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); HashMap<Integer, String> genderMap = new HashMap<>(); genderMap.put(maleClassCountsIndex, "Male"); genderMap.put(femaleClassCountsIndex, "Female"); /* load data for males and females into the dataset */ for (int i = femaleClassCountsIndex; i > maleClassCountsIndex - 1; i--) { for (int j = 0; j < treatmentClassUnknownIndex + 1; j++) { dataset.addValue(treatmentData.getGroups().get(i).get(j).getValue(), genderMap.get(i), treatmentData.getGroups().get(i).get(j).getCategory()); } } /* remove reference */ session.setAttribute(SessionObjectUtility.GENDER_CLASS_COUNTS_TREATMENT_STATS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; JFreeChart barChart = ChartFactory.createBarChart("Treatment Class by Gender", "Treatment Class", "Number of Patients", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); barChart.setBorderPaint(Color.GREEN); barChart.setBorderStroke(new BasicStroke(5.0f)); barChart.setBorderVisible(true); CategoryPlot plot = barChart.getCategoryPlot(); final BarRenderer renderer = (BarRenderer) plot.getRenderer(); /* creating a shadow */ renderer.setShadowXOffset(4.0); renderer.setShadowYOffset(1.5); renderer.setShadowVisible(true); ChartUtilities.writeChartAsPNG(outputStream, barChart, width, height); break; } case "treatmentraceclasscounts": { int whiteClassCountsIndex = 4; int africanAmericanClassCountsIndex = 5; int asianPacificIslanderClassCountsIndex = 6; int americanIndianAlaskaNativeClassCountsIndex = 7; int hispanicClassCountsIndex = 8; int middleEasternClassCountsIndex = 9; int otherClassCountsIndex = 10; Stats treatmentData = (Stats) session .getAttribute(SessionObjectUtility.RACE_CLASS_COUNTS_TREATMENT_STATS); final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); HashMap<Integer, String> raceMap = new HashMap<>(); raceMap.put(whiteClassCountsIndex, "White"); raceMap.put(africanAmericanClassCountsIndex, "African American"); raceMap.put(asianPacificIslanderClassCountsIndex, "Asian/Pacific Islander"); raceMap.put(americanIndianAlaskaNativeClassCountsIndex, "American Indian/Alaska Native"); raceMap.put(hispanicClassCountsIndex, "Hispanic"); raceMap.put(middleEasternClassCountsIndex, "Middle Eastern"); raceMap.put(otherClassCountsIndex, "Other"); /* load data for each race into the dataset */ for (int i = whiteClassCountsIndex; i < otherClassCountsIndex + 1; i++) { for (int j = 0; j < treatmentClassUnknownIndex + 1; j++) { dataset.addValue(treatmentData.getGroups().get(i).get(j).getValue(), raceMap.get(i), treatmentData.getGroups().get(i).get(j).getCategory()); } } /* remove reference */ session.setAttribute(SessionObjectUtility.RACE_CLASS_COUNTS_TREATMENT_STATS, null); boolean legend = true; boolean tooltips = false; boolean urls = false; JFreeChart barChart = ChartFactory.createStackedBarChart("Treatment Class by Race", "Treatment Class", "Number of Patients", dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); barChart.setBorderPaint(Color.GREEN); barChart.setBorderStroke(new BasicStroke(5.0f)); barChart.setBorderVisible(true); CategoryPlot plot = barChart.getCategoryPlot(); final BarRenderer renderer = (BarRenderer) plot.getRenderer(); /* creating a shadow */ renderer.setShadowXOffset(4.0); renderer.setShadowYOffset(1.5); renderer.setShadowVisible(true); ChartUtilities.writeChartAsPNG(outputStream, barChart, width, height); break; } default: break; } }
From source file:org.forester.archaeopteryx.TreePanel.java
private static JFreeChart createChart(CategoryDataset dataset, String branch_name) { // create the chart JFreeChart chart = ChartFactory.createBarChart("RAxML Weights Histogram " + branch_name, // chart title "RAxML Weights", // domain axis label "Placements", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? );// w ww. j av a2s . c o m // set the background color for the chart and title colors & font chart.setBackgroundPaint(Color.black); chart.setTextAntiAlias(true); chart.setBorderPaint(Color.green); chart.getTitle().setPaint(Color.white); chart.getTitle().setFont(chart.getTitle().getFont().deriveFont(12.0f)); // get a reference to the plot for further customisation CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(0.7f); plot.setBackgroundPaint(Color.black); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only, set colors & font final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelPaint(Color.white); rangeAxis.setLabelFont(rangeAxis.getLabelFont().deriveFont(10.0f)); rangeAxis.setAxisLinePaint(new Color(226, 236, 243)); rangeAxis.setTickLabelFont(rangeAxis.getTickLabelFont().deriveFont(8.0f)); rangeAxis.setTickLabelPaint(Color.white); // Custom renderer to display each bar in another color final BarRenderer renderer = new CustomRenderer(new Paint[] { new Color(255, 0, 0), new Color(227, 28, 0), new Color(199, 56, 0), new Color(171, 84, 0), new Color(143, 112, 0), new Color(115, 140, 0), new Color(87, 168, 0), new Color(59, 196, 0), new Color(31, 224, 0), new Color(0, 255, 0) }); // shadow effect off renderer.setShadowVisible(false); //make custom renderer the new renderer for the barchart plot.setRenderer(renderer); // set x axis label rotation, font and color CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4)); domainAxis.setLabelPaint(Color.white); domainAxis.setLabelFont(domainAxis.getLabelFont().deriveFont(10.0f)); domainAxis.setTickLabelPaint(Color.white); domainAxis.setTickLabelFont(domainAxis.getTickLabelFont().deriveFont(8.0f)); domainAxis.setAxisLinePaint(new Color(226, 236, 243)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:com.afunms.system.manage.equipManager.java
/** * Creates a chart.//from w w w . j a v a 2s . c o m * * @param dataset * the dataset. * * @return The chart. */ private JFreeChart _createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart3D("IP", // chart // title "IP", // domain axis label "", // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation true, // include legend true, // tooltips false // urls ); final CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(1.0f); // left align the category labels... final CategoryAxis axis = plot.getDomainAxis(); final CategoryLabelPositions p = axis.getCategoryLabelPositions(); final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f); axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left)); return chart; }
From source file:skoa.helpers.Graficos.java
private void barrasDual2() { unificarDatosFicheros();// ww w.j av a 2 s .com Vector<String> vectorOrdenUnidades = new Vector<String>(); vectorOrdenUnidades = ordenDeUnidades(); aplicarDiferencia(vectorOrdenUnidades); //En este caso, que queremos 2 ejes, MARCAMOS LA DIFERENCIA AL RECOGER EL 2 DATASET. CategoryDataset dataset = obtenerSerieBarrasDual(1); //String unidad=vectorOrdenUnidades.elementAt(0); String unidad; if (vectorOrdenUnidades.elementAt(0).indexOf("W") >= 0 || vectorOrdenUnidades.elementAt(0).indexOf("L") >= 0 || vectorOrdenUnidades.elementAt(0).indexOf("m") >= 0 || vectorOrdenUnidades.elementAt(0).indexOf("B") >= 0) unidad = vectorOrdenUnidades.elementAt(0); else if (vectorOrdenUnidades.elementAt(0).indexOf("C") >= 0) unidad = "C"; else unidad = ""; final CategoryAxis domainAxis = new CategoryAxis("Fechas"); final NumberAxis rangeAxis = new NumberAxis("Mediciones (" + unidad + ")"); final BarRenderer renderer1 = new BarRenderer(); final CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer1) { private static final long serialVersionUID = 1L; //ESPECIAL. Modificamos la leyenda, para que se vea correcta, cogiendo los 2 items deseados. public LegendItemCollection getLegendItems() { final LegendItemCollection result = new LegendItemCollection(); final CategoryDataset data = getDataset(); if (data != null) { final CategoryItemRenderer r = getRenderer(); if (r != null) { final LegendItem item; try { //Se recoge la excepcion en caso de haber solo item = r.getLegendItem(0, 0); //una lnea en el fichero unificado, porque } catch (Exception e) { //no habria nada en diferenciaAplicada. System.out.println("MAL " + e); return null; } result.add(item); } } final CategoryDataset dset2 = getDataset(1); if (dset2 != null) { final CategoryItemRenderer renderer2 = getRenderer(1); if (renderer2 != null) { final LegendItem item = renderer2.getLegendItem(1, 1); result.add(item); } } return result; } }; final JFreeChart grafica = new JFreeChart("Valores medidos de las direcciones de grupo", plot); plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF)); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryDataset dataset2 = obtenerSerieBarrasDual(2); //unidad=vectorOrdenUnidades.elementAt(1); if (vectorOrdenUnidades.elementAt(1).indexOf("W") >= 0 || vectorOrdenUnidades.elementAt(1).indexOf("L") >= 0 || vectorOrdenUnidades.elementAt(1).indexOf("m") >= 0 || vectorOrdenUnidades.elementAt(1).indexOf("B") >= 0) unidad = vectorOrdenUnidades.elementAt(1); else if (vectorOrdenUnidades.elementAt(1).indexOf("C") >= 0) unidad = "C"; else unidad = ""; plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); final ValueAxis axis2 = new NumberAxis("Mediciones (" + unidad + ")"); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); final BarRenderer renderer2 = new BarRenderer(); renderer2.setShadowVisible(false); //Esconder las sombras de la barra 1. plot.setRenderer(1, renderer2); BarRenderer renderer = new BarRenderer(); renderer.setShadowVisible(false); //Esconder las sombras de la barra 2. plot.setRenderer(0, renderer); plot.setRangeGridlinePaint(Color.BLACK); //Color de las lineas divisorias. //Subttulos if (fechaInicial.isEmpty()) { fechaInicial = fechaFinal = "?"; } TextTitle t = new TextTitle("desde " + fechaInicial + " hasta " + fechaFinal, new Font("SanSerif", Font.ITALIC, 12)); grafica.addSubtitle(t); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); domainAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 8)); //Letra de las fechas ms pequea grafica.setBackgroundPaint(Color.white); //------------------------------------------------- //Guarda la imagen: BufferedImage i1 = grafica.createBufferedImage(400, 300); BufferedImage i2 = grafica.createBufferedImage(900, 600); BufferedImage imag1 = convertirTipo(i1, BufferedImage.TYPE_INT_RGB);//!OBLIGATORIO!Para que al guardar la imagen, BufferedImage imag2 = convertirTipo(i2, BufferedImage.TYPE_INT_RGB);//no se vea transparente naranja. try { ImageIO.write(imag1, "jpg", new File(ruta + "BarrasSmall.jpg")); ImageIO.write(imag2, "jpg", new File(ruta + "BarrasBig.jpg")); } catch (IOException e) { System.out.println("Error de escritura"); } }
From source file:app.RunApp.java
/** * Create Chart//from w w w . ja va2 s . c om * * @param jpanel Panel * @param type Chart type * @param titleX Title for X axis * @param titleY Title for Y axis * @param showXAxis Indicates if shows X axis * @param chartTitle Chart title * @return ChartPanel with the generated chart */ private ChartPanel createJChart(JPanel jpanel, String type, String titleX, String titleY, boolean showXAxis, String chartTitle) { DefaultCategoryDataset myData = new DefaultCategoryDataset(); JFreeChart chart1; CategoryPlot plot1; LineAndShapeRenderer lineandshaperenderer; //hide horizontal axis switch (type) { case "bar": chart1 = ChartFactory.createBarChart(chartTitle, titleY, titleX, myData, PlotOrientation.VERTICAL, false, true, false); plot1 = chart1.getCategoryPlot(); //Custom tooltips BarRenderer renderer = (BarRenderer) plot1.getRenderer(); switch (chartTitle.toLowerCase()) { case "label frequency": renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance())); break; case "labelset frequency": renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance())); break; case "labels histogram": renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator( "Instances with {1} labels = {2}", NumberFormat.getInstance())); break; case "ir inter class": renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance())); break; case "ir intra class": renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance())); break; case "ir per labelset": renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("ID: {0} = {2}", NumberFormat.getInstance())); break; default: renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); break; } plot1.setBackgroundAlpha(0); plot1.setRangeGridlinePaint(Color.black); break; case "line_2_axis": chart1 = ChartFactory.createLineChart(" ", titleX, titleY, myData, PlotOrientation.VERTICAL, false, true, false); plot1 = chart1.getCategoryPlot(); plot1.setRangeGridlinePaint(Color.black); //show little rectangles lineandshaperenderer = (LineAndShapeRenderer) plot1.getRenderer(); lineandshaperenderer.setBaseShapesVisible(true); CategoryAxis domainAxis = plot1.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); ValueAxis axis2 = new NumberAxis("# Labels"); plot1.setRangeAxis(1, axis2); plot1.mapDatasetToRangeAxis(1, 1); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); plot1.setRenderer(1, renderer2); break; default: //type == "line") chart1 = ChartFactory.createLineChart(" ", titleX, titleY, myData, PlotOrientation.VERTICAL, false, true, false); plot1 = chart1.getCategoryPlot(); plot1.setRangeGridlinePaint(Color.black); //show little rectangles lineandshaperenderer = (LineAndShapeRenderer) plot1.getRenderer(); lineandshaperenderer.setBaseShapesVisible(true); break; } //Hide X axis plot1.getDomainAxis().setTickLabelsVisible(showXAxis); ChartPanel cp1 = new ChartPanel(chart1); cp1.setSize(new Dimension(450, 300)); cp1.setBounds(260, 100, 450, 300); cp1.setPreferredSize(new Dimension(450, 300)); cp1.repaint(); jpanel.setBounds(260, 100, 450, 300); jpanel.setLayout(new BorderLayout()); jpanel.add(cp1, BorderLayout.CENTER); jpanel.repaint(); jpanel.validate(); return cp1; }