List of usage examples for org.jfree.chart ChartUtilities writeChartAsPNG
public static void writeChartAsPNG(OutputStream out, JFreeChart chart, int width, int height, ChartRenderingInfo info) throws IOException
From source file:org.n52.server.io.EESGenerator.java
public void createChartToOutputStream(DesignOptions options, ChartRenderingInfo renderingInfo, OutputStream outputStream) { try {//from ww w.ja va 2 s.co m Map<String, OXFFeatureCollection> entireCollMap = getFeatureCollectionFor(options, true); JFreeChart chart = producePresentation(entireCollMap, options); chart.removeLegend(); int width = options.getWidth(); int height = options.getHeight(); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height, renderingInfo); } catch (Exception e) { LOGGER.warn("Error while rendering chart.", e); } }
From source file:net.sf.jsfcomp.chartcreator.renderkit.ChartRenderer.java
private void writeImageMap(FacesContext context, UIChart uichart) { ResponseWriter writer = context.getResponseWriter(); ExternalContext externalContext = context.getExternalContext(); Map sessionMap = externalContext.getSessionMap(); String clientId = uichart.getClientId(context); ChartData data = (ChartData) sessionMap.get(clientId); JFreeChart chart = ChartUtils.createChartWithType(data); ChartUtils.setGeneralChartProperties(chart, data); ChartRenderingInfo chartRenderingInfo = new ChartRenderingInfo(); try {// w w w . ja v a2s . co m ByteArrayOutputStream out = new ByteArrayOutputStream(); if (data.getOutput().equalsIgnoreCase("png")) ChartUtilities.writeChartAsPNG(out, chart, data.getWidth(), data.getHeight(), chartRenderingInfo); else if (data.getOutput().equalsIgnoreCase("jpeg")) ChartUtilities.writeChartAsJPEG(out, chart, data.getWidth(), data.getHeight(), chartRenderingInfo); renderImageMapSupport(context, uichart, chartRenderingInfo); writer.write(ChartUtilities.getImageMap(uichart.getGenerateMap(), chartRenderingInfo, new StandardToolTipTagFragmentGenerator(), new URLTagFragmentGenerator(uichart.getId()))); } catch (IOException error) { error.printStackTrace(); } }
From source file:action.GraphAction.java
public String drawgraph() { List<CustomerOrder> orderList = new ArrayList<CustomerOrder>(); HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(); TransactionDao transactionDao = new TransactionDao(); // orderList = transactionDao.findByDate(fromdate, todate); orderList = (List<CustomerOrder>) request.getSession().getAttribute("orderList"); int a = orderList.size(); System.out.println("Size--->" + a); Number[] values = getValues(orderList); System.out.println("final values are " + Arrays.toString(values)); final Number[][] data = new Number[][] { values, {} }; final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("", "", data); JFreeChart chart = null;/* www. j ava2 s . c om*/ BarRenderer renderer3D = null; CategoryPlot plot = null; final CategoryAxis3D categoryAxis = new CategoryAxis3D("Month"); final ValueAxis valueAxis = new NumberAxis3D("Number of Transactions"); renderer3D = new BarRenderer3D(); plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer3D); plot.setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart("Online Transactions", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(new Color(152, 169, 236)); try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("D:\\3dbarchart.png"); OutputStream out = ServletActionContext.getResponse().getOutputStream(); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); ChartUtilities.writeChartAsPNG(out, chart, 600, 400, info); out.close(); //returnString = "success"; } catch (Exception e) { System.out.println(e); // returnString = "error"; } return SUCCESS; }
From source file:gov.nih.nci.ispy.web.taglib.CorrScatterPlotTag.java
public int doStartTag() { chart = null;/*w ww .j av a 2 s . c om*/ plotPoints.clear(); ServletRequest request = pageContext.getRequest(); HttpSession session = pageContext.getSession(); Object o = request.getAttribute(beanName); JspWriter out = pageContext.getOut(); ServletResponse response = pageContext.getResponse(); try { //retrieve the Finding from cache and build the list of PCAData points ISPYCorrelationFinding corrFinding = (ISPYCorrelationFinding) businessTierCache .getSessionFinding(session.getId(), taskId); Collection<ClinicalFactorType> clinicalFactors = new ArrayList<ClinicalFactorType>(); List<String> sampleIds = new ArrayList<String>(); List<DataPoint> points = corrFinding.getDataPoints(); ClinicalDataService cqs = ClinicalDataServiceFactory.getInstance(); IdMapperFileBasedService idMapper = IdMapperFileBasedService.getInstance(); List<ISPYPlotPoint> plotPoints = new ArrayList<ISPYPlotPoint>(); ISPYPlotPoint pp; SampleInfo si; ISPYclinicalDataQueryDTO dto; Set<String> sampleHolder = new HashSet<String>(); //set just holds one entry need this for the dto Set<PatientData> dataHolder = new HashSet<PatientData>(); PatientData pd = null; for (DataPoint p : points) { pp = new ISPYPlotPoint(p.getId()); pp.setX(p.getX()); pp.setY(p.getY()); pp.setZ(p.getZ()); String patientId = null; if (corrFinding.isSampleBased()) { si = idMapper.getSampleInfoForLabtrackId(p.getId()); if (si != null) { pp.setSampleInfo(si); patientId = si.getISPYId(); } else { logger.warn("Could not get sample info for DataPoint=" + p.getId()); } } else if (corrFinding.isPatientBased()) { patientId = p.getId(); } if (patientId != null) { dto = new ISPYclinicalDataQueryDTO(); sampleHolder.clear(); sampleHolder.add(patientId); dto.setRestrainingSamples(sampleHolder); dataHolder.clear(); dataHolder = cqs.getClinicalData(dto); if (dataHolder.size() == 1) { Iterator i = dataHolder.iterator(); pd = (PatientData) i.next(); pp.setPatientData(pd); } else { logger.error("Internal Error. Did not get back correct patient data for patientId=" + patientId); } } plotPoints.add(pp); } ISPYCorrelationScatterPlot plot = new ISPYCorrelationScatterPlot(plotPoints, corrFinding.getGroup1Name(), corrFinding.getGroup2Name(), corrFinding.getContinuousType1(), corrFinding.getContinuousType2(), corrFinding.getCorrelationValue(), ColorByType.valueOf(ColorByType.class, colorBy.toUpperCase())); chart = plot.getChart(); ISPYImageFileHandler imageHandler = new ISPYImageFileHandler(session.getId(), "png", 650, 600); //The final complete path to be used by the webapplication String finalPath = imageHandler.getSessionTempFolder(); String finalURLpath = imageHandler.getFinalURLPath(); /* * Create the actual charts, writing it to the session temp folder */ ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); String mapName = imageHandler.createUniqueMapName(); //PrintWriter writer = new PrintWriter(new FileWriter(mapName)); ChartUtilities.writeChartAsPNG(new FileOutputStream(finalPath), chart, 650, 600, info); //ImageMapUtil.writeBoundingRectImageMap(writer,"PCAimageMap",info,true); //writer.close(); /* This is here to put the thread into a loop while it waits for the * image to be available. It has an unsophisticated timer but at * least it is something to avoid an endless loop. **/ boolean imageReady = false; int timeout = 1000; FileInputStream inputStream = null; while (!imageReady) { timeout--; try { inputStream = new FileInputStream(finalPath); inputStream.available(); imageReady = true; inputStream.close(); } catch (IOException ioe) { imageReady = false; if (inputStream != null) { inputStream.close(); } } if (timeout <= 1) { break; } } out.print(ImageMapUtil.getBoundingRectImageMapTag(mapName, true, info)); finalURLpath = finalURLpath.replace("\\", "/"); long randomness = System.currentTimeMillis(); //prevent image caching out.print("<img id=\"geneChart\" name=\"geneChart\" src=\"" + finalURLpath + "?" + randomness + "\" usemap=\"#" + mapName + "\" border=\"0\" />"); //(imageHandler.getImageTag(mapFileName)); } catch (IOException e) { logger.error(e); } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); logger.error(sw.toString()); } catch (Throwable t) { logger.error(t); } return EVAL_BODY_INCLUDE; }
From source file:nl.ctmm.trait.proteomics.qcviewer.utils.ReportPDFExporter.java
/** * Create image of the TIC Chart./*from ww w . j ava 2 s .co m*/ * * @param reportUnit Report unit for which to create TIC chart image. * @return TIC Chart image. */ private static Image createTICChartImage(final ReportUnit reportUnit) { /*Reference: http://vangjee.wordpress.com/2010/11/03/how-to-use-and-not-use-itext-and-jfreechart/ * Apache License, Version 2.0 */ JFreeChart ticChart = null; try { ticChart = (JFreeChart) reportUnit.getChartUnit().getTicChart().clone(); } catch (final CloneNotSupportedException e) { logger.log(Level.SEVERE, String.format(CLONE_EXCEPTION_MESSAGE, reportUnit.getMsrunName()), e); } final String titleString = String.format(TIC_GRAPH_TITLE, reportUnit.getMsrunName(), reportUnit.getChartUnit().getMaxTicIntensityString()); final TextTitle newTitle = new TextTitle(titleString, Constants.PDF_CHART_TITLE_FONT); newTitle.setPaint(Color.red); if (ticChart != null) { ticChart.setTitle(newTitle); } Image chartImage = null; try { final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); if (ticChart != null) { ChartUtilities.writeChartAsPNG(byteArrayOutputStream, ticChart, CHART_IMAGE_WIDTH, CHART_IMAGE_HEIGHT, new ChartRenderingInfo()); } chartImage = Image.getInstance(byteArrayOutputStream.toByteArray()); byteArrayOutputStream.close(); } catch (final BadElementException | IOException e) { // TODO Explain when these exception can occur. /* * IOException occurs in case PDF file can not be created. * e.g. PDF file with same name exist in the PDF directory and it is open. * In this case, the PDF file can not be overwritten. * BadElementException Signals an attempt to create an Element that hasn't got the right form. */ logger.log(Level.SEVERE, PDF_EXPORT_EXCEPTION_MESSAGE, e); } if (chartImage != null) { chartImage.setAlignment(Element.ALIGN_CENTER); } return chartImage; }
From source file:gov.nih.nci.ispy.web.taglib.PCAPlotTag.java
public int doStartTag() { chart = null;//from w ww . j av a2 s. com pcaResults = null; pcaData.clear(); ServletRequest request = pageContext.getRequest(); HttpSession session = pageContext.getSession(); Object o = request.getAttribute(beanName); JspWriter out = pageContext.getOut(); ServletResponse response = pageContext.getResponse(); try { //retrieve the Finding from cache and build the list of PCAData points PrincipalComponentAnalysisFinding principalComponentAnalysisFinding = (PrincipalComponentAnalysisFinding) businessTierCache .getSessionFinding(session.getId(), taskId); Collection<ClinicalFactorType> clinicalFactors = new ArrayList<ClinicalFactorType>(); List<String> sampleIds = new ArrayList<String>(); Map<String, PCAresultEntry> pcaResultMap = new HashMap<String, PCAresultEntry>(); pcaResults = principalComponentAnalysisFinding.getResultEntries(); for (PCAresultEntry pcaEntry : pcaResults) { sampleIds.add(pcaEntry.getSampleId()); pcaResultMap.put(pcaEntry.getSampleId(), pcaEntry); } //Get the clinical data for the sampleIds ClinicalDataService cqs = ClinicalDataServiceFactory.getInstance(); IdMapperFileBasedService idMapper = IdMapperFileBasedService.getInstance(); //Map<String, ClinicalData> clinicalDataMap = cqs.getClinicalDataMapForLabtrackIds(sampleIds); PCAresultEntry entry; //ClinicalData clinData; //PatientData patientData; SampleInfo si; TimepointType timepoint; for (String id : sampleIds) { entry = pcaResultMap.get(id); ISPYPCADataPoint pcaPoint = new ISPYPCADataPoint(id, entry.getPc1(), entry.getPc2(), entry.getPc3()); si = idMapper.getSampleInfoForLabtrackId(id); //clinData = cqs.getClinicalDataForPatientDID(si.getRegistrantId(), si.getTimepoint()); //patientData = cqs.getPatientDataForPatientDID(si.getISPYId()); Set<String> ispyIds = new HashSet<String>(); ispyIds.add(si.getISPYId()); ISPYclinicalDataQueryDTO dto = new ISPYclinicalDataQueryDTO(); dto.setRestrainingSamples(ispyIds); Set<PatientData> pdSet = cqs.getClinicalData(dto); for (PatientData patientData : pdSet) { pcaPoint.setISPY_ID(si.getISPYId()); timepoint = si.getTimepoint(); pcaPoint.setTimepoint(timepoint); if (patientData != null) { pcaPoint.setClinicalStage(patientData.getClinicalStage()); int clinRespVal; Double mriPctChange = null; if (timepoint == TimepointType.T1) { pcaPoint.setClinicalResponse(ClinicalResponseType.NA); pcaPoint.setTumorMRIpctChange(null); } else if (timepoint == TimepointType.T2) { clinRespVal = PatientData.parseValue(patientData.getClinRespT1_T2()); //set the clinical respoinse to the T1_T2 pcaPoint.setClinicalResponse(ClinicalResponseType.getTypeForValue(clinRespVal)); pcaPoint.setTumorMRIpctChange(patientData.getMriPctChangeT1_T2()); } else if (timepoint == TimepointType.T3) { //set the clinical response to T1_T3 clinRespVal = PatientData.parseValue(patientData.getClinRespT1_T3()); pcaPoint.setClinicalResponse(ClinicalResponseType.getTypeForValue(clinRespVal)); pcaPoint.setTumorMRIpctChange(patientData.getMriPctChangeT1_T3()); } else if (timepoint == TimepointType.T4) { //set the clinical response to T1_T4 clinRespVal = PatientData.parseValue(patientData.getClinRespT1_T4()); pcaPoint.setClinicalResponse(ClinicalResponseType.getTypeForValue(clinRespVal)); pcaPoint.setTumorMRIpctChange(patientData.getMriPctChangeT1_T4()); } else { pcaPoint.setClinicalResponse(ClinicalResponseType.UNKNOWN); pcaPoint.setTumorMRIpctChange(null); } } pcaData.add(pcaPoint); } } //check the components to see which graph to get if (components.equalsIgnoreCase("PC1vsPC2")) { ISPYPrincipalComponentAnalysisPlot plot = new ISPYPrincipalComponentAnalysisPlot(pcaData, PCAcomponent.PC2, PCAcomponent.PC1, ColorByType.valueOf(ColorByType.class, colorBy.toUpperCase())); chart = plot.getChart(); } if (components.equalsIgnoreCase("PC1vsPC3")) { ISPYPrincipalComponentAnalysisPlot plot = new ISPYPrincipalComponentAnalysisPlot(pcaData, PCAcomponent.PC3, PCAcomponent.PC1, ColorByType.valueOf(ColorByType.class, colorBy.toUpperCase())); chart = plot.getChart(); } if (components.equalsIgnoreCase("PC2vsPC3")) { ISPYPrincipalComponentAnalysisPlot plot = new ISPYPrincipalComponentAnalysisPlot(pcaData, PCAcomponent.PC3, PCAcomponent.PC2, ColorByType.valueOf(ColorByType.class, colorBy.toUpperCase())); chart = plot.getChart(); } ISPYImageFileHandler imageHandler = new ISPYImageFileHandler(session.getId(), "png", 650, 600); //The final complete path to be used by the webapplication String finalPath = imageHandler.getSessionTempFolder(); String finalURLpath = imageHandler.getFinalURLPath(); /* * Create the actual charts, writing it to the session temp folder */ ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); String mapName = imageHandler.createUniqueMapName(); //PrintWriter writer = new PrintWriter(new FileWriter(mapName)); ChartUtilities.writeChartAsPNG(new FileOutputStream(finalPath), chart, 650, 600, info); //ImageMapUtil.writeBoundingRectImageMap(writer,"PCAimageMap",info,true); //writer.close(); /* This is here to put the thread into a loop while it waits for the * image to be available. It has an unsophisticated timer but at * least it is something to avoid an endless loop. **/ boolean imageReady = false; int timeout = 1000; FileInputStream inputStream = null; while (!imageReady) { timeout--; try { inputStream = new FileInputStream(finalPath); inputStream.available(); imageReady = true; inputStream.close(); } catch (IOException ioe) { imageReady = false; if (inputStream != null) { inputStream.close(); } } if (timeout <= 1) { break; } } out.print(ImageMapUtil.getBoundingRectImageMapTag(mapName, false, info)); finalURLpath = finalURLpath.replace("\\", "/"); long randomness = System.currentTimeMillis(); //prevent image caching out.print("<img id=\"geneChart\" name=\"geneChart\" src=\"" + finalURLpath + "?" + randomness + "\" usemap=\"#" + mapName + "\" border=\"0\" />"); //(imageHandler.getImageTag(mapFileName)); } catch (IOException e) { logger.error(e); } catch (Exception e) { logger.error(e); } catch (Throwable t) { logger.error(t); } return EVAL_BODY_INCLUDE; }
From source file:gov.nih.nci.rembrandt.web.taglib.PCAPlotTag.java
public int doStartTag() { chart = null;/* w w w . j av a2 s .c o m*/ pcaResults = null; pcaData.clear(); ServletRequest request = pageContext.getRequest(); HttpSession session = pageContext.getSession(); Object o = request.getAttribute(beanName); JspWriter out = pageContext.getOut(); ServletResponse response = pageContext.getResponse(); try { //retrieve the Finding from cache and build the list of PCAData points PrincipalComponentAnalysisFinding principalComponentAnalysisFinding = (PrincipalComponentAnalysisFinding) businessTierCache .getSessionFinding(session.getId(), taskId); Collection<ClinicalFactorType> clinicalFactors = new ArrayList<ClinicalFactorType>(); List<String> sampleIds = new ArrayList<String>(); Map<String, PCAresultEntry> pcaResultMap = new HashMap<String, PCAresultEntry>(); if (principalComponentAnalysisFinding != null) { pcaResults = principalComponentAnalysisFinding.getResultEntries(); for (PCAresultEntry pcaEntry : pcaResults) { sampleIds.add(pcaEntry.getSampleId()); pcaResultMap.put(pcaEntry.getSampleId(), pcaEntry); } Collection<SampleResultset> validatedSampleResultset = ClinicalDataValidator .getValidatedSampleResultsetsFromSampleIDs(sampleIds, clinicalFactors); if (validatedSampleResultset != null) { String id; PCAresultEntry entry; for (SampleResultset rs : validatedSampleResultset) { id = rs.getBiospecimen().getSpecimenName(); entry = pcaResultMap.get(id); PrincipalComponentAnalysisDataPoint pcaPoint = new PrincipalComponentAnalysisDataPoint(id, entry.getPc1(), entry.getPc2(), entry.getPc3()); String diseaseName = rs.getDisease().getValueObject(); if (diseaseName != null) { pcaPoint.setDiseaseName(diseaseName); } else { pcaPoint.setDiseaseName(DiseaseType.NON_TUMOR.name()); } GenderDE genderDE = rs.getGenderCode(); if (genderDE != null && genderDE.getValue() != null) { String gt = genderDE.getValueObject().trim(); if (gt != null) { GenderType genderType = GenderType.valueOf(gt); if (genderType != null) { pcaPoint.setGender(genderType); } } } Long survivalLength = rs.getSurvivalLength(); if (survivalLength != null) { //survival length is stored in days in the DB so divide by 30 to get the //approx survival in months double survivalInMonths = survivalLength.doubleValue() / 30.0; pcaPoint.setSurvivalInMonths(survivalInMonths); } pcaData.add(pcaPoint); } } PCAcomponent pone = PCAcomponent.PC1; PCAcomponent ptwo = PCAcomponent.PC2; //check the components to see which graph to get if (components.equalsIgnoreCase("PC1vsPC2")) { pone = PCAcomponent.PC2; ptwo = PCAcomponent.PC1; //chart = (JFreeChart) CaIntegratorChartFactory.getPrincipalComponentAnalysisGraph(pcaData,PCAcomponent.PC2,PCAcomponent.PC1,PCAcolorByType.valueOf(PCAcolorByType.class,colorBy)); } if (components.equalsIgnoreCase("PC1vsPC3")) { pone = PCAcomponent.PC3; ptwo = PCAcomponent.PC1; //chart = (JFreeChart) CaIntegratorChartFactory.getPrincipalComponentAnalysisGraph(pcaData,PCAcomponent.PC3,PCAcomponent.PC1,PCAcolorByType.valueOf(PCAcolorByType.class,colorBy)); } if (components.equalsIgnoreCase("PC2vsPC3")) { pone = PCAcomponent.PC2; ptwo = PCAcomponent.PC3; //chart = (JFreeChart) CaIntegratorChartFactory.getPrincipalComponentAnalysisGraph(pcaData,PCAcomponent.PC3,PCAcomponent.PC2,PCAcolorByType.valueOf(PCAcolorByType.class,colorBy)); } PrincipalComponentAnalysisPlot plot = new RBTPrincipalComponentAnalysisPlot(pcaData, pone, ptwo, PCAcolorByType.valueOf(PCAcolorByType.class, colorBy)); if (plot != null) { chart = (JFreeChart) plot.getChart(); } RembrandtImageFileHandler imageHandler = new RembrandtImageFileHandler(session.getId(), "png", 650, 600); //The final complete path to be used by the webapplication String finalPath = imageHandler.getSessionTempFolder(); String finalURLpath = imageHandler.getFinalURLPath(); /* * Create the actual charts, writing it to the session temp folder */ ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); String mapName = imageHandler.createUniqueMapName(); //PrintWriter writer = new PrintWriter(new FileWriter(mapName)); ChartUtilities.writeChartAsPNG(new FileOutputStream(finalPath), chart, 650, 600, info); //ImageMapUtil.writeBoundingRectImageMap(writer,"PCAimageMap",info,true); //writer.close(); /* This is here to put the thread into a loop while it waits for the * image to be available. It has an unsophisticated timer but at * least it is something to avoid an endless loop. **/ boolean imageReady = false; int timeout = 1000; FileInputStream inputStream = null; while (!imageReady) { timeout--; try { inputStream = new FileInputStream(finalPath); inputStream.available(); imageReady = true; inputStream.close(); } catch (IOException ioe) { imageReady = false; if (inputStream != null) { inputStream.close(); } } if (timeout <= 1) { break; } } out.print(ImageMapUtil.getBoundingRectImageMapTag(mapName, false, info)); finalURLpath = finalURLpath.replace("\\", "/"); long randomness = System.currentTimeMillis(); //prevent image caching out.print("<img id=\"geneChart\" name=\"geneChart\" alt=\"geneChart\" src=\"" + finalURLpath + "?" + randomness + "\" usemap=\"#" + mapName + "\" border=\"0\" />"); //(imageHandler.getImageTag(mapFileName)); } } catch (IOException e) { logger.error(e); } catch (Exception e) { logger.error(e); } catch (Throwable t) { logger.error(t); } return EVAL_BODY_INCLUDE; }
From source file:gov.nih.nci.rembrandt.web.taglib.ClinicalPlotTag.java
public int doStartTag() { chart = null;/* w w w . jav a 2 s . c o m*/ clinicalData.clear(); ServletRequest request = pageContext.getRequest(); HttpSession session = pageContext.getSession(); Object o = request.getAttribute(beanName); JspWriter out = pageContext.getOut(); ServletResponse response = pageContext.getResponse(); try { // //retrieve the Finding from cache and build the list of Clinical Data points //ClinicalFinding clinicalFinding = (ClinicalFinding)businessTierCache.getSessionFinding(session.getId(),taskId); ReportBean clincalReportBean = presentationTierCache.getReportBean(session.getId(), taskId); Resultant clinicalResultant = clincalReportBean.getResultant(); ResultsContainer resultsContainer = clinicalResultant.getResultsContainer(); SampleViewResultsContainer sampleViewContainer = null; if (resultsContainer instanceof DimensionalViewContainer) { DimensionalViewContainer dimensionalViewContainer = (DimensionalViewContainer) resultsContainer; sampleViewContainer = dimensionalViewContainer.getSampleViewResultsContainer(); } if (sampleViewContainer != null) { Collection<ClinicalFactorType> clinicalFactors = new ArrayList<ClinicalFactorType>(); clinicalFactors.add(ClinicalFactorType.AgeAtDx); //clinicalFactors.add(ClinicalFactorType.Survival); Collection<SampleResultset> samples = sampleViewContainer.getSampleResultsets(); if (samples != null) { int numDxvsKa = 0; int numDxvsSl = 0; for (SampleResultset rs : samples) { //String id = rs.getBiospecimen().getValueObject(); String id = rs.getSampleIDDE().getValueObject(); ClinicalDataPoint clinicalDataPoint = new ClinicalDataPoint(id); String diseaseName = rs.getDisease().getValueObject(); if (diseaseName != null) { clinicalDataPoint.setDiseaseName(diseaseName); } else { clinicalDataPoint.setDiseaseName(DiseaseType.NON_TUMOR.name()); } Long sl = rs.getSurvivalLength(); double survivalDays = -1.0; double survivalMonths = -1.0; if (sl != null) { survivalDays = sl.doubleValue(); survivalMonths = survivalDays / 30.0; //if ((survivalMonths > 0.0)&&(survivalMonths < 1000.0)) { clinicalDataPoint.setSurvival(survivalDays); //} } Long dxAge = rs.getAge(); if (dxAge != null) { clinicalDataPoint.setAgeAtDx(dxAge.doubleValue()); } KarnofskyClinicalEvalDE ka = rs.getKarnofskyClinicalEvalDE(); if (ka != null) { String kaStr = ka.getValueObject(); if (kaStr != null) { if (kaStr.contains("|")) { kaStr = kaStr.trim(); String[] kaStrArray = kaStr.split("\\|"); for (int i = 0; i < kaStrArray.length; i++) { if (i == 0) { //first score is baseline just use this for now //later we will need to use all score in a series for each patient double kaVal = Double.parseDouble(kaStrArray[i].trim()); clinicalDataPoint.setKarnofskyScore(kaVal); } } } else { double kaVal = Double.parseDouble(kaStr); clinicalDataPoint.setKarnofskyScore(kaVal); } } } if ((dxAge != null) && (ka != null)) { numDxvsKa++; } if ((dxAge != null) && (sl != null)) { numDxvsSl++; } // Object dx = rs.getAgeGroup(); // if(sl !=null && dx !=null){ // clinicalDataPoint.setSurvival(new Double(sl.toString())); // clinicalDataPoint.setAgeAtDx(new Double(dx.toString())); // } // Object ks = rs.getKarnofskyClinicalEvalDE(); // Object dx = rs.getAgeGroup(); // if(ks !=null && dx !=null){ // clinicalDataPoint.setNeurologicalAssessment(new Double(ks.toString())); // clinicalDataPoint.setAgeAtDx(new Double(dx.toString())); // } clinicalData.add(clinicalDataPoint); } } } System.out.println("Done creating points!"); //------------------------------------------------------------- //GET THE CLINICAL DATA AND POPULATE THE clinicalData list //Note the ClinicalFinding is currently an empty class //---------------------------------------------------------- //check the components to see which graph to get if (components.equalsIgnoreCase("SurvivalvsAgeAtDx")) { chart = (JFreeChart) CaIntegratorChartFactory.getClinicalGraph(clinicalData, ClinicalFactorType.SurvivalLength, "Survival Length (Months)", ClinicalFactorType.AgeAtDx, "Age At Diagnosis (Years)"); } if (components.equalsIgnoreCase("KarnofskyScorevsAgeAtDx")) { chart = (JFreeChart) CaIntegratorChartFactory.getClinicalGraph(clinicalData, ClinicalFactorType.KarnofskyAssessment, "Karnofsky Score", ClinicalFactorType.AgeAtDx, "Age At Diagnosis (Years)"); } RembrandtImageFileHandler imageHandler = new RembrandtImageFileHandler(session.getId(), "png", 600, 500); //The final complete path to be used by the webapplication String finalPath = imageHandler.getSessionTempFolder(); String finalURLpath = imageHandler.getFinalURLPath(); /* * Create the actual charts, writing it to the session temp folder */ ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); String mapName = imageHandler.createUniqueMapName(); ChartUtilities.writeChartAsPNG(new FileOutputStream(finalPath), chart, 600, 500, info); /* This is here to put the thread into a loop while it waits for the * image to be available. It has an unsophisticated timer but at * least it is something to avoid an endless loop. **/ boolean imageReady = false; int timeout = 1000; FileInputStream inputStream = null; while (!imageReady) { timeout--; try { inputStream = new FileInputStream(finalPath); inputStream.available(); imageReady = true; inputStream.close(); } catch (IOException ioe) { imageReady = false; if (inputStream != null) { inputStream.close(); } } if (timeout <= 1) { break; } } out.print(ImageMapUtil.getBoundingRectImageMapTag(mapName, false, info)); //finalURLpath = finalURLpath.replace("\\", "/"); finalURLpath = finalURLpath.replace("\\", "/"); long randomness = System.currentTimeMillis(); //prevent image caching out.print("<img id=\"geneChart\" alt=\"geneChart\" name=\"geneChart\" src=\"" + finalURLpath + "?" + randomness + "\" usemap=\"#" + mapName + "\" border=\"0\" />"); //out.print("<img id=\"geneChart\" name=\"geneChart\" src=\""+finalURLpath+"\" usemap=\"#"+mapName + "\" border=\"0\" />"); } catch (IOException e) { logger.error(e); } catch (Exception e) { logger.error(e); } catch (Throwable t) { logger.error(t); } return EVAL_BODY_INCLUDE; }
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
private byte[] generateChart(JFreeChart chart, byte _format, int width, int height, ChartRenderingInfo info) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); if (_format == FORMAT_JPG) ChartUtilities.writeChartAsJPEG(out, chart, width, height, info); else//w ww . java 2 s . co m ChartUtilities.writeChartAsPNG(out, chart, width, height, info); out.close(); return out.toByteArray(); }