List of usage examples for org.jfree.chart.axis CategoryLabelPositions UP_45
CategoryLabelPositions UP_45
To view the source code for org.jfree.chart.axis CategoryLabelPositions UP_45.
Click Source Link
From source file:j2se.jfreechart.barchart.BarChartDemo7.java
/** * Creates a sample chart.//from w w w . j ava 2 s.c o m * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 7", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final IntervalMarker target = new IntervalMarker(4.5, 7.5); target.setLabel("Target Range"); target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11)); target.setLabelAnchor(RectangleAnchor.LEFT); target.setLabelTextAnchor(TextAnchor.CENTER_LEFT); target.setPaint(new Color(222, 222, 255, 128)); plot.addRangeMarker(target, Layer.BACKGROUND); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setItemMargin(0.10); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); // renderer.setLabelGenerator(new BarChartDemo7.LabelGenerator()); renderer.setItemLabelsVisible(true); final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0); renderer.setPositiveItemLabelPosition(p); final ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0); renderer.setPositiveItemLabelPositionFallback(p2); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:forms.frDados.java
/** * Inicializa o grfico de velocidade.//from w ww.j a v a 2 s .com */ private void initSatVelox() { dadosGraficoVelox.clear(); veloxPlot = ChartFactory.createLineChart("Velocidade", "Hora", "Velocidade KM/h", dadosGraficoVelox, PlotOrientation.VERTICAL, false, true, false); veloxPlot.getTitle().setFont(Font.decode("arial-16")); veloxPlot.getTitle().setPadding(5, 20, 5, 20); veloxPlot.setPadding(new RectangleInsets(10, 10, 0, 10)); ChartPanel cp = new ChartPanel(veloxPlot); cp.setBorder(LineBorder.createGrayLineBorder()); LineAndShapeRenderer br = (LineAndShapeRenderer) veloxPlot.getCategoryPlot().getRenderer(); br.setBaseItemLabelsVisible(true); br.setSeriesItemLabelFont(0, Font.decode("arial-12")); br.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); br.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER)); veloxPlot.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); //veloxPlot.getCategoryPlot().getRangeAxis().setRange(new Range(0,100), true,true); pnlChartSpeed.setLayout(new BorderLayout()); pnlChartSpeed.add(cp, BorderLayout.CENTER); }
From source file:org.mars_sim.msp.ui.swing.demo.BarChartDemo7.java
/** * Creates a sample chart./*from w w w . j av a 2s . c o m*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 7", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final IntervalMarker target = new IntervalMarker(4.5, 7.5); target.setLabel("Target Range"); target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11)); target.setLabelAnchor(RectangleAnchor.LEFT); target.setLabelTextAnchor(TextAnchor.CENTER_LEFT); target.setPaint(new Color(222, 222, 255, 128)); plot.addRangeMarker(target, Layer.BACKGROUND); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); //renderer.setItemMargin(0.10); renderer.setMaximumBarWidth(.5); // set maximum width to 35% of chart // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); // renderer.setLabelGenerator(new BarChartDemo7.LabelGenerator()); renderer.setDefaultItemLabelsVisible(true); final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0); renderer.setDefaultPositiveItemLabelPosition(p); final ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0); renderer.setPositiveItemLabelPositionFallback(p2); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // OPTIONAL CUSTOMISATION COMPLETED. return 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 w w . j a va 2s . c o 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:vis2006.VisGrafik.java
public JFreeChart createChart(Stand st, int speciesCode) { // create the dataset... DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Durchmesserhufigkeiten in 5-cm-Klassen bestimmen (Klassenmitten: 7.5 bis max. 152.5) for (int i = 0; i < 30; i++) { for (int j = 0; j < 3; j++) { double anz = 0; double gesamtZahl = 0; for (int k = 0; k < st.ntrees; k++) { if (speciesCode == st.tr[k].code && st.tr[k].fac > 0.0) { if ((st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5)) gesamtZahl = gesamtZahl + st.tr[k].fac; if ((j == 2) && (st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5) && (st.tr[k].out < 0) && (st.tr[k].crop == true)) anz = anz + st.tr[k].fac; if ((j == 0) && (st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5) && (st.tr[k].out < 0) && (st.tr[k].crop == false)) anz = anz + st.tr[k].fac; if ((j == 1) && (st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5) && (st.tr[k].out > 0)) anz = anz + st.tr[k].fac; }//w w w . ja v a 2 s .co m } if (gesamtZahl > 0) { Integer m = (5 * i) + 2; String textcode = ""; if (j == 0) textcode = "verbleibend"; if (j == 1) textcode = "ausscheidend"; if (j == 2) textcode = "Z-Bume"; dataset.addValue(anz / st.size, // Anzahl pro ha textcode, // Gruppe m.toString() + ".5"); // Durchmesserklassenmitte } } } // JFreeChart chart = ChartFactory.createStackedBarChart(messages.getString("diameterDistribution"), // chart title messages.getString("dbhClass"), // domain axis label messages.getString("numberOfStems"), // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); CategoryPlot plot = chart.getCategoryPlot(); // plot.setBackgroundPaint(Color.lightGray); // plot.setDomainGridlinePaint(Color.white); // plot.setDomainGridlinesVisible(true); // plot.setRangeGridlinePaint(Color.white); // reenderer StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... renderer.setSeriesPaint(0, Color.GREEN); renderer.setSeriesPaint(1, Color.RED); renderer.setSeriesPaint(2, Color.BLUE); //renderer.setMaxBarWidth(0.15); renderer.setMaximumBarWidth(0.15); if (dataset.getColumnCount() > 10) { CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); if (dataset.getColumnCount() < 21) xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); else xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); } return chart; }
From source file:eu.cassandra.training.utils.ChartUtils.java
/** * This function is used for the visualization of two Area Diagrams. * /*w w w. j a va 2 s . co m*/ * @param title * The title of the chart. * @param x * The unit on the X axis of the chart. * @param y * The unit on the Y axis of the chart. * @param doubles * The array of values of the first array. * @param doubles2 * The array of values of the second array. * @return a chart panel with the graphical representation. */ public static ChartPanel createArea(String title, String x, String y, Double[] doubles, Double[] doubles2) { JFreeChart chart = null; if (doubles.length != doubles2.length) { System.out.println("ERROR with lengths."); } else { Double[][] data = new Double[2][doubles.length]; data[0] = doubles; data[1] = doubles2; final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Power ", "", data); chart = ChartFactory.createAreaChart(title, x, y, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(0.5f); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // domainAxis.setTickUnit(new NumberTickUnit(10)); NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } return new ChartPanel(chart); }
From source file:org.objectweb.proactive.benchmarks.timit.util.charts.BasicComparativeChartBuilder.java
/** * Creates a sample chart.//from w w w. ja va 2 s .c om * * @param dataset a dataset. * * @return The chart. */ private JFreeChart createChart() { // create the chart... final JFreeChart chart = ChartFactory.createBarChart(this.chartTitle, // chart title "", // x axis label DEFAULT_Y_AXIS_NAME, // y axis label this.dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); chart.addSubtitle(new TextTitle(this.subtitle + "Time used is : " + TIME_ATTRIBUTE_NAME)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.black); plot.getRangeAxis().setLabelAngle((0 * Math.PI) / 2.0); ((BarRenderer) plot.getRenderer()).setItemMargin(0); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:com.wicht.benchmark.utils.Benchs.java
/** * Generate the chart.//from ww w. ja va 2s .c o m * * @param title The title of the chart. * @param benchmarks The benchmarks to include in the chart. * @param sub A boolean tag indicating if we want to generate sub chart ({@code true}) or not ({@code * false}). * @param prefix The time prefix. */ private void generateChart(String title, Collection<NamedBenchmark> benchmarks, boolean sub, Prefix prefix) { String data = "Time (" + prefix.getSymbol() + "s)"; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (NamedBenchmark benchmark : benchmarks) { dataset.addValue(getExactMean(benchmark.getMean(), prefix), "", benchmark.getTitle()); } JFreeChart chart = ChartFactory.createBarChart(title.replace("-sub", ""), "Methods", data, dataset, PlotOrientation.VERTICAL, false, false, false); final CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setMaximumCategoryLabelLines(5); BufferedImage image = chart.createBufferedImage(width, height); try { ImageIO.write(image, "png", new File(folder + title + ".png")); } catch (IOException e) { e.printStackTrace(); } if (sub) { generateSubChart(title, benchmarks); } }
From source file:gg.view.categoriesbalances.GraphCategoriesBalancesTopComponent.java
/** * Displays the categories/sub-categories' balances by period * @param balances Categories' balances/* ww w .j a va 2 s .c o m*/ */ private void displayData(Map<Long, Map<SearchCriteria, BigDecimal>> balances) { log.info("Categories' balances graph computed and displayed"); // Display hourglass cursor Utilities.changeCursorWaitStatus(true); // Create the dataset (that will contain the categories/sub-categories' balances) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Create an empty chart JFreeChart chart = ChartFactory.createLineChart("", // chart title "", // x axis label NbBundle.getMessage(GraphCategoriesBalancesTopComponent.class, "GraphAccountsBalancesTopComponent.Amount"), // y axis label dataset, // data displayed in the chart PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // Chart color chart.setBackgroundPaint(jPanelCategoriesBalances.getBackground()); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); // Grid lines plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // Set the orientation of the categories on the domain axis (X axis) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Add the series on the chart for each category/sub-category displayed in the table for (Long categoryId : balances.keySet()) { Category category = Wallet.getInstance().getCategoriesWithId().get(categoryId); assert (category != null); SortedSet<SearchCriteria> sortedSearchCriteria = new TreeSet<SearchCriteria>( balances.get(categoryId).keySet()); for (SearchCriteria searchCriteria : sortedSearchCriteria) { if ((!searchCriteria.hasCategoriesFilter() && category.isTopCategory() && !category.getSystemProperty()) || searchCriteria.getCategories().contains(category)) { BigDecimal balance = new BigDecimal(0); if (balances.get(categoryId) != null && balances.get(categoryId).get(searchCriteria) != null) { balance = balances.get(categoryId).get(searchCriteria); } dataset.addValue(balance, category.getName(), searchCriteria.getPeriod()); } } } // Series' shapes LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F)); } // Set the scale of the chart NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create the chart panel that contains the chart ChartPanel chartPanel = new ChartPanel(chart); // Display the chart jPanelCategoriesBalances.removeAll(); jPanelCategoriesBalances.add(chartPanel, BorderLayout.CENTER); jPanelCategoriesBalances.updateUI(); // Display normal cursor Utilities.changeCursorWaitStatus(false); }
From source file:gg.view.accountsbalances.GraphAccountsBalancesTopComponent.java
/** * Displays the accounts' balances by period * @param balances Accounts' balances/*from w w w . j a v a2 s. c o m*/ */ private void displayData(Map<MoneyContainer, Map<SearchCriteria, BigDecimal>> balances) { log.info("Accounts' balances graph computed and displayed"); // Display hourglass cursor Utilities.changeCursorWaitStatus(true); // Create the dataset (that will contain the accounts' balances) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Create an empty chart JFreeChart chart = ChartFactory.createLineChart("", // chart title "", // x axis label NbBundle.getMessage(GraphAccountsBalancesTopComponent.class, "AccountsBalancesTopComponent.Amount"), // y axis label dataset, // data displayed in the chart PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // Chart color chart.setBackgroundPaint(jPanelAccountsBalances.getBackground()); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); // Grid lines plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // Set the orientation of the categories on the domain axis (X axis) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Add the series on the chart for each account displayed in the table for (MoneyContainer moneyContainer : balances.keySet()) { if (moneyContainer instanceof Account) { Account account = (Account) moneyContainer; SortedSet<SearchCriteria> sortedSearchCriteria = new TreeSet<SearchCriteria>( balances.get(account).keySet()); for (SearchCriteria searchCriteria : sortedSearchCriteria) { if (!searchCriteria.hasAccountsFilter() || searchCriteria.getAccounts().contains(account)) { dataset.addValue(balances.get(moneyContainer).get(searchCriteria), account.toString(), searchCriteria.getPeriod()); } } } } // Series' shapes LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F)); } // Set the scale of the chart NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create the chart panel that contains the chart ChartPanel chartPanel = new ChartPanel(chart); // Display the chart jPanelAccountsBalances.removeAll(); jPanelAccountsBalances.add(chartPanel, BorderLayout.CENTER); jPanelAccountsBalances.updateUI(); // Display normal cursor Utilities.changeCursorWaitStatus(false); }