List of usage examples for org.jfree.chart ChartRenderingInfo ChartRenderingInfo
public ChartRenderingInfo(EntityCollection entities)
From source file:gov.nih.nci.ispy.web.taglib.PCAPlotTag.java
public int doStartTag() { chart = null;/*from ww w . ja v a 2s. co 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>(); 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:org.signserver.client.cli.performance.PerformanceTestPDFServlet.java
License:asdf
/** * Create and write diagrams to disk.//from ww w. jav a 2s. co m */ private void createDiagram(String statisticsDirectory, ArrayList<String> explanationRow, ArrayList<ArrayList<Double>> processedData, int xRow, int y1Row, int y2Row) { final XYSeries s1 = new XYSeries(explanationRow.get(y1Row)); final XYSeries s2 = new XYSeries(explanationRow.get(y2Row)); for (ArrayList<Double> currentRow : processedData) { s1.add(currentRow.get(xRow), currentRow.get(y1Row)); s2.add(currentRow.get(xRow), currentRow.get(y2Row)); } final XYSeriesCollection dataset1 = new XYSeriesCollection(); dataset1.addSeries(s1); final XYSeriesCollection dataset2 = new XYSeriesCollection(); dataset2.addSeries(s2); final JFreeChart chart = ChartFactory.createXYLineChart("Test result " + xRow + "" + y1Row + "" + y2Row, explanationRow.get(xRow), explanationRow.get(y1Row), dataset1, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = chart.getXYPlot(); if (y1Row == COLUMN_INVOCATIONS_PER_SECOND) { final NumberAxis axis1 = new LogarithmicAxis(explanationRow.get(y1Row)); plot.setRangeAxis(0, axis1); } final NumberAxis axis2 = new NumberAxis(explanationRow.get(y2Row)); axis2.setAutoRangeIncludesZero(false); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, Color.BLUE); plot.setRenderer(1, renderer2); final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file = new File( statisticsDirectory + "PDF Signatures" + "-" + xRow + "" + y1Row + "" + y2Row + ".png"); int imageWidth = 800; int imageHeight = 600; try { System.out.println("Writing diagram to " + file.getName()); System.out.flush(); ChartUtilities.saveChartAsPNG(file, chart, imageWidth, imageHeight, info); } catch (IOException e) { e.printStackTrace(); } }
From source file:graph.plotter.PieMenu.java
/** * This is the main working button for this class... It creates pie chart analyZing whole data set * /*from www . j av a2 s . c om*/ * @param evt */ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed try { DefaultPieDataset pieDataset = new DefaultPieDataset(); /** Initializing pie dataset*/ int i; i = 0; String genre = "a"; if (Button == 1) { /** For User Input*/ while (i < cnt) { double aa = Double.parseDouble(Table.getModel().getValueAt(i, 1).toString()); String str = Table.getModel().getValueAt(i, 0).toString(); pieDataset.setValue(str, new Double(aa)); i++; genre += "a"; } } else { try { BufferedReader br = new BufferedReader(new FileReader(jTextField3.getText())); String Line; while ((Line = br.readLine()) != null) { String[] value = Line.split(","); double val = Double.parseDouble(value[1]); pieDataset.setValue(value[0], new Double(val)); // dataset.setValue(new Double(val),genre,value[0]); // genre+="a"; // (value[0]); } } catch (FileNotFoundException ex) { Logger.getLogger(PieMenu.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PieMenu.class.getName()).log(Level.SEVERE, null, ex); } } JFreeChart chart = ChartFactory.createPieChart("Pie Chart", pieDataset, true, true, true); PiePlot P = (PiePlot) chart.getPlot(); P.setLabelLinkPaint(Color.BLACK); P.setBackgroundPaint(Color.white); ChartFrame frame = new ChartFrame("PieChart", chart); jButto1 = new JButton("Save"); frame.setLayout(new BorderLayout()); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); gc.gridx = 1; gc.gridy = 0; panel.add(jButto1, gc); frame.add(panel, BorderLayout.SOUTH); jButto1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("Pie_Chart.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (Exception ex) { } } }); frame.setVisible(true); frame.setSize(858, 512); try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("Pie_Chart.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (Exception e) { } } catch (Exception ex) { } }
From source file:org.pentaho.platform.uifoundation.chart.DialChartComponent.java
@Override public Document getXmlContent() { // Create a document that describes the result Document result = DocumentHelper.createDocument(); IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$ PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$ String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$ Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ); if (chartDefinition == null) { Element errorElement = result.addElement("error"); //$NON-NLS-1$ errorElement.addElement("title").setText( //$NON-NLS-1$ Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$ definitionPath);//from w ww . j a v a 2 s .c o m errorElement.addElement("message").setText(message); //$NON-NLS-1$ error(message); return result; } dataDefinition = createChart(chartDefinition); if (dataDefinition == null) { Element errorElement = result.addElement("error"); //$NON-NLS-1$ errorElement.addElement("title").setText( //$NON-NLS-1$ Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ errorElement.addElement("message").setText(message); //$NON-NLS-1$ // System .out.println( result.asXML() ); return result; } // create an image for the dial using the JFreeChart engine PrintWriter printWriter = new PrintWriter(new StringWriter()); // we'll dispay the title in HTML so that the dial image does not have // to // accommodate it String chartTitle = ""; //$NON-NLS-1$ try { if (width == -1) { width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$ } if (height == -1) { height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$ } } catch (Exception e) { // go with the default } if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$ urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$ .getText(); } if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$ paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$ } Element root = result.addElement("charts"); //$NON-NLS-1$ DefaultValueDataset chartDataDefinition = (DefaultValueDataset) dataDefinition; // if (dataDefinition.getRowCount() > 0) { // create temporary file names String[] tempFileInfo = createTempFile(); String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX]; String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX]; ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$ JFreeChartEngine.OUTPUT_PNG, printWriter, info, this); applyOuterURLTemplateParam(); populateInfo(info); Element chartElement = root.addElement("chart"); //$NON-NLS-1$ chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$ chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$ chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$ // for (int row = 0; row < chartDataDefinition.getRowCount(); row++) { // for (int column = 0; column < chartDataDefinition.getColumnCount(); column++) { // Number value = chartDataDefinition.getValue(row, column); // Comparable rowKey = chartDataDefinition.getRowKey(row); // Comparable columnKey = chartDataDefinition.getColumnKey(column); // Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$ // valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$ // valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$ // valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$ // } // } String mapString = ImageMapUtilities.getImageMap(mapName, info); chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$ chartElement.addElement("image").setText(fileName); //$NON-NLS-1$ // } return result; }
From source file:org.gephi.statistics.plugin.DegreeDistribution.java
/** * * @return The directed version of the report. *//*from ww w . ja va 2 s . c om*/ private String getDirectedReport() { double inMax = 0; XYSeries inSeries2 = new XYSeries("Series 2"); for (int i = 1; i < inDistribution[1].length; i++) { if (inDistribution[1][i] > 0) { inSeries2.add((Math.log(inDistribution[0][i]) / Math.log(Math.E)), (Math.log(inDistribution[1][i]) / Math.log(Math.E))); inMax = (float) Math.max((Math.log(inDistribution[0][i]) / Math.log(Math.E)), inMax); } } double inA = inAlpha; double inB = inBeta; String inImageFile = ""; String outImageFile = ""; try { XYSeries inSeries1 = new XYSeries(inAlpha + " "); inSeries1.add(0, inA); inSeries1.add(inMax, inA + inB * inMax); XYSeriesCollection inDataset = new XYSeriesCollection(); inDataset.addSeries(inSeries1); inDataset.addSeries(inSeries2); JFreeChart inChart = ChartFactory.createXYLineChart("In-Degree Distribution", "In-Degree", "Occurrence", inDataset, PlotOrientation.VERTICAL, true, false, false); XYPlot inPlot = (XYPlot) inChart.getPlot(); XYLineAndShapeRenderer inRenderer = new XYLineAndShapeRenderer(); inRenderer.setSeriesLinesVisible(0, true); inRenderer.setSeriesShapesVisible(0, false); inRenderer.setSeriesLinesVisible(1, false); inRenderer.setSeriesShapesVisible(1, true); inRenderer.setSeriesShape(1, new java.awt.geom.Ellipse2D.Double(0, 0, 1, 1)); inPlot.setBackgroundPaint(java.awt.Color.WHITE); inPlot.setDomainGridlinePaint(java.awt.Color.GRAY); inPlot.setRangeGridlinePaint(java.awt.Color.GRAY); inPlot.setRenderer(inRenderer); final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); TempDir tempDir = TempDirUtils.createTempDir(); final String fileName = "inDistribution.png"; final File file1 = tempDir.createFile(fileName); inImageFile = "<IMG SRC=\"file:" + file1.getAbsolutePath() + "\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\"></IMG>"; ChartUtilities.saveChartAsPNG(file1, inChart, 600, 400, info); double outMax = 0; XYSeries outSeries2 = new XYSeries("Series 2"); for (int i = 1; i < outDistribution[1].length; i++) { if (outDistribution[1][i] > 0) { outSeries2.add((Math.log(outDistribution[0][i]) / Math.log(Math.E)), (Math.log(outDistribution[1][i]) / Math.log(Math.E))); outMax = (float) Math.max((Math.log(outDistribution[0][i]) / Math.log(Math.E)), outMax); } } double outA = outAlpha; double outB = outBeta; XYSeries outSeries1 = new XYSeries(outAlpha + " "); outSeries1.add(0, outA); outSeries1.add(outMax, outA + outB * outMax); XYSeriesCollection outDataset = new XYSeriesCollection(); outDataset.addSeries(outSeries1); outDataset.addSeries(outSeries2); JFreeChart outchart = ChartFactory.createXYLineChart("Out-Degree Distribution", "Out-Degree", "Occurrence", outDataset, PlotOrientation.VERTICAL, true, false, false); XYPlot outPlot = (XYPlot) outchart.getPlot(); XYLineAndShapeRenderer outRenderer = new XYLineAndShapeRenderer(); outRenderer.setSeriesLinesVisible(0, true); outRenderer.setSeriesShapesVisible(0, false); outRenderer.setSeriesLinesVisible(1, false); outRenderer.setSeriesShapesVisible(1, true); outRenderer.setSeriesShape(1, new java.awt.geom.Ellipse2D.Double(0, 0, 1, 1)); outPlot.setBackgroundPaint(java.awt.Color.WHITE); outPlot.setDomainGridlinePaint(java.awt.Color.GRAY); outPlot.setRangeGridlinePaint(java.awt.Color.GRAY); outPlot.setRenderer(outRenderer); final ChartRenderingInfo info2 = new ChartRenderingInfo(new StandardEntityCollection()); final String fileName2 = "outDistribution.png"; final File file2 = tempDir.createFile(fileName2); outImageFile = "<IMG SRC=\"file:" + file2.getAbsolutePath() + "\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\"></IMG>"; ChartUtilities.saveChartAsPNG(file2, outchart, 600, 400, info2); } catch (IOException e) { Exceptions.printStackTrace(e); } String report = "<HTML> <BODY> <h1>Degree Distribution Metric Report </h1> " + "<hr>" + "<br>" + "<h2> Parameters: </h2>" + "Network Interpretation: " + (isDirected ? "directed" : "undirected") + "<br>" + "<br> <h2> Results: </h2>" + "In-Degree Power Law: -" + inAlpha + "\n <BR>" + inImageFile + "<br>Out-Degree Power Law: -" + outAlpha + "\n <BR>" + outImageFile + "</BODY> </HTML>"; return report; }
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** * Return rendering information for the chart. */// w w w .java2s.c o m public static final ChartRenderingInfo getAverageTestCountRenderingInfo() { return new ChartRenderingInfo(new StandardEntityCollection()); }
From source file:graph.plotter.BarMenu.java
/** * This is the main working button for this class... It creates bar chart analyZing whole data set * /*w ww. j a va 2 s . c om*/ * @param evt */ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: try { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int i; i = 0; String genre = " "; if (Button == 1) while (i < count) { double amount = Double.parseDouble(Table.getModel().getValueAt(i, 1).toString()); String name = Table.getModel().getValueAt(i, 0).toString(); dataset.setValue(new Double(amount), genre, name); i++; genre += " "; } else { try { BufferedReader br = new BufferedReader(new FileReader(jTextField3.getText())); String Line; while ((Line = br.readLine()) != null) { String[] value = Line.split(","); double val = Double.parseDouble(value[1]); dataset.setValue(new Double(val), genre, value[0]); genre += " "; System.out.println(value[0]); } } catch (FileNotFoundException ex) { Logger.getLogger(BarMenu.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(BarMenu.class.getName()).log(Level.SEVERE, null, ex); } } JFreeChart chart = ChartFactory.createBarChart3D("Amount", "Name", "Amount", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.white); p.setBackgroundPaint(Color.black); ChartFrame frame = new ChartFrame("Bar Chart", chart); saveButton = new JButton("Save image in Project Folder"); frame.setLayout(new BorderLayout()); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); gc.gridx = 1; gc.gridy = 0; panel.add(saveButton, gc); frame.add(panel, BorderLayout.SOUTH); saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("Bar_Chart.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (Exception ex) { } } }); frame.setVisible(true); frame.setSize(858, 513); } catch (Exception e) { } }
From source file:Gui.admin.GererlesSratistique.java
private void StatistiquesBouttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StatistiquesBouttonActionPerformed int size = evaluationTable.getRowCount(); System.out.println(size);/*w ww . ja va2 s . c o m*/ List<Double> notes = new ArrayList<Double>(); List<Integer> ids = new ArrayList<Integer>(); for (int i = 0; i < size; i++) { notes.add((new Double(evaluationTable.getValueAt(i, 3).toString()))); ids.add((int) evaluationTable.getValueAt(i, 1)); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < size; i++) { dataset.setValue(new Double(notes.get(i)), "notes", new Double(ids.get(i))); } //dataset.setValue(evaluationTable); JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Id Adhrents", "Notes", dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.black); ChartFrame frame = new ChartFrame(" les notes des adhrents", chart); frame.setVisible(true); frame.setSize(450, 350); try { } catch (Exception e) { } /* String note =noteTxt.getText(); String idAdherent=idAdherentEvaluText.getText(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(new Double(note), "notes", new Double(idAdherent)); //dataset.setValue(evaluationTable); JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Id Adhrents", "Notes", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p= chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.black); ChartFrame frame = new ChartFrame(" les notes des adhrents", chart); frame.setVisible(true); frame.setSize(450,350); */ try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("statistiques.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (Exception e) { } }
From source file:gov.nih.nci.cma.web.graphing.GEPlot.java
public String generateBWLog2IntensityChart(String xAxisLabel, String yAxisLabel, HttpSession session, PrintWriter pw, boolean isCoinPlot) { String bwFilename = ""; //PlotSize ps = PlotSize.MEDIUM; JFreeChart bwChart = null;/* w w w. j a v a 2 s. c o m*/ try { //IMAGE Size Control CategoryAxis xAxis = new CategoryAxis(xAxisLabel); xAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(true); BoxAndWhiskerCoinPlotRenderer bwRenderer = null; CategoryPlot bwPlot = null; if (isCoinPlot) { Map<String, List<Double>> groupMap = rawDataMap.get(reporterName); DefaultBoxAndWhiskerCategoryDataset smallBwdataset = new DefaultBoxAndWhiskerCategoryDataset(); int row = 0; int column = 0; HashMap<String, List> caIntegatorCoinList = new HashMap<String, List>(); for (String group : groupList) { smallBwdataset.add(groupMap.get(group), reporterName, group); caIntegatorCoinList.put(row + "_" + column++, groupMap.get(group)); } bwRenderer = new BoxAndWhiskerCoinPlotRenderer(caIntegatorCoinList); bwRenderer.setDisplayAllOutliers(true); bwRenderer.setDisplayCoinCloud(true); bwRenderer.setDisplayMean(false); bwRenderer.setFillBox(false); bwRenderer.setPlotColor(null); bwPlot = new CategoryPlot(smallBwdataset, xAxis, yAxis, bwRenderer); if (groupList.size() < 6) imgW = 200; } else { bwRenderer = new BoxAndWhiskerCoinPlotRenderer(); bwRenderer.setDisplayAllOutliers(true); bwRenderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset dataset, int series, int item) { String tt = ""; NumberFormat formatter = new DecimalFormat(".####"); String key = ""; //String s = formatter.format(-1234.567); // -001235 if (dataset instanceof DefaultBoxAndWhiskerCategoryDataset) { DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset) dataset; try { String med = formatter.format(ds.getMedianValue(series, item)); tt += "Median: " + med + "<br/>"; tt += "Mean: " + formatter.format(ds.getMeanValue(series, item)) + "<br/>"; tt += "Q1: " + formatter.format(ds.getQ1Value(series, item)) + "<br/>"; tt += "Q3: " + formatter.format(ds.getQ3Value(series, item)) + "<br/>"; tt += "Max: " + formatter.format( FaroutOutlierBoxAndWhiskerCalculator.getMaxFaroutOutlier(ds, series, item)) + "<br/>"; tt += "Min: " + formatter.format( FaroutOutlierBoxAndWhiskerCalculator.getMinFaroutOutlier(ds, series, item)) + "<br/>"; tt += "<br/><br/>Please click on the box and whisker to view a plot for this reporter.<br/>"; key = ds.getRowKeys().get(series).toString(); } catch (Exception e) { } } String returnString = "onclick=\"popCoin('" + geneSymbol + "','" + key + "');\" | "; return returnString + tt; } }); bwRenderer.setFillBox(false); bwPlot = new CategoryPlot(bwdataset, xAxis, yAxis, bwRenderer); } bwChart = new JFreeChart(bwPlot); bwChart.setBackgroundPaint(java.awt.Color.white); LegendTitle title = bwChart.getLegend(); LegendItemSource[] sources = title.getSources(); legendItemCollection = sources[0].getLegendItems(); bwChart.removeLegend(); // Write the chart image to the temporary directory ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); // BW if (bwChart != null) { //int bwwidth = new BigDecimal(1.5).multiply(new BigDecimal(imgW)).intValue(); bwFilename = ServletUtilities.saveChartAsPNG(bwChart, imgW, 400, info, session); CustomOverlibToolTipTagFragmentGenerator ttip = new CustomOverlibToolTipTagFragmentGenerator(); ttip.setExtra(" href='javascript:void(0);' "); //must have href for area tags to have cursor:pointer ChartUtilities.writeImageMap(pw, bwFilename, info, ttip, new StandardURLTagFragmentGenerator()); info.clear(); // lose the first one info = new ChartRenderingInfo(new StandardEntityCollection()); } //END BW pw.flush(); } catch (Exception e) { System.out.println("Exception - " + e.toString()); e.printStackTrace(System.out); } // return filename; //charts.put("errorBars", log2Filename); //charts.put("noErrorBars", rawFilename); //charts.put("bwFilename", bwFilename); //charts.put("legend", legendHtml); //charts.put("size", ps.toString()); return bwFilename; }
From source file:org.squale.squaleweb.applicationlayer.action.results.ReviewAction.java
/** * Create the GraphMaker/* www . j a v a 2 s .c o m*/ * * @param pRequest The http request * @param result The list of results to display * @return an object GraphMaker * @throws IOException exception happen */ private GraphMaker componentGraph(HttpServletRequest pRequest, Object[] result) throws IOException { GraphMaker histoChart = null; if (((Map) result[1]).size() > 0) { HistoMaker histoMaker = new HistoMaker(); //Add the curve for the list of result histoMaker.addCurve((String) result[0], (Map) result[1]); JFreeChart chartKiviat = histoMaker.getChart(); ChartRenderingInfo infoHisto = new ChartRenderingInfo(new StandardEntityCollection()); // Sauvegarde du graphe historique au format png dans un espace temporaire String fileNameHisto = ServletUtilities.saveChartAsPNG(chartKiviat, HistoMaker.DEFAULT_WIDTH, HistoMaker.DEFAULT_HEIGHT, infoHisto, pRequest.getSession()); histoChart = new GraphMaker(pRequest, fileNameHisto, infoHisto); } return histoChart; }