List of usage examples for org.jfree.chart JFreeChart getXYPlot
public XYPlot getXYPlot()
From source file:org.xapagy.ui.tempdyn.GraphEvolution.java
/** * Creates a chart the style we like.//from www.java2 s. co m * * @param chart */ public static void setChartProperties(JFreeChart chart, List<SimpleEntry<Color, Stroke>> lineStyles) { // set the background and title font chart.setBackgroundPaint(Color.white); chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 14)); // set the background and the grid all white XYPlot plot = chart.getXYPlot(); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setBackgroundPaint(Color.white); // now plot.setOutlineStroke(null); XYItemRenderer rend = plot.getRenderer(); Stroke stroke = new BasicStroke(2.0f); rend.setBaseStroke(stroke); // rend.setDrawSeriesLineAsPath(true); // stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, // BasicStroke.JOIN_ROUND, 10, new float[] {10, 10}, 0); // strokes.add(stroke); // stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, // BasicStroke.JOIN_ROUND, 10, new float[] {2, 4}, 0); // strokes.add(stroke); int seriesCount = plot.getSeriesCount(); for (int i = 0; i != seriesCount; i++) { SimpleEntry<Color, Stroke> lineStyle = lineStyles.get(i % lineStyles.size()); rend.setSeriesStroke(i, lineStyle.getValue()); rend.setSeriesPaint(i, lineStyle.getKey()); } }
From source file:org.xapagy.ui.tempdyn.GraphEvolution.java
/** * Returns a chart for the evolution of the shadowing of the component tdc with sh. * /*from w ww. j a v a2 s .c o m*/ * @param tdc * @param sh * @param database * @param agent * @param index * @param shadowRange * @param ged * @return */ public static JFreeChart chartShadowEvolution(tdComponent tdc, String sh, tdDataBase database, Agent agent, List<Double> index, double shadowRange, GraphEvolutionDescriptor ged) { List<String> shadowColors = null; if (tdc.getType() == tdComponentType.INSTANCE) { shadowColors = ged.shadowInstanceEnergyColors; } else { shadowColors = ged.shadowViEnergyColors; } // create a general purpose xy collection for jfreechart XYSeriesCollection xysc = new XYSeriesCollection(); // shadow energy values (if needed) if (ged.graphShadowEnergy) { for (String ec : shadowColors) { xysc.addSeries(new XYSeries("ShadowEnergy_" + ec + "_" + sh)); } } // shadow salience values (if needed) if (ged.graphShadowSalience) { for (String ec : shadowColors) { xysc.addSeries(new XYSeries("ShadowSalience_" + ec + "_" + sh)); } } // // Fill in the values into the xysc // for (Double time : index) { double dtime = time; // shadow energy values (if needed) if (ged.graphShadowEnergy) { for (String ec : shadowColors) { double value = database.getEnergy(tdc.getIdentifier(), sh, ec, time); xysc.getSeries("ShadowEnergy_" + ec + "_" + sh).add(dtime, value); } } // shadow salience values (if needed) if (ged.graphShadowSalience) { for (String ec : shadowColors) { double value = database.getSalience(tdc.getIdentifier(), sh, ec, time); xysc.getSeries("ShadowSalience_" + ec + "_" + sh).add(dtime, value); } } } XYSeriesCollection xysSH = new XYSeriesCollection(); // shadow energy (if needed) if (ged.graphShadowEnergy) { for (String ec : shadowColors) { xysSH.addSeries(xysc.getSeries("ShadowEnergy_" + ec + "_" + sh)); } } // shadow salience (if needed) if (ged.graphShadowSalience) { for (String ec : shadowColors) { xysSH.addSeries(xysc.getSeries("ShadowSalience_" + ec + "_" + sh)); } } // FIND a label String shadowLabel = "Shadow:" + sh; if (tdc.getType() == tdComponentType.INSTANCE) { Instance instance = agent.getAutobiographicalMemory().getInstance(sh); shadowLabel += " - " + SpInstance.spc(instance, agent); } else { VerbInstance vi = agent.getAutobiographicalMemory().getVerbInstance(sh); shadowLabel += " - " + XapiPrint.ppsViXapiForm(vi, agent); } JFreeChart chart = ChartFactory.createXYLineChart(shadowLabel, "Time", "Value", xysSH, PlotOrientation.VERTICAL, true, false, false); GraphEvolution.setChartProperties(chart, GraphEvolution.lineStylesConservative); XYPlot plot = chart.getXYPlot(); plot.getRangeAxis(0).setRange(0, shadowRange); return chart; }
From source file:evaluation.simulator.gui.results.LineJFreeChartCreator.java
/** * Creates a chart./*from ww w .j a v a 2 s . co m*/ * * @param dataset * the data for the chart. * * @return a chart. */ private static JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createXYLineChart("Latency Mix Message", // chart title "BATCH_SIZE", // x axis label "ms", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); // Spezial berschreiben des Aussehen der Striche im Graphen final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer() { private static final long serialVersionUID = 1L; Stroke soild = new BasicStroke(2.0f); @Override public Stroke getItemStroke(int row, int column) { return this.soild; } }; final XYPlot plot = chart.getXYPlot(); plot.setRenderer(renderer); return chart; }
From source file:dbseer.gui.chart.DBSeerChartFactory.java
public static JFreeChart createCustomXYLineChart(String xAxisName, String yAxisName) throws Exception { StatisticalPackageRunner runner = DBSeerGUI.runner; runner.eval("[Xdata Ydata] = plotter.plotCustom('" + DBSeerPlotControlPanel.axisMap.get(xAxisName) + "', '" + DBSeerPlotControlPanel.axisMap.get(yAxisName) + "');"); String title = "Custom Plot"; Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata"); Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata"); String xLabel = xAxisName;//from w w w .j a v a 2 s . c om String yLabel = yAxisName; XYSeriesCollection dataSet = new XYSeriesCollection(); int numXCellArray = xCellArray.length; int numYCellArray = yCellArray.length; int dataCount = 0; if (numXCellArray != numYCellArray) { JOptionPane.showMessageDialog(null, "The number of X dataset and Y dataset does not match.", "The number of X dataset and Y dataset does not match.", JOptionPane.ERROR_MESSAGE); System.out.println(numXCellArray + " : " + numYCellArray); return null; } for (int i = 0; i < numYCellArray; ++i) { double[] xArray = (double[]) xCellArray[i]; runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});"); runner.eval("yArray = Ydata{" + (i + 1) + "};"); double[] yArraySize = runner.getVariableDouble("yArraySize"); double[] yArray = runner.getVariableDouble("yArray"); int xLength = xArray.length; int row = (int) yArraySize[0]; int col = (int) yArraySize[1]; for (int c = 0; c < col; ++c) { XYSeries series = new XYSeries(yAxisName + " " + (c + 1)); for (int r = 0; r < row; ++r) { int xRow = (r >= xLength) ? xLength - 1 : r; series.add(xArray[xRow], yArray[r + c * row]); } dataSet.addSeries(series); ++dataCount; } } JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, dataSet); for (int i = 0; i < dataCount; ++i) { // Renderer to highlight selected normal or outlier points. chart.getXYPlot().setRenderer(i, new DBSeerXYLineAndShapeRenderer()); } return chart; }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * DOC xqliu Comment method "createLineChart". * /*from w ww.j a va2s .com*/ * @param title * @param dataset * @param showLegend * @return */ public static JFreeChart createLineChart(String title, XYDataset dataset, boolean showLegend) { // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); // TDQ-5112~ final JFreeChart chart = ChartFactory.createXYLineChart(null, title, Messages.getString("TopChartFactory.Percent"), dataset, PlotOrientation.VERTICAL, //$NON-NLS-1$ showLegend, false, false); final XYPlot plot = chart.getXYPlot(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); plot.setRenderer(renderer); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:org.gwaspi.reports.GenericReportGenerator.java
public static XYPlot buildQQPlot(OperationKey testOpKey, int df) throws IOException { if (df != 1 && df != 2) { throw new IllegalArgumentException("Only df = 1 or 2 is supported; it is " + df); }// ww w . j av a 2s . co m //<editor-fold defaultstate="expanded" desc="PLOT DEFAULTS"> final Config config = Config.getSingleton(); final Color background = config.getColor(PLOT_QQ_BACKGROUND_CONFIG, PLOT_QQ_BACKGROUND_DEFAULT); final Color actual = config.getColor(PLOT_QQ_ACTUAL_CONFIG, PLOT_QQ_ACTUAL_DEFAULT); final Color sigma = config.getColor(PLOT_QQ_SIGMA_CONFIG, PLOT_QQ_SIGMA_DEFAULT); final Color mu = config.getColor(PLOT_QQ_MU_CONFIG, PLOT_QQ_MU_DEFAULT); //</editor-fold> //<editor-fold defaultstate="expanded" desc="GET X^2"> List<Double> obsChiSqrVals = assembleQQPlotData(testOpKey); int N = obsChiSqrVals.size(); List<Double> expChiSqrDist; if (df == 1) { expChiSqrDist = Chisquare.getChiSquareDistributionDf1(N, 1.0f); } else { // df == 2 expChiSqrDist = Chisquare.getChiSquareDistributionDf2(N, 1.0f); } Collections.sort(expChiSqrDist); //</editor-fold> //<editor-fold defaultstate="expanded" desc="GET CONFIDENCE BOUNDARY"> InputStream boundaryStream = GenericReportGenerator.class .getResourceAsStream("/samples/chisqrboundary-df" + df + ".txt"); InputStreamReader isr = new InputStreamReader(boundaryStream); BufferedReader inputBufferReader = new BufferedReader(isr); Double stopValue = expChiSqrDist.get(N - 1); Double currentValue = 0d; List<Double[]> boundary = new ArrayList<Double[]>(); while (currentValue <= stopValue) { String l = inputBufferReader.readLine(); if (l == null) { break; } String[] cVals = l.split(","); Double[] slice = new Double[3]; slice[0] = Double.parseDouble(cVals[0]); slice[1] = Double.parseDouble(cVals[1]); slice[2] = Double.parseDouble(cVals[2]); currentValue = slice[1]; boundary.add(slice); } inputBufferReader.close(); //</editor-fold> XYSeriesCollection dataSeries = new XYSeriesCollection(); XYSeries seriesData = new XYSeries("X"); XYSeries seriesRef = new XYSeries("Expected"); for (int i = 0; i < obsChiSqrVals.size(); i++) { double obsVal = obsChiSqrVals.get(i); double expVal = expChiSqrDist.get(i); seriesData.add(expVal, obsVal); seriesRef.add(expVal, expVal); } //constant chi-square boundaries XYSeries seriesLower = new XYSeries("2 boundary"); XYSeries seriesUpper = new XYSeries(""); for (Double[] slice : boundary) { seriesUpper.add(slice[1], slice[0]); seriesLower.add(slice[1], slice[2]); } dataSeries.addSeries(seriesData); dataSeries.addSeries(seriesRef); dataSeries.addSeries(seriesUpper); dataSeries.addSeries(seriesLower); final XYDataset data = dataSeries; //create QQ plot final boolean withLegend = true; JFreeChart chart = ChartFactory.createScatterPlot("QQ-plot", "Exp X", "Obs X", data, PlotOrientation.VERTICAL, withLegend, false, false); final XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setSeriesPaint(0, actual); renderer.setSeriesPaint(1, mu); renderer.setSeriesPaint(2, sigma); renderer.setSeriesPaint(3, sigma); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setSeriesShape(0, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); renderer.setSeriesShape(1, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); renderer.setSeriesShape(2, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); renderer.setSeriesShape(3, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); plot.setRenderer(renderer); // PLOT BACKGROUND COLOR plot.setBackgroundPaint(background); // Hue, saturation, brightness return plot; }
From source file:net.sf.jsfcomp.chartcreator.utils.ChartAxisUtils.java
public static void createXYSeriesAxis(JFreeChart chart, ChartAxisData chartAxisData, int axisIndex) { ValueAxis axis = null;//from ww w . java2 s . com if (chartAxisData.getType() != null) { if (chartAxisData.getType().equals("number")) axis = createNumberAxis(chart, chartAxisData); else if (chartAxisData.getType().equals("date")) axis = createDateAxis(chart, chartAxisData); if (chartAxisData.getTickLabelFontSize() > 0) { Font tickFont = CategoryAxis.DEFAULT_TICK_LABEL_FONT .deriveFont(chartAxisData.getTickLabelFontSize()); axis.setTickLabelFont(tickFont); } axis.setTickLabelsVisible(chartAxisData.isTickLabels()); axis.setTickMarksVisible(chartAxisData.isTickMarks()); axis.setVerticalTickLabels(chartAxisData.isVerticalTickLabels()); } XYPlot plot = chart.getXYPlot(); if (chartAxisData.isDomain()) { plot.setDomainAxis(plot.getDomainAxisCount() - 1, axis); } else { plot.setRangeAxis(axisIndex, axis); XYDataset dataset = (XYDataset) chartAxisData.getDatasource(); plot.setRenderer(axisIndex, new StandardXYItemRenderer()); plot.setDataset(axisIndex, dataset); plot.mapDatasetToRangeAxis(axisIndex, axisIndex); } setXYSeriesAxisColors(chartAxisData, plot.getRenderer(axisIndex)); }
From source file:de.thorstenberger.taskmodel.view.statistics.graph.FixXAxisChartPostProcessor.java
public void processChart(Object arg0, Map arg1) { JFreeChart chart = (JFreeChart) arg0; chart.getXYPlot().setDomainAxis(new NumberAxis(chart.getXYPlot().getDomainAxis().getLabel())); }
From source file:edu.unc.LCCC.caBIG.DWD.javaCode.visualization.SetUpPlotWindow.java
public static JPanel createXYScatterPlotChart(XYDataset data, String x, String y, int w, int h) { //XYDataset data = new SampleXYDataset2(); JFreeChart chart = ChartFactory.createScatterPlot(null, // the title of the chart x, // the label for the X axis y, // the label for the Y axis data, // the dataset for the chart PlotOrientation.VERTICAL, // the orientation of the chart true, // a flag specifying whether or not a legend is required true, // a flag specifying whether or not tooltips should be generated false); // a flag specifying whether or not the chart should generate URLs XYPlot plot = (XYPlot) chart.getXYPlot(); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); /*//www.jav a 2 s . c om NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); ValueAxis xAxis = plot.getDomainAxis(); xAxis.setFixedDimension(50); ValueAxis yAxis = plot.getRangeAxis(); */ //StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); //renderer.setSeriesPaint(0, java.awt.Color.red); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(w, h)); return chartPanel; }
From source file:Util.PacketGenerator.java
public static void GenerateGraph() { try {/*from ww w .ja va 2 s.com*/ for (int j = 6; j <= 6; j++) { File real = new File("D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\Real.csv"); for (int k = 1; k <= 4; k++) { File simu = new File( "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\SimulacaoInstancia" + k + ".csv"); FileInputStream simuFIS = new FileInputStream(simu); DataInputStream simuDIS = new DataInputStream(simuFIS); BufferedReader simuBR = new BufferedReader(new InputStreamReader(simuDIS)); FileInputStream realFIS = new FileInputStream(real); DataInputStream realDIS = new DataInputStream(realFIS); BufferedReader realBR = new BufferedReader(new InputStreamReader(realDIS)); String lineSimu = simuBR.readLine(); String lineReal = realBR.readLine(); XYSeries matrix = new XYSeries("Matriz", false, true); while (lineSimu != null && lineReal != null) { lineSimu = lineSimu.replaceAll(",", "."); String[] simuMatriz = lineSimu.split(";"); String[] realMatriz = lineReal.split(";"); for (int i = 0; i < simuMatriz.length; i++) { try { Integer valorReal = Integer.parseInt(realMatriz[i]); Float valorSimu = Float.parseFloat(simuMatriz[i]); matrix.add(valorReal.doubleValue() / 1000.0, valorSimu.doubleValue() / 1000.0); } catch (NumberFormatException ex) { } } lineSimu = simuBR.readLine(); lineReal = realBR.readLine(); } simuFIS.close(); simuDIS.close(); simuBR.close(); realFIS.close(); realDIS.close(); realBR.close(); double maxPlot = Double.max(matrix.getMaxX(), matrix.getMaxY()) * 1.1; XYSeries middle = new XYSeries("Referncia"); ; middle.add(0, 0); middle.add(maxPlot, maxPlot); XYSeries max = new XYSeries("Superior 20%"); max.add(0, 0); max.add(maxPlot, maxPlot * 1.2); XYSeries min = new XYSeries("Inferior 20%"); min.add(0, 0); min.add(maxPlot, maxPlot * 0.8); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(middle); dataset.addSeries(matrix); dataset.addSeries(max); dataset.addSeries(min); JFreeChart chart; if (k == 4) { chart = ChartFactory.createXYLineChart("Matriz de Trfego", "Real", "CMO-MT", dataset); } else { chart = ChartFactory.createXYLineChart("Matriz de Trfego", "CMO-MT", "Zhao", dataset); } chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); chart.getTitle().setFont(new Font("Times New Roman", Font.BOLD, 13)); chart.getLegend().setItemFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 10)); chart.getXYPlot().getDomainAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10)); chart.getXYPlot().getDomainAxis() .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1)); chart.getXYPlot().getRangeAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10)); chart.getXYPlot().getRangeAxis() .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1)); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 0.1f }, 0.0f)); renderer.setSeriesShape(1, new Ellipse2D.Float(-1.5f, -1.5f, 3f, 3f)); renderer.setSeriesStroke(2, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f }, 0.0f)); renderer.setSeriesStroke(3, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f }, 0.0f)); renderer.setSeriesPaint(0, Color.BLACK); renderer.setSeriesPaint(1, Color.BLACK); renderer.setSeriesPaint(2, Color.BLACK); renderer.setSeriesPaint(3, Color.BLACK); int width = (int) (192 * 1.5f); /* Width of the image */ int height = (int) (144 * 1.5f); /* Height of the image */ File XYChart = new File( "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\SimulacaoInstancia" + k + ".jpeg"); ChartUtilities.saveChartAsJPEG(XYChart, chart, width, height); } } } catch (Exception e) { e.printStackTrace(); } }