List of usage examples for org.jfree.chart.plot PlotOrientation VERTICAL
PlotOrientation VERTICAL
To view the source code for org.jfree.chart.plot PlotOrientation VERTICAL.
Click Source Link
From source file:com.etest.view.tq.charts.SubjectTestLineChart.java
public static JFreeChart difficultIndex(int tqCoverageId) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (CellItem ci : CellItemDAO.getItemAnalysisResult(tqCoverageId)) { dataset.setValue((int) (ci.getDifficultIndex() * 100), "Difficulty Index", String.valueOf(ci.getItemNo())); }// w w w . j a v a 2s . co m JFreeChart chart = ChartFactory.createLineChart("Item Analysis Report", "Item No.", "Difficulty Index (%)", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // customise the renderer... LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setFillPaint(Color.white); return chart; }
From source file:problematica.Graficos.java
/** * //w w w . ja va 2s . c om * @param cantCigarros */ public static void createGrafico(ArrayList<ArrayList<String>> datos, String nombreArchivo) { XYSeries series = new XYSeries("Linea de consumo"); //como su nombre lo indica el primer valor sera asignado al eje X //y el segundo al eje Y series.add(0, 0); for (int i = 0; i < datos.size(); i++) { series.add((i + 1), Integer.parseInt(datos.get(i).get(0))); } //se crea un objeto XYDataset requerido mas adelante por el metodo que grafica XYDataset juegoDatos = new XYSeriesCollection(series); /*aqui se hace la instancia de la nueva grafica invocando al metodo de ChartFactory que nos dibujara una grafica de lineas este metodo como casi todos los demas recibe los siguientes argumentos: tipo valor String nombre de la grafica , aparecera en la parte superior centro String tutulo del eje X String titulo del eje Y XYDataset el conjunto de datos X y Y del tipo XYDataset (aqui cambian el parametro dependiendo del tipo de grafica que se quiere pueden ver todos los parametros en la documentacion aqui <a href="http://www.jfree.org/jfreechart/api/javadoc/index.html " title="http://www.jfree.org/jfreechart/api/javadoc/index.html ">http://www.jfree.org/jfreechart/api/javadoc/index.html </a> iremos notando los cambios mas adelante.. PlotOrientation la orientacion del grafico puede ser PlotOrientation.VERTICAL o PlotOrientation.HORIZONTAL boolean muestra u oculta leyendas boolean muestra u oculta tooltips boolean muestra u oculta urls (esta opcion aun no la entiendo del todo) generalmente solo necesitaremos cambiar los primeros 3 parametros lo demas puede quedarse asi */ JFreeChart chart = ChartFactory.createXYLineChart("Grafico de consumo", "dias", "cantidad cigarrillos", juegoDatos, PlotOrientation.VERTICAL, true, false, true // Show legend ); //donde guardaremos la imagen?? pues en un bufer jeje BufferedImage image = chart.createBufferedImage(500, 500); try { ImageIO.write(image, "jpg", new File("c:/users/public/nms/grafico/" + nombreArchivo + ".jpg")); } catch (IOException e) { System.out.println("Error de escritura"); } }
From source file:ec.nbdemetra.benchmarking.calendarization.CalendarizationChartView.java
private static JFreeChart createChart(String title) { JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(), PlotOrientation.VERTICAL, false, false, false); result.setPadding(TsCharts.CHART_PADDING); result.setTitle(new TextTitle(title, new Font("SansSerif", Font.PLAIN, 12))); XYPlot plot = result.getXYPlot();/*from ww w . j a v a 2 s.co m*/ plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); LinesThickness linesThickness = LinesThickness.Thin; XYLineAndShapeRenderer daily = new XYLineAndShapeRenderer(true, false); daily.setAutoPopulateSeriesPaint(false); daily.setAutoPopulateSeriesStroke(false); daily.setBaseStroke(TsCharts.getStrongStroke(linesThickness)); plot.setRenderer(DAILY_INDEX, daily); XYDifferenceRenderer difference = new XYDifferenceRenderer(); difference.setAutoPopulateSeriesPaint(false); difference.setAutoPopulateSeriesStroke(false); difference.setBaseStroke(TsCharts.getNormalStroke(linesThickness)); plot.setRenderer(DIFF_INDEX, difference); XYLineAndShapeRenderer smooth = new XYLineAndShapeRenderer(true, false); smooth.setAutoPopulateSeriesPaint(false); smooth.setAutoPopulateSeriesStroke(false); smooth.setBaseStroke(TsCharts.getStrongStroke(linesThickness)); plot.setRenderer(SMOOTH_INDEX, smooth); DateAxis domainAxis = new DateAxis(); domainAxis.setTickMarkPosition(DateTickMarkPosition.START); domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setDomainAxis(domainAxis); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setRangeAxis(rangeAxis); return result; }
From source file:edu.emory.library.tast.database.graphs.GraphTypeScatter.java
public JFreeChart createChart(Object[] data) { CategoryTableXYDataset dataset = new CategoryTableXYDataset(); JFreeChart chart = ChartFactory.createScatterPlot(null, getSelectedIndependentVariable().getLabel(), TastResource.getText("components_charts_barvalue"), dataset, PlotOrientation.VERTICAL, true, true, false);/*from w w w . j a v a 2 s . co m*/ //getSelectedIndependentVariable().getFormat(); XYPlot plot = chart.getXYPlot(); ((NumberAxis) plot.getDomainAxis()).setNumberFormatOverride(new DecimalFormat("0")); chart.setBackgroundPaint(Color.white); List allDataSeries = getDataSeries(); for (int j = 0; j < allDataSeries.size(); j++) { DataSeries dataSearies = (DataSeries) allDataSeries.get(j); String dataSeriesLabel = dataSearies.formatForDisplay(); for (int i = 0; i < data.length; i++) { Object[] row = (Object[]) data[i]; Number x = (Number) row[0]; Number y = (Number) row[j + 1]; if (x != null && y != null) dataset.add(x.doubleValue(), y.doubleValue(), dataSeriesLabel); } } return chart; }
From source file:statistic.graph.XYChart.java
public XYChart(String title, String xAxisLabel, String yAxis, XYSeriesCollection collection, boolean linear) { super(title, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), true); this.collection = collection; setBackgroundPaint(Color.WHITE); setTitle(title);/* w w w .j av a 2 s . c o m*/ plot = (XYPlot) getPlot(); plot.setDataset(collection); if (linear) { plot.setRenderer(new DefaultXYItemRenderer()); } else { plot.setRenderer(new XYStepRenderer()); } plot.setOrientation(PlotOrientation.VERTICAL); initXAxis(xAxisLabel); plot.setRangeAxis(new NumberAxis(yAxis)); plot.setBackgroundPaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.WHITE); plot.setRangeGridlinePaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); }
From source file:chart.DualAxis.java
/** * Creates a new demo instance./*from w ww . ja v a 2 s .com*/ * * @param title the frame title. */ public DualAxis(final String title, double[] xData, double[] YDataAnalitic, double[] YDataNumerical) { super(title); final CategoryDataset dataset1 = createDataset1(xData, YDataAnalitic); // create the chart... final JFreeChart chart = ChartFactory.createLineChart("", // chart title "x", // domain axis label "y", // range axis label dataset1, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips? false // URL generator? Not required... ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // chart.getLegend().setAnchor(Legend.SOUTH); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF)); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); final CategoryDataset dataset2 = createDataset2(xData, YDataNumerical); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); //final ValueAxis axis2 = new NumberAxis(""); final ValueAxis axis2 = new NumberAxis(" "); plot.setRangeAxis(1, axis2); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator()); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); // OPTIONAL CUSTOMISATION COMPLETED. // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); // panel.removeAll(); // panel.add(chartPanel); // panel.validate(); }
From source file:e3fraud.gui.GraphingTool.java
public static JFreeChart generateGraph(E3Model model, Resource need, int startValue, int endValue, boolean expected) { //Get list of actors Set<Resource> actors = model.getActors(); //generate a series Map<Resource, XYSeries> actorSeriesMap = model.getTotalForActors(need, startValue, endValue, expected); //for each actor XYSeriesCollection line_chart_dataset = new XYSeriesCollection(); for (Resource actor : actors) { //add it's series to the chart XYSeries series = actorSeriesMap.get(actor); line_chart_dataset.addSeries(series); double slope; if (series.getItemCount() > 1) { slope = (series.getY(0).doubleValue() - series.getY(1).doubleValue()) / (series.getX(0).doubleValue() - series.getX(1).doubleValue()); } else {// w ww . j av a 2s . co m slope = 0; } DecimalFormat df = new DecimalFormat("#.##"); series.setKey(series.getKey() + "\nAvg.\t = \t" + df.format(model.getLastKnownAverages().get(actor)) + "\nSlope\t = \t" + df.format(slope)); } /* Step -2:Define the JFreeChart object to create line chart */ JFreeChart lineChartObject; if (expected) { lineChartObject = ChartFactory.createScatterPlot( "(Ideal) Profit Vs Occurences of \"" + need.getProperty(E3value.e3_has_name).getString() + " \"", "Occurences of \"" + need.getProperty(E3value.e3_has_name).getString() + " \"", "Profit (in Euro)", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false); } else { lineChartObject = ChartFactory.createScatterPlot( "(Non-ideal) Profit Vs Occurences of \"" + need.getProperty(E3value.e3_has_name).getString() + " \"", "Occurences of \"" + need.getProperty(E3value.e3_has_name).getString() + " \"", "Profit (in Euro)", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false); } return lineChartObject; }
From source file:com.opendoorlogistics.components.barchart.BarchartPanel.java
@Override protected JFreeChart createChart(ODLTableReadOnly table, int[] rowFilter) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); if (rowFilter != null) { for (int row : rowFilter) { createRowData(table, dataset, row); }/* w w w. j a va 2 s . c o m*/ } else { int n = table.getRowCount(); for (int row = 0; row < n; row++) { createRowData(table, dataset, row); } } // create the chart... JFreeChart chart = ChartFactory.createBarChart( Strings.isEmpty(config.getTitle()) ? null : config.getTitle(), // chart title config.getXLabel(), // domain axis label config.getYLabel(), // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // set the background color for the chart... chart.setBackgroundPaint(Color.WHITE); // don't show legend for just one series if (((BarchartConfig) config).getSeriesNames().size() <= 1) { chart.removeLegend(); } return chart; }
From source file:user.CreateChart.java
private ImageIcon XYChart(XYSeriesCollection dataset, String name, String X, String Y) { JFreeChart chart = ChartFactory.createXYLineChart(name, X, Y, dataset, PlotOrientation.VERTICAL, true, true, false);/*w ww .j a v a 2s . c o m*/ ImageIcon ii = new ImageIcon(chart.createBufferedImage(592, 500)); return ii; }
From source file:PerformanceGraph.java
/** * Plots the performance graph of the best fitness value so far versus the * number of function calls (NFC)./*from w w w. j av a 2 s.co m*/ * * @param bestFitness A linked hashmap mapping the NFC to the best fitness value * found so far. * @param fitnessFunction The name of the fitness function, used for the title and the * name of the file that is saved, e.g. "De Jong". */ public static void plot(LinkedHashMap<Integer, Double> bestFitness, String fitnessFunction) { /* Create an XYSeries plot */ XYSeries series = new XYSeries("Best Fitness Value Vs. Number of Function Calls"); /* Add the NFC and best fitness value data to the series */ for (Integer NFC : bestFitness.keySet()) { /* Jfreechart crashes if double values are too large! */ if (bestFitness.get(NFC) <= 10E12) { series.add(NFC.doubleValue(), bestFitness.get(NFC).doubleValue()); } } /* Add the x,y series data to the dataset */ XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); /* Plot the data as an X,Y line chart */ JFreeChart chart = ChartFactory.createXYLineChart("Best Fitness Value Vs. Number of Function Calls", "Number of Function Calls (NFC)", "Best Fitness Value", dataset, PlotOrientation.VERTICAL, false, true, false); /* Configure the chart settings such as anti-aliasing, background colour */ chart.setAntiAlias(true); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); plot.setDomainGridlinePaint(Color.black); /* Set the domain range from 0 to NFC */ NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setRange(0.0, ControlVariables.MAX_FUNCTION_CALLS.doubleValue()); /* Logarithmic range axis */ plot.setRangeAxis(new LogAxis()); /* Set the thickness and colour of the lines */ XYItemRenderer renderer = plot.getRenderer(); BasicStroke thickLine = new BasicStroke(3.0f); renderer.setSeriesStroke(0, thickLine); renderer.setPaint(Color.BLACK); /* Display the plot in a JFrame */ ChartFrame frame = new ChartFrame(fitnessFunction + " Best Fitness Value", chart); frame.setVisible(true); frame.setSize(1000, 600); /* Save the plot as an image named after fitness function try { ChartUtilities.saveChartAsJPEG(new File("plots/" + fitnessFunction + ".jpg"), chart, 1600, 900); } catch (IOException e) { e.printStackTrace(); }*/ }