List of usage examples for org.jfree.chart ChartFactory createXYLineChart
public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:graficar.Graficar.java
private void construirGrafica() { chart = ChartFactory.createXYLineChart(titulo, // Ttulo etiquetaX, // Etiqueta Coordenada X etiquetaY, // Etiqueta Coordenada Y dataset, // Datos PlotOrientation.VERTICAL, true, // Muestra la leyenda de los productos (Producto A) false, false);//from w w w . j a va2 s . c o m }
From source file:org.jfree.chart.demo.YIntervalChartDemo2.java
private static JFreeChart createChart(IntervalXYDataset intervalxydataset) { JFreeChart jfreechart = ChartFactory.createXYLineChart("YIntervalChartDemo2", "Date", "Value", intervalxydataset, PlotOrientation.VERTICAL, true, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setDomainPannable(true);//from www. ja va 2 s. c o m xyplot.setRangePannable(true); xyplot.setDomainAxis(new DateAxis("Date")); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setAutoRangeIncludesZero(false); XYErrorRenderer xyerrorrenderer = new XYErrorRenderer(); xyerrorrenderer.setBaseLinesVisible(true); xyerrorrenderer.setUseFillPaint(true); xyerrorrenderer.setBaseFillPaint(Color.white); xyplot.setRenderer(xyerrorrenderer); ChartUtilities.applyCurrentTheme(jfreechart); return jfreechart; }
From source file:Utils.GeneradorDeGraficas.java
public JFreeChart graficarInventario(DeterministaGeneral general, String unidad) { XYDataset dataset;//from w w w . java 2 s . c om if (general.getTipo() == "escasez") dataset = createDatasetEscasez(general); else dataset = createDataset(general); return ChartFactory.createXYLineChart("Perfil del Inventario", "Tiempo en " + unidad, "Unidades", dataset, PlotOrientation.VERTICAL, true, true, false); }
From source file:network.Draw.java
@Override public void run() { JFrame frame = new JFrame(); frame.addWindowListener(new java.awt.event.WindowAdapter() { @Override/*from w ww .ja va 2 s .c o m*/ public void windowClosing(java.awt.event.WindowEvent windowEvent) { isRun = false; } }); while (isRun) { JFreeChart xylineChart; if (method == 0) { System.out.println("hi"); xylineChart = ChartFactory.createXYLineChart("Tempreture", "Time", "Tempreture", createDataset(0), PlotOrientation.VERTICAL, true, true, false); } else { System.out.println("hi"); xylineChart = ChartFactory.createXYLineChart("Tempreture", "Time", "Tempreture", createDataset(1), PlotOrientation.VERTICAL, true, true, false); } final XYPlot plot = xylineChart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesStroke(0, new BasicStroke(1.0f)); plot.setRenderer(renderer); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setSize(700, 500); frame.getContentPane().removeAll(); ChartPanel chartPanel = new ChartPanel(xylineChart); frame.add(chartPanel); frame.setVisible(true); try { Thread.sleep(10000); } catch (InterruptedException ex) { System.out.println(ex); } } }
From source file:loadmaprenderer.ChartTest.java
private JFreeChart makeChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createXYLineChart("Cost/Year Chart", "Year", "Cost", dataset, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = chart.getXYPlot();//from w ww. j a v a 2s . c o m plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLUE); plot.setRangeGridlinePaint(Color.BLUE); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRange(rootPaneCheckingEnabled); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(rootPaneCheckingEnabled); return chart; }
From source file:chartsPK.LineChart.java
private JPanel createChartPanel(String color1, String color2) { XYDataset dataset = createDataset(); boolean showLegend = false; boolean createURL = false; boolean createTooltip = false; JFreeChart chart = ChartFactory.createXYLineChart(getMyTitle(), getAxis().getXLabel(), getAxis().getYLabel(), dataset, PlotOrientation.VERTICAL, true, true, true); Color color;//from www. ja v a 2 s.c om XYPlot plot = (XYPlot) chart.getPlot(); try { Field field = Class.forName("java.awt.Color").getField(color1); color = (Color) field.get(null); } catch (Exception e) { color = null; // Not defined } plot.setBackgroundPaint(color); try { Field field = Class.forName("java.awt.Color").getField(color2); color = (Color) field.get(null); } catch (Exception e) { color = null; // Not defined } chart.setBackgroundPaint(color); for (int i = 0; i < dataSeries.size(); i++) { try { Field field = Class.forName("java.awt.Color").getField(dataSeries.get(i).getColor()); color = (Color) field.get(null); } catch (Exception e) { color = null; // Not defined } plot.getRenderer().setSeriesPaint(i, color); } RectangleEdge p = RectangleEdge.BOTTOM; LegendTitle legend = chart.getLegend(); switch (getLegend().getPosition().toLowerCase()) { case "top": p = RectangleEdge.TOP; break; case "bottom": p = RectangleEdge.BOTTOM; break; case "left": p = RectangleEdge.LEFT; break; case "right": p = RectangleEdge.RIGHT; break; } legend.setPosition(p); try { Field field = Class.forName("java.awt.Color").getField(getLegend().getColor()); color = (Color) field.get(null); } catch (Exception e) { color = null; // Not defined } legend.setBackgroundPaint(color); return new ChartPanel(chart); }
From source file:statistics.distribution.CustomDistribution.java
@Override public JFreeChart getChart() { JFreeChart chart = ChartFactory.createXYLineChart("Workload", "Time (s)", "Timeout (s)", getDataset(), PlotOrientation.VERTICAL, true, true, false); return chart; }
From source file:PerformanceGraph.java
/** * Plots the performance graph of the best fitness value so far versus the * number of function calls (NFC).// w ww . j ava2 s. c o 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(); }*/ }
From source file:edu.emory.library.tast.database.graphs.GraphTypeXY.java
public JFreeChart createChart(Object[] data) { CategoryTableXYDataset dataset = new CategoryTableXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart(null, getSelectedIndependentVariable().getLabel(), TastResource.getText("components_charts_barvalue"), dataset, PlotOrientation.VERTICAL, true, true, false);/* w ww . j a v a2 s .c o m*/ Format formatter = getSelectedIndependentVariable().getFormat(); XYPlot plot = chart.getXYPlot(); if (formatter != null) ((NumberAxis) plot.getDomainAxis()).setNumberFormatOverride((NumberFormat) formatter); 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); } } LegendItemCollection legendItems = chart.getPlot().getLegendItems(); for (int i = 0; i < legendItems.getItemCount(); i++) { LegendItem legendItem = legendItems.get(i); DataSeries dataSearies = (DataSeries) allDataSeries.get(i); if (legendItem.getFillPaint() instanceof Color) { dataSearies.setColor(((Color) legendItem.getFillPaint())); } } return chart; }
From source file:problematica.Graficos.java
/** * /*from w w w . jav a 2 s . 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"); } }