List of usage examples for org.jfree.chart ChartUtilities saveChartAsPNG
public static void saveChartAsPNG(File file, JFreeChart chart, int width, int height, ChartRenderingInfo info) throws IOException
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 w ww . j ava2 s.co m*/ * @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.signserver.client.cli.performance.PerformanceTestPDFServlet.java
License:asdf
/** * Create and write diagrams to disk.//from w ww . j av a 2 s . c o 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:org.gephi.statistics.plugin.DegreeDistribution.java
/** * * @return The directed version of the report. *///from w w w . ja va 2 s . c o m 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:graph.plotter.BarMenu.java
/** * This is the main working button for this class... It creates bar chart analyZing whole data set * /*from ww w .j av a 2s . c o m*/ * @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);/*from w w w. j a 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:it.eng.spagobi.engines.chart.SpagoBIChartInternalEngine.java
/** This method is used to execute a chart code way and returning the image chart execution * Pay attention that must get the parameters from BiObject in order to filter categories and series * /* w ww . jav a 2 s .c om*/ * All the parameters must be taken not from request but from BiObject * * @param requestContainer * @param obj * @param response * @throws EMFUserError */ public File executeChartCode(RequestContainer requestContainer, BIObject obj, SourceBean response, IEngUserProfile userProfile) throws EMFUserError { logger.debug("IN"); File toReturn = null; Locale locale = GeneralUtilities.getDefaultLocale(); DatasetMap datasets = null; ChartImpl sbi = null; String documentId = obj.getId().toString(); // **************get the template***************** logger.debug("getting template"); SourceBean serviceRequest = requestContainer.getServiceRequest(); try { //SourceBean content = getTemplate(documentId); SourceBean content = null; byte[] contentBytes = null; try { ObjTemplate template = DAOFactory.getObjTemplateDAO() .getBIObjectActiveTemplate(Integer.valueOf(documentId)); if (template == null) throw new Exception("Active Template null"); contentBytes = template.getContent(); if (contentBytes == null) { logger.error("TEMPLATE DOESN'T EXIST !!!!!!!!!!!!!!!!!!!!!!!!!!!"); EMFUserError userError = new EMFUserError(EMFErrorSeverity.ERROR, 2007); userError.setBundle("messages"); throw userError; } // get bytes of template and transform them into a SourceBean String contentStr = new String(contentBytes); content = SourceBean.fromXMLString(contentStr); } catch (Exception e) { logger.error("Error while converting the Template bytes into a SourceBean object"); EMFUserError userError = new EMFUserError(EMFErrorSeverity.ERROR, 2003); userError.setBundle("messages"); throw userError; } // **************take informations on the chart type***************** String type = content.getName(); String subtype = (String) content.getAttribute("type"); //if it's an highcharts document get the png file by the svg content presents into the // description of the biobject /* if (type != null && type.startsWith(HIGHCHART_TEMPLATE)){ //create the png file using the svg InputStream inputStream = null; OutputStream outputStream = null; try{ String svg = obj.getDescription(); //svg = svg.replaceAll("\\\\", ""); inputStream = new ByteArrayInputStream(svg.getBytes("UTF-8")); File dir = new File(System.getProperty("java.io.tmpdir")); Random generator = new Random(); int randomInt = generator.nextInt(); toReturn = File.createTempFile(Integer.valueOf(randomInt).toString(), ".png", dir); outputStream = new FileOutputStream(toReturn); ExportHighCharts.transformSVGIntoPNG(inputStream, outputStream); } catch (Exception e) { logger.error(e); return null; }finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { logger.error(e); } } if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { logger.error(e); } } logger.debug("OUT"); } logger.debug("OUT"); return toReturn; } */ String data = ""; try { logger.debug("Getting Data Set ID"); data = obj.getDataSetId().toString(); } catch (Exception e) { logger.error("Error while getting the dataset ", e); return null; } //Map parametersMap=getParametersCode(obj); Map parametersMap = getParameters(obj); try { logger.debug("create the chart"); // set the right chart type sbi = ChartImpl.createChart(type, subtype); sbi.setProfile(userProfile); sbi.setType(type); sbi.setSubtype(subtype); sbi.setData(data); sbi.setLocale(locale); sbi.setParametersObject(parametersMap); // configure the chart with template parameters sbi.configureChart(content); sbi.setLocalizedTitle(); // Don't care for linkable charts configuration because we are building for static exporting } catch (Exception e) { logger.error("Error while creating the chart", e); EMFUserError userError = new EMFUserError(EMFErrorSeverity.ERROR, 2004); userError.setBundle("messages"); throw userError; } datasets = retrieveDatasetValue(sbi); String series = null; String categories = null; String catGroups = null; String n_visualization = null; //check if serie or categories or cat_group have been set, here you have to check among parameters if (parametersMap.get("serie") != null) {// check what happens in case of multivalue! series = parametersMap.get("serie").toString(); } if (parametersMap.get("cat_group") != null) {// check what happens in case of multivalue! catGroups = parametersMap.get("cat_group").toString(); } if (parametersMap.get("categoryAll") != null) { categories = "0"; } else if (parametersMap.get("category") != null) { categories = parametersMap.get("category").toString(); if (categories.equals("0")) categories = "1"; } if (parametersMap.get("n_visualization") != null) {// check what happens in case of multivalue! n_visualization = parametersMap.get("n_visualization").toString(); } // Now I have to filter the dataset and draw the image! AttributesContainer attCont = new AttributesContainer(parametersMap); DatasetMap copyDatasets = null; // use the same code used in chart.jsp to filter various type of chart datasets.setSelectedSeries(new Vector()); if (sbi.getType().equalsIgnoreCase("BARCHART") || sbi.getType().equalsIgnoreCase("CLUSTERCHART")) { //if(sbi.getSubtype().equalsIgnoreCase("simplebar") || sbi.getSubtype().equalsIgnoreCase("linkableBar") || sbi.getSubtype().equalsIgnoreCase("stacked_bar") || sbi.getSubtype().equalsIgnoreCase("stacked_bar_group")){ if (sbi.getSubtype().equalsIgnoreCase("simplebar") || sbi.getSubtype().equalsIgnoreCase("linkableBar") || sbi.getSubtype().equalsIgnoreCase("stacked_bar")) { // returns a new datasets map filtered copyDatasets = datasets.filteringSimpleBarChartUtil(attCont, attCont, (BarCharts) sbi, "WEB", true); } else if (sbi.getSubtype().equalsIgnoreCase("overlaid_barline") || sbi.getSubtype().equalsIgnoreCase("overlaid_stackedbarline") || sbi.getSubtype().equalsIgnoreCase("combined_category_bar")) { copyDatasets = datasets.filteringMultiDatasetBarChartUtil(attCont, attCont, (BarCharts) sbi, "WEB", true); } else if (sbi.getSubtype().equalsIgnoreCase("simplecluster")) { copyDatasets = datasets.filteringClusterChartUtil(attCont, (ClusterCharts) sbi, "WEB", true); } else if (sbi.getSubtype().equalsIgnoreCase("stacked_bar_group")) { copyDatasets = datasets.filteringGroupedBarChartUtil(attCont, attCont, (StackedBarGroup) sbi, "WEB", true); } } else { copyDatasets = datasets; } // TODO MultiCHart export if (sbi.getMultichart()) { logger.debug("no treated yet multichart export"); } else { JFreeChart chart = null; chart = sbi.createChart(copyDatasets); String dir = System.getProperty("java.io.tmpdir"); Random generator = new Random(); int randomInt = generator.nextInt(); String path = dir + "/" + Integer.valueOf(randomInt).toString() + ".png"; //String path=dir+"/"+executionId+".png"; toReturn = new java.io.File(path); ChartUtilities.saveChartAsPNG(toReturn, chart, sbi.getWidth(), sbi.getHeight(), null); } } catch (Exception e) { logger.error("Error in executing th chart"); } logger.debug("OUT"); return toReturn; }
From source file:Gui.admin.NouveauStatistique.java
private void StatistiquesBouttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StatistiquesBouttonActionPerformed int size = tablemesEvaluation.getRowCount(); List<Double> notes = new ArrayList<Double>(); List<Integer> ids = new ArrayList<Integer>(); List<String> noms = new ArrayList<String>(); EvaluationDAO evaluationDAO = new EvaluationDAO(); System.out.println("ouh ouh " + size); //System.out.println(evaluationDAO.getMoyenneByAdherent(8)); int idadh;//w w w .j av a2s . c om float ess; for (int i = 0; i < size; i++) { System.out.println(tablemesEvaluation.getValueAt(i, 4).toString()); idadh = Integer.parseInt(tablemesEvaluation.getValueAt(i, 1).toString()); String nom = (tablemesEvaluation.getValueAt(i, 2).toString()); // notes.add((new Double (tablemesEvaluation.getValueAt(i,2).toString()))); System.out.println(" id adherent " + idadh); // System.out.println("moyenne "+); ess = evaluationDAO.getMoyenneByAdherent(idadh); System.out.println(ess); // notes.add((new Double (evaluationDAO.getMoyenneByAdherent((int) tablemesEvaluation.getValueAt(i,1))))); notes.add((new Double(ess))); ids.add((int) tablemesEvaluation.getValueAt(i, 1)); noms.add(nom); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < size; i++) { dataset.setValue(new Double(notes.get(i)), "notes", new String(noms.get(i))); } //dataset.setValue(evaluationTable); JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Noms des 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(700, 800); ValueMarker marker = new ValueMarker(15); marker.setLabel(" seuil de l'valuation "); marker.setLabelAnchor(RectangleAnchor.CENTER); marker.setPaint(Color.YELLOW); p.addRangeMarker(marker); p.setRangeGridlinePaint(Color.RED); 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:org.gephi.statistics.plugin.DegreeDistribution.java
/** * * @return The undirected version of this report. *///from w ww .j a va 2 s . com private String getUndirectedReport() { double max = 0; XYSeries series2 = new XYSeries("Series 2"); for (int i = 1; i < combinedDistribution[1].length; i++) { if (combinedDistribution[1][i] > 0) { series2.add((Math.log(combinedDistribution[0][i]) / Math.log(Math.E)), (Math.log(combinedDistribution[1][i]) / Math.log(Math.E))); max = (float) Math.max((Math.log(combinedDistribution[0][i]) / Math.log(Math.E)), max); } } double a = combinedAlpha; double b = combinedBeta; XYSeries series1 = new XYSeries(combinedAlpha + " "); series1.add(0, a); series1.add(max, a + b * max); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); JFreeChart chart = ChartFactory.createXYLineChart("Degree Distribution", "Degree", "Occurrence", dataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesShape(1, new java.awt.geom.Ellipse2D.Double(0, 0, 1, 1)); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainGridlinePaint(java.awt.Color.GRAY); plot.setRangeGridlinePaint(java.awt.Color.GRAY); plot.setRenderer(renderer); String imageFile = ""; try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); TempDir tempDir = TempDirUtils.createTempDir(); final String fileName = "distribution.png"; final File file1 = tempDir.createFile(fileName); imageFile = "<IMG SRC=\"file:" + file1.getAbsolutePath() + "\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\"></IMG>"; ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (IOException e) { System.out.println(e.toString()); } 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>" + "Degree Power Law: -" + combinedAlpha + "\n <BR>" + imageFile + "</BODY> </HTML>"; return report; }
From source file:org.yardstickframework.report.jfreechart.JFreeChartGraphPlotter.java
/** * @param folderToWrite Folder to write the resulted charts. * @param plots Collections of plots.//from w ww . j av a2s . c om * @param infoMap Map with additional plot info. * @param mode Generation mode. * @throws Exception If failed. */ private static void processPlots(File folderToWrite, Collection<List<PlotData>> plots, Map<String, List<JFreeChartPlotInfo>> infoMap, JFreeChartGenerationMode mode) throws Exception { ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); int idx = -1; while (true) { idx++; DefaultXYDataset dataSet = new DefaultXYDataset(); List<JFreeChartPlotInfo> infoList = new ArrayList<>(); String xAxisLabel = ""; String yAxisLabel = ""; String plotName = ""; int cnt = 0; for (List<PlotData> plotData0 : plots) { if (plotData0.size() <= idx) continue; PlotData plotData = plotData0.get(idx); dataSet.addSeries(plotData.plotName() + "_" + cnt++, plotData.series().data); xAxisLabel = plotData.xAxisLabel; yAxisLabel = plotData.yAxisLabel; plotName = plotData.plotName(); infoList.add(info(plotData.series(), mode)); } if (infoList.isEmpty()) break; JFreeChart chart = ChartFactory.createXYLineChart("", xAxisLabel, yAxisLabel, dataSet, PlotOrientation.VERTICAL, false, false, false); AxisSpace as = new AxisSpace(); as.add(150, RectangleEdge.LEFT); XYPlot plot = (XYPlot) chart.getPlot(); BasicStroke stroke = new BasicStroke(1); plot.setRenderer(renderer); plot.setBackgroundPaint(WHITE); plot.setRangeGridlinePaint(GRAY); plot.setDomainGridlinePaint(GRAY); plot.setFixedRangeAxisSpace(as); plot.setOutlineStroke(stroke); for (int i = 0; i < infoList.size(); i++) { Color color = PLOT_COLORS[i % PLOT_COLORS.length]; renderer.setSeriesPaint(i, color); renderer.setSeriesStroke(i, new BasicStroke(3)); // Line thickness. infoList.get(i).color(Integer.toHexString(color.getRGB()).substring(2)); } ValueAxis axis = plot.getRangeAxis(); Font font = new Font("Helvetica,Arial,sans-serif", Font.BOLD, axis.getTickLabelFont().getSize() + 5); axis.setTickLabelFont(font); axis.setLabelFont(font); plot.getDomainAxis().setTickLabelFont(font); plot.getDomainAxis().setLabelFont(font); chart.setTitle(new TextTitle(yAxisLabel, new Font(font.getName(), font.getStyle(), 30))); File res = new File(folderToWrite, plotName + ".png"); ChartUtilities.saveChartAsPNG(res, chart, 1000, 500, info); infoMap.put(res.getAbsolutePath(), infoList); println("Chart is saved to file: ", res); } }
From source file:graph.plotter.LineGraph.java
/** * This is the main working button for this class... It creates Line Graph analyZing whole data set * /* w ww .j av a2 s .co m*/ * @param evt */ private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: try { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int i; i = 0; String genre = " "; if (button1 == 2) { if (button2 == 1) while (i < cnt) { double aa = Double.parseDouble(Table.getModel().getValueAt(i, 1).toString()); String str = Table.getModel().getValueAt(i, 0).toString(); dataset.setValue(new Double(aa), genre, str); i++; //genre+=" "; } else { try { BufferedReader br = new BufferedReader(new FileReader(jTextField4.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(LineGraph.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(LineGraph.class.getName()).log(Level.SEVERE, null, ex); } } } else if (button1 == 1) { String input = jTextField1.getText(); input = input.replaceAll("sin", "@"); input = input.replaceAll("cos", "#"); input = input.replaceAll("tan", "Q"); input = input.replaceAll("log", "~"); input = input.replaceAll("e", "&"); input = input.replaceAll("cosec", "r"); input = input.replaceAll("cot", "w"); input = input.replaceAll("sec", "y"); //System.out.println(input); int len; len = input.length(); String so = "."; for (ind = 0; ind < 360; ind++) { String gini = input; String sa = Integer.toString(ind); gini = gini.replaceAll("X", sa); Polish polish = new Polish(gini); double Calculate = Polish.Calculate(); dataset.setValue(new Double(Calculate), ".", sa); so += "."; } } JFreeChart chart = ChartFactory.createLineChart("Line Graph", "X - Axis", "Y - Axis", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.YELLOW); p.setBackgroundPaint(Color.BLACK); ChartFrame frame = new ChartFrame("Line Chart", 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("Line_Chart.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (Exception ex) { } } }); frame.setVisible(true); frame.setSize(858, 513); } catch (Exception e) { } }