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:networkmonitor.MainIBMApplicationForm.java
/** * Creates a chart.//from ww w . j av a 2 s. co m * * @param dataset the data for the chart. * * @return a chart. */ private JFreeChart createChart(final XYDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createXYLineChart( // put a big space or it'll overlap with the statistics of data... :) "B/W Usage in KBps: ", // chart title "Seconds ", // x axis label " Usage", // y axis label dataset, // data PlotOrientation.VERTICAL, // Plot Orientation.. it means grap will show you statistics vertically true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // Background color of chart/outside plot........ chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final XYPlot plot = chart.getXYPlot(); //plot background color inside the graph.... plot.setBackgroundPaint(Color.orange); //org.jfree.chart.plot.XYPlot; //Plot vertical inner graph line..... plot.setDomainGridlinePaint(Color.red); //plot horizontal inner graph line..... plot.setRangeGridlinePaint(Color.blue); //Sets the renderer for the PGraphics object that is used for drawing to... final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); // it used to show the up and down connecting line will show or not(RED LINE of graph) renderer.setSeriesLinesVisible(1, true); //renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer);//it used to show the up and down block of data(RED Block Of GRAPH) //......................................... //..... change the auto tick unit selection to integer units only //LIMIT OF X and Y axis GRAPH SIDE DATA (usages/second) //.....if I unhide these then only integer number show in X axis,it avoid floating point /*final NumberAxis domainAxis = new NumberAxis("X-Axis"); domainAxis.setRange(0.00,1.00); domainAxis.setTickUnit(new NumberTickUnit(0.1)); final NumberAxis rangeAxis = new NumberAxis("Y-Axis"); rangeAxis.setRange(0.0,1.0); rangeAxis.setTickUnit(new NumberTickUnit(0.0));*/ //usases(X axis) integer data counting //final NumberAxis rangeAxis = (NumberAxis) //plot.getRangeAxis(); // rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. //.............................................. return chart; }
From source file:fr.irit.smac.libs.tooling.plot.server.AgentPlotChart.java
public JFreeChart getJFreeChart() { if (chart == null) { switch (chartType) { case LINE: chart = ChartFactory.createXYLineChart("", // chart // title "X", // x axis label "Y", // y axis label getDataset(), // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );//from w ww. ja va 2s . c om break; case PLOT: chart = ChartFactory.createScatterPlot("", // chart // title "X", // x axis label "Y", // y axis label getDataset(), // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); break; } XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.black); } return chart; }
From source file:examples.monalisa.gui.GeneticDrawingView.java
/** This method is called from within the constructor to * initialize the form.//from ww w . jav a 2 s. c o m * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { mainPanel = new javax.swing.JPanel(); chooseImage = new javax.swing.JButton(); startEvolution = new javax.swing.JToggleButton(); targetImageLabel = new javax.swing.JLabel(); JFreeChart chart = ChartFactory.createXYLineChart("Fitness versus Generation", "Generation", "Fitness", new XYSeriesCollection(new XYSeries("")), org.jfree.chart.plot.PlotOrientation.VERTICAL, false, false, false); chartPanel = new ChartPanel(chart); menuBar = new javax.swing.JMenuBar(); javax.swing.JMenu fileMenu = new javax.swing.JMenu(); javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem(); javax.swing.JMenu helpMenu = new javax.swing.JMenu(); javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem(); mainPanel.setName("mainPanel"); // NOI18N javax.swing.ActionMap actionMap = org.jdesktop.application.Application .getInstance(examples.monalisa.gui.GeneticDrawingApp.class).getContext() .getActionMap(GeneticDrawingView.class, this); chooseImage.setAction(actionMap.get("chooseImage")); // NOI18N org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application .getInstance(examples.monalisa.gui.GeneticDrawingApp.class).getContext() .getResourceMap(GeneticDrawingView.class); chooseImage.setText(resourceMap.getString("chooseImage.text")); // NOI18N chooseImage.setName("chooseImage"); // NOI18N startEvolution.setAction(actionMap.get("startEvolution")); // NOI18N startEvolution.setText(resourceMap.getString("startEvolution.text")); // NOI18N startEvolution.setName("startEvolution"); // NOI18N targetImageLabel.setIcon(resourceMap.getIcon("targetImageLabel.icon")); // NOI18N targetImageLabel.setText(resourceMap.getString("targetImageLabel.text")); // NOI18N targetImageLabel.setName("targetImageLabel"); // NOI18N chartPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); chartPanel.setName("chartPanel"); // NOI18N org.jdesktop.layout.GroupLayout chartPanelLayout = new org.jdesktop.layout.GroupLayout(chartPanel); chartPanel.setLayout(chartPanelLayout); chartPanelLayout.setHorizontalGroup(chartPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(0, 399, Short.MAX_VALUE)); chartPanelLayout.setVerticalGroup(chartPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(0, 234, Short.MAX_VALUE)); org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup(mainPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(mainPanelLayout.createSequentialGroup().add(mainPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(mainPanelLayout.createSequentialGroup().add(47, 47, 47).add(chooseImage) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED).add(startEvolution) .add(38, 38, 38)) .add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup() .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(targetImageLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(80, 80, 80))) .add(chartPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); mainPanelLayout.setVerticalGroup(mainPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup() .addContainerGap() .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(org.jdesktop.layout.GroupLayout.LEADING, chartPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(mainPanelLayout.createSequentialGroup() .add(targetImageLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(mainPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(startEvolution).add(chooseImage)))) .addContainerGap())); chooseImage.getAccessibleContext() .setAccessibleName(resourceMap.getString("jButton1.AccessibleContext.accessibleName")); // NOI18N menuBar.setName("menuBar"); // NOI18N fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N fileMenu.setName("fileMenu"); // NOI18N exitMenuItem.setAction(actionMap.get("quit")); // NOI18N exitMenuItem.setName("exitMenuItem"); // NOI18N fileMenu.add(exitMenuItem); menuBar.add(fileMenu); helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N helpMenu.setName("helpMenu"); // NOI18N aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N aboutMenuItem.setName("aboutMenuItem"); // NOI18N helpMenu.add(aboutMenuItem); menuBar.add(helpMenu); setComponent(mainPanel); setMenuBar(menuBar); }
From source file:src.examples.monalisa.gui.GeneticDrawingView.java
/** This method is called from within the constructor to * initialize the form./*from w w w. j a va2s.co m*/ * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { mainPanel = new javax.swing.JPanel(); chooseImage = new javax.swing.JButton(); startEvolution = new javax.swing.JToggleButton(); targetImageLabel = new javax.swing.JLabel(); JFreeChart chart = ChartFactory.createXYLineChart("Fitness versus Generation", "Generation", "Fitness", new XYSeriesCollection(new XYSeries("")), org.jfree.chart.plot.PlotOrientation.VERTICAL, false, false, false); chartPanel = new ChartPanel(chart); menuBar = new javax.swing.JMenuBar(); javax.swing.JMenu fileMenu = new javax.swing.JMenu(); javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem(); javax.swing.JMenu helpMenu = new javax.swing.JMenu(); javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem(); mainPanel.setName("mainPanel"); // NOI18N javax.swing.ActionMap actionMap = org.jdesktop.application.Application .getInstance(src.examples.monalisa.gui.GeneticDrawingApp.class).getContext() .getActionMap(GeneticDrawingView.class, this); chooseImage.setAction(actionMap.get("chooseImage")); // NOI18N org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application .getInstance(src.examples.monalisa.gui.GeneticDrawingApp.class).getContext() .getResourceMap(GeneticDrawingView.class); chooseImage.setText(resourceMap.getString("chooseImage.text")); // NOI18N chooseImage.setName("chooseImage"); // NOI18N startEvolution.setAction(actionMap.get("startEvolution")); // NOI18N startEvolution.setText(resourceMap.getString("startEvolution.text")); // NOI18N startEvolution.setName("startEvolution"); // NOI18N targetImageLabel.setIcon(resourceMap.getIcon("targetImageLabel.icon")); // NOI18N targetImageLabel.setText(resourceMap.getString("targetImageLabel.text")); // NOI18N targetImageLabel.setName("targetImageLabel"); // NOI18N chartPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); chartPanel.setName("chartPanel"); // NOI18N org.jdesktop.layout.GroupLayout chartPanelLayout = new org.jdesktop.layout.GroupLayout(chartPanel); chartPanel.setLayout(chartPanelLayout); chartPanelLayout.setHorizontalGroup(chartPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(0, 399, Short.MAX_VALUE)); chartPanelLayout.setVerticalGroup(chartPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(0, 234, Short.MAX_VALUE)); org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup(mainPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(mainPanelLayout.createSequentialGroup().add(mainPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(mainPanelLayout.createSequentialGroup().add(47, 47, 47).add(chooseImage) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED).add(startEvolution) .add(38, 38, 38)) .add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup() .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(targetImageLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(80, 80, 80))) .add(chartPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); mainPanelLayout.setVerticalGroup(mainPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup() .addContainerGap() .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(org.jdesktop.layout.GroupLayout.LEADING, chartPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(mainPanelLayout.createSequentialGroup() .add(targetImageLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(mainPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(startEvolution).add(chooseImage)))) .addContainerGap())); chooseImage.getAccessibleContext() .setAccessibleName(resourceMap.getString("jButton1.AccessibleContext.accessibleName")); // NOI18N menuBar.setName("menuBar"); // NOI18N fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N fileMenu.setName("fileMenu"); // NOI18N exitMenuItem.setAction(actionMap.get("quit")); // NOI18N exitMenuItem.setName("exitMenuItem"); // NOI18N fileMenu.add(exitMenuItem); menuBar.add(fileMenu); helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N helpMenu.setName("helpMenu"); // NOI18N aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N aboutMenuItem.setName("aboutMenuItem"); // NOI18N helpMenu.add(aboutMenuItem); menuBar.add(helpMenu); setComponent(mainPanel); setMenuBar(menuBar); }
From source file:org.keycloak.testsuite.util.Timer.java
private void saveChart(String op) { XYSeries series = new XYSeries(op); int i = 0;/*from w w w. j ava2 s . com*/ for (Long duration : stats.get(op)) { series.add(++i, duration); } final XYSeriesCollection data = new XYSeriesCollection(series); final JFreeChart chart = ChartFactory.createXYLineChart(op, "Operations", "Duration (ms)", data, PlotOrientation.VERTICAL, true, true, false); try { ChartUtilities.saveChartAsPNG(new File(CHARTS_DIR, op.replace(" ", "_") + ".png"), chart, 640, 480); } catch (IOException ex) { log.warn("Unable to save chart for operation '" + op + "'."); } }
From source file:sim.app.sugarscape.Charts.java
JFreeChart createGiniChart() { JFreeChart chart3 = ChartFactory.createXYLineChart("Lorenz Curve", "Population Percentage", "Percentage of Total Wealth", new XYSeriesCollection(model.lorenz_curve), PlotOrientation.VERTICAL, true, true, false);/*from w w w.jav a2 s. c o m*/ XYPlot plot = chart3.getXYPlot(); ValueAxis yAxis = plot.getRangeAxis(); //xAxis.setFixedDimension(100); yAxis.setFixedDimension(1.0); //yAxis.setRange(0,1); ValueAxis xAxis = plot.getDomainAxis(); xAxis.setFixedDimension(50); //StandardXYItemRenderer XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, Color.black); NumberAxis axis2 = new NumberAxis("Average Agent Vision"); //axis2.setAutoRangeIncludesZero(false); axis2.setRange(0, 12); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); //XYSeriesCollection vision = new XYSeriesCollection(lorenz_agent_vision); //plot.setDataset(1, vision); return chart3; }
From source file:com.epiq.bitshark.ui.TimeDomainPanel.java
/** * Initializes the graph/*w w w . j a va 2 s .co m*/ */ private void initGraph() { dataset = new XYSeriesCollection(); realSeries = new BasicSeries("Real"); imaginarySeries = new BasicSeries("Imaginary"); dataset.addSeries(realSeries); dataset.addSeries(imaginarySeries); graph = ChartFactory.createXYLineChart(null, // no title "", // no x-axis label "", // no y-axis label dataset, // data PlotOrientation.VERTICAL, false, // no legend false, // no tooltips false // no URLs ); graph.setBorderVisible(false); graph.setPadding(new RectangleInsets(-5, -5, 0, -7)); graph.setBackgroundPaint(null); graph.setAntiAlias(true); plot = (XYPlot) graph.getPlot(); plot.setBackgroundAlpha(0.0f); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(false); renderer.setBaseShapesFilled(true); renderer.setSeriesPaint(0, I_COLOR); renderer.setSeriesPaint(1, Q_COLOR); } // X-axis setup plot.getDomainAxis().setAutoRange(false); plot.getDomainAxis().setVisible(true); plot.getDomainAxis().setRange(0, FMCUartClient.BLOCK_SIZE - 1); // Y-axis setup plot.getRangeAxis().setAutoRange(false); plot.getRangeAxis().setVisible(true); plot.getRangeAxis().setUpperBound(Math.pow(2, 13)); plot.getRangeAxis().setLowerBound(-Math.pow(2, 13)); // setup chart panel chartPanel = new ChartPanel(graph, false); chartPanel.setMouseZoomable(false); chartPanel.setOpaque(false); chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); chartPanel.setMinimumDrawWidth(0); chartPanel.setMinimumDrawHeight(0); chartPanel.setDomainZoomable(true); // mouse wheel zooming chartPanel.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int clicks = e.getWheelRotation(); plot.getRangeAxis().setUpperBound(plot.getRangeAxis().getUpperBound() - (clicks * 100)); plot.getRangeAxis().setLowerBound(plot.getRangeAxis().getLowerBound() + (clicks * 100)); } }); }
From source file:org.samjoey.graphing.GraphUtility.java
public static void createGraphs(LinkedList<Game> games) { HashMap<String, XYSeriesCollection> datasets = new HashMap<>(); for (Game game : games) { for (String key : game.getVarData().keySet()) { if (datasets.containsKey(key)) { try { datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } catch (Exception e) { }// ww w . j av a 2 s. co m } else { datasets.put(key, new XYSeriesCollection()); datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } } } for (String key : datasets.keySet()) { JFrame f = new JFrame(); JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title "X", // x axis label "Y", // y axis label datasets.get(key), // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); XYItemRenderer rend = plot.getRenderer(); for (int i = 0; i < games.size(); i++) { Game g = games.get(i); if (g.getWinner() == 1) { rend.setSeriesPaint(i, Color.RED); } if (g.getWinner() == 2) { rend.setSeriesPaint(i, Color.BLACK); } if (g.getWinner() == 0) { rend.setSeriesPaint(i, Color.PINK); } } ChartPanel chartPanel = new ChartPanel(chart); f.setContentPane(chartPanel); f.pack(); RefineryUtilities.centerFrameOnScreen(f); f.setVisible(true); } }
From source file:Methods.CalculusBisection.java
public static ChartPanel createChartBisection(XYDataset datasetFunction) {// Method that populates and returns a Chart Pannel object, uses an entering paramether for the equation dataset and a global variable for the iteration points data set datasetPointsBisection();// w ww.ja v a2s. co m JFreeChart chart = ChartFactory.createXYLineChart("Equation Chart", "X Axys", "Y Axys", datasetFunction, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();//declaring a renderer used to plot more than one datatset on the table plot.setDataset(1, datasetPoints); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); plot.setRenderer(1, renderer); return new ChartPanel(chart); }
From source file:org.bench4Q.console.ui.section.P_WIRTSection.java
/** * print out a WIRT picture.//from ww w .jav a2 s . c om * * @return */ public JPanel printWIRTPic() { wirtCDFPrepare(); DefaultXYDataset ds = new DefaultXYDataset(); ds.addSeries("test", result); JFreeChart chart = ChartFactory.createXYLineChart("WIRT CDF", "time (ms)", "percent", ds, PlotOrientation.VERTICAL, false, false, false); final XYPlot plot = chart.getXYPlot(); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.setRangeCrosshairLockedOnData(true); plot.setBackgroundPaint(Color.WHITE); plot.setRangeCrosshairVisible(true); final ChartPanel chartPanel = new ChartPanel(chart); return chartPanel; }