List of usage examples for org.jfree.chart JFreeChart getXYPlot
public XYPlot getXYPlot()
From source file:jyplot.XYErrorBar.ErrorBarDemo.java
private ChartPanel createChartPanel(XYDataset dataset) { JFreeChart chart = ChartFactory.createScatterPlot("Error Bar Demo", // title "x",/*from w w w. j a va2s . co m*/ // x-axis label "y", // y-axis label dataset, // data PlotOrientation.VERTICAL, // create legend? true, // generate tooltips? true, false // generate URLs? ); XYErrorBarRenderer r = new XYErrorBarRenderer(); chart.getXYPlot().setRenderer(r); r.addChangeListener(chart.getXYPlot());// see bug 1177884 ChartPanel chartPanel = new ChartPanel(chart, false, false, false, false, false); chartPanel.setMouseZoomable(true, false); return chartPanel; }
From source file:org.jfree.chart.demo.ChartPanelSerializationTest.java
/** * Creates a chart.//from w w w . j a v a 2s . co m * * @param dataset a dataset. * * @return A chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date", "Price Per Unit", dataset, true, true, false); chart.setBackgroundPaint(Color.white); // final StandardLegend sl = (StandardLegend) chart.getLegend(); // sl.setDisplaySeriesShapes(true); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final XYItemRenderer renderer = plot.getRenderer(); if (renderer instanceof StandardXYItemRenderer) { final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer; rr.setPlotShapes(true); rr.setShapesFilled(true); rr.setItemLabelsVisible(true); } final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); return chart; }
From source file:org.jfree.chart.demo.ScatterPlotDemo3.java
/** * Creates a sample chart.// www .ja v a2 s . c o m * * @param dataset the dataset. * * @return A dataset. */ private JFreeChart createChart(XYDataset dataset) { final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); // final Legend legend = chart.getLegend(); // if (legend instanceof StandardLegend) { // final StandardLegend sl = (StandardLegend) legend; // sl.setDisplaySeriesShapes(true); //} final NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis(); // domainAxis.setAutoRangeIncludesZero(false); return chart; }
From source file:net.vanosten.dings.swing.SummaryView.java
public void displayTimeSeriesChart(final TimeSeriesCollection averageScore, final int maxScoreRange, final TimeSeriesCollection numberOfEntries, final int maxTotalRange) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series", "Date", "Average Score", averageScore, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYItemRenderer renderer1 = plot.getRenderer(); renderer1.setPaint(Color.blue); //axis 1/*from w w w. j a v a 2 s.c o m*/ final NumberAxis axis1 = new NumberAxis("Average Score"); axis1.setLabelPaint(Color.blue); axis1.setTickLabelPaint(Color.blue); axis1.setRange(0.0d, maxScoreRange + 1); plot.setRangeAxis(0, axis1); //axis 2 final NumberAxis axis2 = new NumberAxis("Number of Entries"); axis2.setLabelPaint(Color.red); axis2.setTickLabelPaint(Color.red); axis2.setRange(0.0d, 10 * (((int) (maxTotalRange / 10)) + 1)); plot.setRangeAxis(1, axis2); plot.setDataset(1, numberOfEntries); plot.mapDatasetToRangeAxis(1, 1); final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setPaint(Color.red); plot.setRenderer(1, renderer2); placeChart(chart); }
From source file:chart.XYChart.java
public XYChart(String applicationTitle, String chartTitle, double[] xData, double[] YDataAnalitic, double[] YDataNumerical) { super(applicationTitle); JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle, "", "", createDataset(xData, YDataAnalitic, YDataNumerical), PlotOrientation.VERTICAL, true, true, false); System.out.println("vvvv"); ChartPanel chartPanel = new ChartPanel(xylineChart); chartPanel.setPreferredSize(new java.awt.Dimension(560, 367)); final XYPlot plot = xylineChart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, Color.GREEN); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f)); plot.setRenderer(renderer);//from www . j ava 2s .c o m setContentPane(chartPanel); // panel.removeAll(); // panel.add(chartPanel); // panel.validate(); }
From source file:org.easyrec.controller.StatisticsController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { if (Security.isSignedIn(request)) { int tenant; int month; int year; boolean flot; String actionType = request.getParameter("actionType"); try {/*w w w.j a va2s .c o m*/ tenant = Integer.parseInt(request.getParameter("tenant")); month = Integer.parseInt(request.getParameter("month")); year = Integer.parseInt(request.getParameter("year")); flot = Integer.parseInt(request.getParameter("flot")) != 0; } catch (Exception e) { logger.warn(e); return null; } ModelAndView mav = new ModelAndView(); XYSeriesCollection dataset = new XYSeriesCollection(); FlotDataSet flotDataSet = new FlotDataSet(); Calendar from = Calendar.getInstance(); Calendar to = Calendar.getInstance(); from.set(year, month, Calendar.getInstance().getActualMinimum(Calendar.DAY_OF_MONTH), 0, 0, 0); to.set(year, month, from.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59); Integer actionTypeId = null; Integer assocTypeId = null; if (!Strings.isNullOrEmpty(actionType)) { if ("CLICKS_ON_RECS".equals(actionType)) assocTypeId = 1001; else if ("CLICKS_ON_CHARTS".equals(actionType)) assocTypeId = 998; else actionTypeId = typeMappingService.getIdOfActionType(tenant, actionType); } HashMap<Integer, HashMap<Integer, Integer>> actionBundleMap = statisticsDAO.getActionBundleMap(tenant, from.getTimeInMillis(), to.getTimeInMillis(), actionTypeId, assocTypeId); Iterator<Integer> iterator = actionBundleMap.keySet().iterator(); while (iterator.hasNext()) { actionTypeId = iterator.next(); if (actionTypeId == 1001) actionType = "clicks on recommendations"; else if (actionTypeId == 998) actionType = "clicks on rankings"; else actionType = typeMappingService.getActionTypeById(tenant, actionTypeId).toLowerCase() + " actions"; XYSeries xySeries = new XYSeries(actionType); FlotSeries flotSeries = new FlotSeries(); flotSeries.setTitle(actionType); for (int i = 1; i <= 31; i++) { Integer y = actionBundleMap.get(actionTypeId).get(i); xySeries.add(i, y != null ? y : 0); flotSeries.add(i, y != null ? y : 0); } //mav.addObject("data",flotDataSet.toString()); dataset.addSeries(xySeries); flotDataSet.add(flotSeries); } // create datapoints that are rendered in the clients browser // return array or html side that renders array if (flot) { boolean onlyData = (ServletUtils.getSafeParameter(request, "onlyData", 0) != 0); if (onlyData) { mav.setViewName("flot/dataOutput"); } else { mav.setViewName("flot/flotPlot"); } mav.addObject("data", flotDataSet.toString()); mav.addObject("flotDataSet", flotDataSet.getData()); mav.addObject("noActions", flotDataSet.getData().isEmpty()); return mav; // create a png } else { JFreeChart action_chart = ChartFactory.createXYLineChart("", "actions", "days", dataset, PlotOrientation.VERTICAL, true, // show legend true, // show tooltips false); // show urls XYPlot plot = action_chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setRange(1, 31); plot.setDomainAxis(axis); BufferedImage bi = action_chart.createBufferedImage(300, 200); byte[] bytes = ChartUtilities.encodeAsPNG(bi); if (bytes != null & !flot) { OutputStream os = response.getOutputStream(); response.setContentType("image/png"); response.setContentLength(bytes.length); os.write(bytes); os.close(); } } return null; } else { return Security.redirectHome(request, response); } }
From source file:com.signalcollect.sna.gephiconnectors.SignalCollectGephiConnector.java
/** * Creates the Chart of the Clustering Distribution according to the * calculated distribution/*from www . j av a2s . c o m*/ * * @param clusterDistribution * @return a {@link JFreeChart} containing the distribution of local cluster * coefficients in the graph * @throws IOException */ public JFreeChart createClusterDistributionChart(Map<Double, Integer> clusterDistribution) throws IOException { XYSeries dSeries = new XYSeries("number of occurences"); for (Iterator it = clusterDistribution.entrySet().iterator(); it.hasNext();) { Map.Entry d = (Map.Entry) it.next(); Number x = (Number) d.getKey(); Number y = (Number) d.getValue(); dSeries.add(x, y); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(dSeries); dataset.setAutoWidth(true); JFreeChart chart = ChartFactory.createHistogram("Local Cluster Coefficient Distribution", "Local Cluster Coefficient value", "number of occurences", dataset, PlotOrientation.VERTICAL, true, true, true); XYPlot plot = chart.getXYPlot(); XYBarRenderer renderer0 = new XYBarRenderer(); Font font = new Font("Font", 0, 14); renderer0.setMargin(0.2); renderer0.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); renderer0.setBaseItemLabelsVisible(true); renderer0.setBaseItemLabelFont(font); plot.setDataset(0, dataset); plot.setRenderer(0, renderer0); plot.getRendererForDataset(plot.getDataset(0)).setSeriesPaint(0, Color.BLUE); return chart; }
From source file:bc.ui.swing.charts.LineChart.java
public void setModel(LineVisualModel line) { XYDataset dataset = createDataset(line); JFreeChart chart = ChartFactory.createXYLineChart(line.getTitle(), // chart title line.getDomainAxisLabel(), // x axis label line.getRangeAxisLabel(), // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );//from w w w . j a v a 2 s . c o m chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setSeriesPaint(0, new Color(153, 215, 255)); removeAll(); chartPanel = new ChartPanel(chart); add(chartPanel, BorderLayout.CENTER); }
From source file:chart.XYChart.java
public XYChart(String applicationTitle, String chartTitle, double[] xData, double[] YDataAnalitic, double[] YDataNumerical1, double[] YDataNumerical2) { super(applicationTitle); JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle, "", "", createDatasetForThree(xData, YDataAnalitic, YDataNumerical1, YDataNumerical2), PlotOrientation.VERTICAL, true, true, false); ChartPanel chartPanel = new ChartPanel(xylineChart); chartPanel.setPreferredSize(new java.awt.Dimension(560, 367)); final XYPlot plot = xylineChart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, Color.GREEN); renderer.setSeriesPaint(2, Color.YELLOW); renderer.setSeriesPaint(3, Color.BLUE); renderer.setSeriesStroke(0, new BasicStroke(1.0f)); renderer.setSeriesStroke(1, new BasicStroke(1.0f)); renderer.setSeriesStroke(2, new BasicStroke(1.0f)); renderer.setSeriesStroke(3, new BasicStroke(1.0f)); plot.setRenderer(renderer);//w w w.j a v a 2s .com setContentPane(chartPanel); // panel.removeAll(); // panel.add(chartPanel); // panel.validate(); }
From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo2.java
protected JFreeChart createChart(IntervalXYDataset dataset) { JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, false, rangeLabel, dataset, PlotOrientation.VERTICAL, false, // !legendPanelOn, true, false);/* w w w .java 2 s . c o m*/ // then customise it a little... // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do")); chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setRenderer(new ClusteredXYBarRenderer()); XYItemRenderer renderer = plot.getRenderer(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); // domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // setXSummary(dataset); //X is time renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); return chart; }