List of usage examples for org.jfree.chart JFreeChart addSubtitle
public void addSubtitle(Title subtitle)
From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java
@Override public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); XYDataset dataset = (XYDataset) datasets.getDatasets().get("1"); final JFreeChart sparkLineGraph = ChartFactory.createTimeSeriesChart(null, null, null, dataset, legend, false, false);/* w ww . ja v a 2 s. c om*/ sparkLineGraph.setBackgroundPaint(color); TextTitle title = setStyleTitle(name, styleTitle); sparkLineGraph.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); sparkLineGraph.addSubtitle(subTitle); } sparkLineGraph.setBorderVisible(false); sparkLineGraph.setBorderPaint(Color.BLACK); XYPlot plot = sparkLineGraph.getXYPlot(); plot.setOutlineVisible(false); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setBackgroundPaint(null); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setBackgroundPaint(color); // calculate the last marker color Paint colorLast = getLastPointColor(); // Calculate average, minimum and maximum to draw plot borders. boolean isFirst = true; double avg = 0, min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY; int count = 0; for (int i = 0; i < timeSeries.getItemCount(); i++) { if (timeSeries.getValue(i) != null) { count++; if (isFirst) { min = timeSeries.getValue(i).doubleValue(); max = timeSeries.getValue(i).doubleValue(); isFirst = false; } double n = timeSeries.getValue(i).doubleValue(); //calculate avg, min, max avg += n; if (n < min) min = n; if (n > max) max = n; } } // average avg = avg / (double) count; // calculate min and max between thresholds! boolean isFirst2 = true; double lb = 0, ub = 0; for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) { Double thres = (Double) iterator.next(); if (isFirst2 == true) { ub = thres.doubleValue(); lb = thres.doubleValue(); isFirst2 = false; } if (thres.doubleValue() > ub) ub = thres.doubleValue(); if (thres.doubleValue() < lb) lb = thres.doubleValue(); } plot.getRangeAxis().setRange(new Range(Math.min(lb, min - 2), Math.max(ub, max + 2) + 2)); addMarker(1, avg, Color.GRAY, 0.8f, plot); //addAvaregeSeries(series, plot); addPointSeries(timeSeries, plot); int num = 3; for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) { Double thres = (Double) iterator.next(); TargetThreshold targThres = thresholds.get(thres); Color color = Color.WHITE; if (targThres != null && targThres.getColor() != null) { color = targThres.getColor(); } if (targThres.isVisible()) { addMarker(num++, thres.doubleValue(), color, 0.5f, plot); } } ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setUpperMargin(0.2); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setVisible(false); plot.getRenderer().setSeriesPaint(0, Color.BLACK); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) { public boolean getItemShapeVisible(int _series, int item) { TimeSeriesDataItem tsdi = timeSeries.getDataItem(item); if (tsdi == null) return false; Month period = (Month) tsdi.getPeriod(); int currMonth = period.getMonth(); int currYear = period.getYearValue(); int lastMonthFilled = lastMonth.getMonth(); int lastYearFilled = lastMonth.getYearValue(); boolean isLast = false; if (currYear == lastYearFilled && currMonth == lastMonthFilled) { isLast = true; } return isLast; } }; renderer.setSeriesPaint(0, Color.decode("0x000000")); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(colorLast); renderer.setBaseOutlinePaint(Color.BLACK); renderer.setUseOutlinePaint(true); renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0)); if (wlt_mode.doubleValue() == 0) { renderer.setBaseItemLabelsVisible(Boolean.FALSE, true); } else { renderer.setBaseItemLabelsVisible(Boolean.TRUE, true); renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("{2}", new DecimalFormat("0.###"), new DecimalFormat("0.###")) { public String generateLabel(CategoryDataset dataset, int row, int column) { if (dataset.getValue(row, column) == null || dataset.getValue(row, column).doubleValue() == 0) return ""; String columnKey = (String) dataset.getColumnKey(column); int separator = columnKey.indexOf('-'); String month = columnKey.substring(0, separator); String year = columnKey.substring(separator + 1); int monthNum = Integer.parseInt(month); if (wlt_mode.doubleValue() >= 1 && wlt_mode.doubleValue() <= 4) { if (wlt_mode.doubleValue() == 2 && column % 2 == 0) return ""; Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MONTH, monthNum - 1); SimpleDateFormat dataFormat = new SimpleDateFormat("MMM"); return dataFormat.format(calendar.getTime()); } else return "" + monthNum; } }); } if (wlt_mode.doubleValue() == 3) { renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 2)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 2)); } else if (wlt_mode.doubleValue() == 4) { renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 4)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 4)); } if (legend == true) { LegendItemCollection collection = createThresholdLegend(plot); LegendItem item = new LegendItem("Avg", "Avg", "Avg", "Avg", new Rectangle(10, 10), colorAverage); collection.add(item); plot.setFixedLegendItems(collection); } plot.setRenderer(0, renderer); logger.debug("OUT"); return sparkLineGraph; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.SimpleBar.java
public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1"); PlotOrientation plotOrientation = PlotOrientation.VERTICAL; if (horizontalView) { plotOrientation = PlotOrientation.HORIZONTAL; }/* w w w .j av a 2 s .c o m*/ JFreeChart chart = ChartFactory.createBarChart(name, // chart title categoryLabel, // domain axis label valueLabel, // range axis label dataset, // data plotOrientation, // orientation false, // include legend true, // tooltips? false // URLs? ); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } // set the background color for the chart... chart.setBackgroundPaint(color); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); NumberFormat nf = NumberFormat.getNumberInstance(locale); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setLabelPaint(styleXaxesLabels.getColor()); rangeAxis .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor()); rangeAxis.setUpperMargin(0.10); rangeAxis.setNumberFormatOverride(nf); if (firstAxisLB != null && firstAxisUB != null) { rangeAxis.setLowerBound(firstAxisLB); rangeAxis.setUpperBound(firstAxisUB); } if (rangeIntegerValues == true) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } else rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); if (rangeAxisLocation != null) { if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); } } // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // add CategorySeriesLabelGenerator generator = new StandardCategorySeriesLabelGenerator("{0}"); renderer.setLegendItemLabelGenerator(generator); if (maxBarWidth != null) { renderer.setMaximumBarWidth(maxBarWidth.doubleValue()); } if (showValueLabels) { renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); // if(valueLabelsPosition.equalsIgnoreCase("inside")){ // renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition( // ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT)); // renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition( // ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT)); // } else { // renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition( // ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT)); // renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition( // ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT)); // } } // PROVA LEGENDA if (legend == true) { drawLegend(chart); /*BlockContainer wrapper = new BlockContainer(new BorderArrangement()); wrapper.setFrame(new BlockBorder(1.0, 1.0, 1.0, 1.0)); LabelBlock titleBlock = new LabelBlock("Legend Items:", new Font("SansSerif", Font.BOLD, 12)); title.setPadding(5, 5, 5, 5); wrapper.add(titleBlock, RectangleEdge.TOP); LegendTitle legend = new LegendTitle(chart.getPlot()); BlockContainer items = legend.getItemContainer(); items.setPadding(2, 10, 5, 2); wrapper.add(items); legend.setWrapper(wrapper); if(legendPosition.equalsIgnoreCase("bottom")) legend.setPosition(RectangleEdge.BOTTOM); else if(legendPosition.equalsIgnoreCase("left")) legend.setPosition(RectangleEdge.LEFT); else if(legendPosition.equalsIgnoreCase("right")) legend.setPosition(RectangleEdge.RIGHT); else if(legendPosition.equalsIgnoreCase("top")) legend.setPosition(RectangleEdge.TOP); else legend.setPosition(RectangleEdge.BOTTOM); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); chart.addSubtitle(legend);*/ } int seriesN = dataset.getRowCount(); // the order color vedctor overrides the color map!! if (orderColorVector != null && orderColorVector.size() > 0) { logger.debug("color serie by SERIES_ORDER_COLORS template specification"); for (int i = 0; i < seriesN; i++) { if (orderColorVector.get(i) != null) { Color color = orderColorVector.get(i); renderer.setSeriesPaint(i, color); } } } else if (colorMap != null) { logger.debug("color serie by SERIES_COLORS template specification"); for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getRowKey(i); String labelName = ""; int index = -1; if (seriesCaptions != null && seriesCaptions.size() > 0) { labelName = serieName; serieName = (String) seriesCaptions.get(serieName); index = dataset.getRowIndex(labelName); } else index = dataset.getRowIndex(serieName); Color color = (Color) colorMap.get(serieName); if (color != null) { //renderer.setSeriesPaint(i, color); renderer.setSeriesPaint(index, color); renderer.setSeriesItemLabelFont(i, new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize())); renderer.setSeriesItemLabelPaint(i, defaultLabelsStyle.getColor()); } } } CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setLabelPaint(styleYaxesLabels.getColor()); domainAxis .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setTickLabelPaint(styleYaxesLabels.getColor()); domainAxis.setUpperMargin(0.10); logger.debug("OUT"); return chart; }
From source file:org.jfree.chart.demo.DualAxisDemo1.java
private static JFreeChart createChart() { JFreeChart jfreechart = ChartFactory.createBarChart("Dual Axis Chart", "Category", "Value", createDataset1(), PlotOrientation.VERTICAL, false, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(new Color(238, 238, 255)); categoryplot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryDataset categorydataset = createDataset2(); categoryplot.setDataset(1, categorydataset); categoryplot.mapDatasetToRangeAxis(1, 1); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); NumberAxis numberaxis = new NumberAxis("Secondary"); categoryplot.setRangeAxis(1, numberaxis); LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(); lineandshaperenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); categoryplot.setRenderer(1, lineandshaperenderer); categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); LegendTitle legendtitle = new LegendTitle(categoryplot.getRenderer(0)); legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendtitle.setFrame(new BlockBorder()); LegendTitle legendtitle1 = new LegendTitle(categoryplot.getRenderer(1)); legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendtitle1.setFrame(new BlockBorder()); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); blockcontainer.add(legendtitle, RectangleEdge.LEFT); blockcontainer.add(legendtitle1, RectangleEdge.RIGHT); blockcontainer.add(new EmptyBlock(2000D, 0.0D)); CompositeTitle compositetitle = new CompositeTitle(blockcontainer); compositetitle.setPosition(RectangleEdge.BOTTOM); jfreechart.addSubtitle(compositetitle); return jfreechart; }
From source file:org.martus.client.swingui.actions.ActionMenuCharts.java
private void configureBarChartPlot(JFreeChart barChart) { CategoryPlot plot = (CategoryPlot) barChart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); TickUnitSource units = NumberAxis.createIntegerTickUnits(); rangeAxis.setStandardTickUnits(units); CategoryAxis domainAxis = plot.getDomainAxis(); CategoryLabelPositions newPositions = CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0); domainAxis.setCategoryLabelPositions(newPositions); barChart.addSubtitle(new TextTitle(getLocalization().getFieldLabel("ChartSelectedBulletinsDisclaimerBar"), FontHandler.getDefaultFont(), TextTitle.DEFAULT_TEXT_PAINT, RectangleEdge.BOTTOM, TextTitle.DEFAULT_HORIZONTAL_ALIGNMENT, TextTitle.DEFAULT_VERTICAL_ALIGNMENT, TextTitle.DEFAULT_PADDING)); }
From source file:apidemo.PanScrollZoomDemo.java
/** * Creates a sample chart.//from w ww . ja v a2 s. com * * @return a sample chart. */ private JFreeChart createChart() { final XYSeriesCollection primaryJFreeColl = new XYSeriesCollection(); final XYSeries left1 = new XYSeries("Left 1"); left1.add(1, 2); left1.add(2.8, 5.9); left1.add(3, null); left1.add(3.4, 2); left1.add(5, -1); left1.add(7, 1); primaryJFreeColl.addSeries(left1); final XYSeriesCollection secondaryJFreeColl = new XYSeriesCollection(); final XYSeries right1 = new XYSeries("Right 1"); right1.add(3.5, 2.2); right1.add(1.2, 1.3); right1.add(5.7, 4.1); right1.add(7.5, 7.4); secondaryJFreeColl.addSeries(right1); final NumberAxis xAxis = new NumberAxis("X"); xAxis.setAutoRangeIncludesZero(false); xAxis.setAutoRangeStickyZero(false); final NumberAxis primaryYAxis = new NumberAxis("Y1"); primaryYAxis.setAutoRangeIncludesZero(false); primaryYAxis.setAutoRangeStickyZero(false); // create plot final XYItemRenderer y1Renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES); y1Renderer.setSeriesPaint(0, Color.blue); y1Renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); final XYPlot xyPlot = new XYPlot(primaryJFreeColl, xAxis, primaryYAxis, y1Renderer); // 2nd y-axis final NumberAxis secondaryYAxis = new NumberAxis("Y2"); secondaryYAxis.setAutoRangeIncludesZero(false); secondaryYAxis.setAutoRangeStickyZero(false); xyPlot.setRangeAxis(1, secondaryYAxis); xyPlot.setDataset(1, secondaryJFreeColl); xyPlot.mapDatasetToRangeAxis(1, 1); xyPlot.mapDatasetToDomainAxis(1, 1); final XYItemRenderer y2Renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES); y2Renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); xyPlot.setRenderer(1, y2Renderer); // set some fixed y-dataranges and remember them // because default chartPanel.autoRangeBoth() // would destroy them ValueAxis axis = xyPlot.getRangeAxis(); this.primYMinMax[0] = -5; this.primYMinMax[1] = 15; axis.setLowerBound(this.primYMinMax[0]); axis.setUpperBound(this.primYMinMax[1]); axis = xyPlot.getRangeAxis(1); this.secondYMinMax[0] = -1; this.secondYMinMax[1] = 10; axis.setLowerBound(this.secondYMinMax[0]); axis.setUpperBound(this.secondYMinMax[1]); // Title + legend final String title = "To pan in zoom mode hold right mouse pressed"; final JFreeChart ret = new JFreeChart(title, null, xyPlot, true); final TextTitle textTitle = new TextTitle("(but you can only pan if the chart was zoomed before)"); ret.addSubtitle(textTitle); return ret; }
From source file:hr.restart.util.chart.ChartXY.java
/** * Creates a PIE CHART//from ww w . jav a2s. c om * @param dataset The org.jfree.data.PieDataset * @param title The title * @return org.jfree.chart.JFreeChart */ private JFreeChart createPieChart(final PieDataset dataset, String title) { final JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data false, // include legend true, false); chart.setBackgroundPaint(Color.white); Plot plot = chart.getPlot(); // the subtitle from the combobox if (jcb != null) chart.addSubtitle(new TextTitle(jcb.getSelectedItem().toString())); //subtitles setted by the user. if (getSubtitles() != null) for (int i = 0; i < getSubtitles().size(); i++) { chart.addSubtitle(new TextTitle(getSubtitles().get(i).toString())); } final PiePlot piePlot = (PiePlot) plot; piePlot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); piePlot.setNoDataMessage("NO DATA!"); piePlot.setCircular(false); piePlot.setLabelLinkPaint(Color.red); piePlot.setLabelGap(0.02); return chart; }
From source file:unalcol.termites.boxplots.BestAgentsPercentageInfoCollected.java
/** * Creates a new demo.//from ww w. j ava2 s . co m * * @param title the frame title. * @param pf */ public BestAgentsPercentageInfoCollected(final String title, ArrayList<Double> pf) { super(title); String sDirectorio = experimentsDir; Hashtable<String, List> info = new Hashtable(); //String[] aMode = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4"}; /*for (String mode : aMode) { info.put(mode, new ArrayList()); }*/ createSampleDataset(pf, info); AddDataFailingExperiments(sDirectorio, pf, info); final BoxAndWhiskerCategoryDataset dataset = addDataSet(info); final CategoryAxis xAxis = new CategoryAxis(""); //final NumberAxis yAxis = new NumberAxis("Information Collected"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 13); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Information Collected " + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("BestAgentsPercentageInfoCollected" + pf + mazeMode + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 350, 350, null); } catch (FileNotFoundException ex) { Logger.getLogger(BestAgentsPercentageInfoCollected.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(BestAgentsPercentageInfoCollected.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:unalcol.termites.boxplots.BestAgentsRoundInfoCollected.java
/** * Creates a new demo./*from w w w. j ava 2s . c om*/ * * @param title the frame title. * @param pf */ public BestAgentsRoundInfoCollected(final String title, ArrayList<Double> pf) { super(title); String sDirectorio = experimentsDir; Hashtable<String, List> info = new Hashtable(); /*for (String mode : aMode) { info.put(mode, new ArrayList()); }*/ createSampleDataset(pf, info); AddDataFailingExperiments(sDirectorio, pf, info); final BoxAndWhiskerCategoryDataset dataset = addDataSet(info); System.out.println("info" + info); final CategoryAxis xAxis = new CategoryAxis(""); //final NumberAxis yAxis = new NumberAxis("Information Collected"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 13); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Round of Best Agents " + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("BestAgentsRound" + pf + mazeMode + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 450, 350, null); } catch (FileNotFoundException ex) { Logger.getLogger(BestAgentsRoundInfoCollected.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(BestAgentsRoundInfoCollected.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.fullerton.ldvservlet.SrcList.java
private PageItem makePlots(ArrayList<ChanSourceData> csdList, String name, Database db, Page vpage, ViewUser vuser, String contextPath) throws WebUtilException, LdvTableException { PageItemList ret = new PageItemList(); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Date/Time (UTC)")); plot.setGap(10.0);/*from w ww . j ava 2 s. c o m*/ String baseName = ""; StringBuilder errors = new StringBuilder(); int plotNum = 0; Color[] colors = { Color.RED, Color.BLUE, Color.MAGENTA, Color.ORANGE, Color.DARK_GRAY, Color.GREEN }; boolean gotData = false; TimeInterval timeRange = null; for (ChanSourceData csd : csdList) { TimeInterval ti = csd.getTimeRange(); if (ti != null) { if (timeRange == null) { timeRange = ti; } else if (timeRange.overlaps(ti)) { timeRange = timeRange.mergeIntervals(ti); } else if (ti.getStartGps() < timeRange.getStartGps()) { timeRange.setStartGps(ti.getStartGps()); } else if (ti.getStopGps() > timeRange.getStopGps()) { timeRange.setStopGps(ti.getStopGps()); } } } if (timeRange != null) { for (ChanSourceData csd : csdList) { baseName = csd.getChanInfo().getBaseName(); TimeSeriesCollection mtds = new TimeSeriesCollection(); String server = csd.getChanInfo().getServer().replace(".caltech.edu", ""); String legend = String.format("Type: %1$s at %2$s", csd.getChanInfo().getcType(), server); TimeSeries ts; double[][] data = csd.getGraphData(); if (data == null) { data = new double[2][2]; data[0][0] = timeRange.getStartGps(); data[1][0] = timeRange.getStopGps(); data[0][1] = data[1][1] = 0; errors.append("Error getting data for: ").append(legend).append("<br>"); } else { gotData = true; } for (double[] d : data) { d[1] = d[1] <= 1 ? 1 : d[1]; } ts = getTimeSeries(data, legend); mtds.addSeries(ts); XYAreaRenderer renderer = new XYAreaRenderer(XYAreaRenderer.AREA); BasicStroke str = new BasicStroke(2); int colorIdx = plotNum % colors.length; Color color = colors[colorIdx]; NumberAxis yAxis = new NumberAxis("% Avail"); yAxis.setRange(0, 100); renderer.setBaseFillPaint(color); renderer.setSeriesFillPaint(0, Color.WHITE); renderer.setBaseStroke(str); renderer.setUseFillPaint(true); XYPlot subplot = new XYPlot(mtds, null, yAxis, renderer); plot.add(subplot); plotNum++; } ChartPanel cpnl; JFreeChart chart; String gtitle = String.format("Available data for %1$s ", baseName); String subTitleTxt = String.format("From %1$s to %2$s", TimeAndDate.gpsAsUtcString(timeRange.getStartGps()), TimeAndDate.gpsAsUtcString(timeRange.getStopGps())); plot.setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart(gtitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.addSubtitle(new TextTitle(subTitleTxt)); cpnl = new ChartPanel(chart, false, false, false, false, false); PluginSupport psupport = new PluginSupport(); psupport.setup(db, vpage, vuser); int imgId; PageItemImage img = null; try { psupport.setSize(800, 600); imgId = psupport.saveImageAsPNG(cpnl); String url = String.format("%1$s/view?act=getImg&imgId=%2$d", contextPath, imgId); img = new PageItemImage(url, "availability", baseName); } catch (SQLException | IOException | NoSuchAlgorithmException ex) { String ermsg = String.format("Error creating or saving image: %1$s - $2$s", ex.getClass().getSimpleName(), ex.getLocalizedMessage()); errors.append(ermsg); } if (errors.length() > 0) { ret.add(errors.toString()); } if (img != null) { ret.add(img); } } else { ret.add("No data to plot."); } return ret; }
From source file:sentimentanalyzer.ChartController.java
public void createAndPopulatePieChart__TESTER(JPanel pnlPieChart) { DefaultPieDataset data = new DefaultPieDataset(); data.setValue(Pos, 0 /*count for 1 */); data.setValue(Neu, 0 /*count for 0 */); data.setValue(Neg, 0 /*count for -1 */); JFreeChart chart = ChartFactory.createPieChart("Sent. Distr. for Testing", data, false, // legend? false, // tooltips? false // URLs? );//from w w w .ja va2 s . c o m ChartPanel CP = new ChartPanel(chart); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("Pie chart is not available", Color.LIGHT_GRAY); plot.setExplodePercent(Pos, 0.025); plot.setExplodePercent(Neg, 0.025); plot.setExplodePercent(Neu, 0.025); //Customize PieChart to show absolute values and percentages; PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0.00%")); plot.setLabelGenerator(gen); TextTitle legendText = new TextTitle("The total number of tweets: "); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); pnlPieChart.setLayout(new java.awt.BorderLayout()); pnlPieChart.add(CP, BorderLayout.CENTER); }