List of usage examples for org.jfree.chart JFreeChart removeLegend
public void removeLegend()
From source file:KIDLYFactory.java
/** * Creates a chart that displays multiple pie plots. The chart object * returned by this method uses a {@link MultiplePiePlot} instance as the * plot.// w w w . j a v a 2 s .com * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset (<code>null</code> permitted). * @param order the order that the data is extracted (by row or by column) * (<code>null</code> not permitted). * @param legend include a legend? * @param tooltips generate tooltips? * @param urls generate URLs? * * @return A chart. */ public static JFreeChart createMultiplePieChart3D(String title, CategoryDataset dataset, TableOrder order, boolean legend, boolean tooltips, boolean urls) { if (order == null) { throw new IllegalArgumentException("Null 'order' argument."); } MultiplePiePlot plot = new MultiplePiePlot(dataset); plot.setDataExtractOrder(order); plot.setBackgroundPaint(null); plot.setOutlineStroke(null); JFreeChart pieChart = new JFreeChart(new PiePlot3D(null)); TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12)); seriesTitle.setPosition(RectangleEdge.BOTTOM); pieChart.setTitle(seriesTitle); pieChart.removeLegend(); pieChart.setBackgroundPaint(null); plot.setPieChart(pieChart); if (tooltips) { PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator(); PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); pp.setToolTipGenerator(tooltipGenerator); } if (urls) { PieURLGenerator urlGenerator = new StandardPieURLGenerator(); PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); pp.setURLGenerator(urlGenerator); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:com.hello2morrow.sonargraph.jenkinsplugin.model.AbstractPlot.java
/** * Creates a chart for a Sonargraph metric * @param categoryName Name for the X-Axis, representing a category * @return Chart built with the given parameters. */// w w w . j a v a 2s . c o m public final JFreeChart createXYChart(SonargraphMetrics metric, String categoryName, int maximumNumberOfDataPoints, boolean hideLegend) { XYDataset dataset = null; try { dataset = createXYDataset(metric, maximumNumberOfDataPoints); } catch (IOException ioe) { SonargraphLogger.INSTANCE.log(Level.SEVERE, "Failed to read metrics from data file '" + m_datasetProvider.getStorageName() + "'"); } JFreeChart chart = createChartInternal(metric.getDescription(), categoryName, metric.getShortDescription(), dataset); XYPlot plot = (XYPlot) chart.getPlot(); int dataPoints = 0; if (dataset == null) { plot.setNoDataMessage( "There was an error loading data for metric '" + metric.getShortDescription() + "'"); } else { for (int i = 0; i < dataset.getSeriesCount(); i++) { dataPoints += dataset.getItemCount(i); } if (dataPoints == 0) { plot.setNoDataMessage("No data found for metric '" + metric.getShortDescription() + "'"); } } if ((dataset == null) || (dataPoints == 0)) { plot.setNoDataMessagePaint(Color.RED); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); } applyRendering(plot); setRangeAxis(metric.isNaturalNumber(), plot); applyStandardPlotColors(plot); if (hideLegend) { chart.removeLegend(); } return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.CategoryStepChartDemo1.java
/** * Creates a chart./*from w ww. j av a2 s .c o m*/ * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { CategoryItemRenderer renderer = new CategoryStepRenderer(true); CategoryAxis domainAxis = new CategoryAxis(domainLabel); NumberAxis rangeAxis = new NumberAxis(rangeLabel); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(chartTitle, plot); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); AbstractCategoryItemRenderer renderer2 = (AbstractCategoryItemRenderer) plot.getRenderer(); renderer2.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.addCategoryLabelToolTip("Type 1", "The first type."); domainAxis.addCategoryLabelToolTip("Type 2", "The second type."); domainAxis.addCategoryLabelToolTip("Type 3", "The third type."); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. setCategorySummary(dataset); if (legendPanelOn) chart.removeLegend(); return chart; }
From source file:Applet.EmbeddedChart.java
/** * Creates a chart./* www. jav a2 s. c o m*/ * * @param dataset * the data for the chart. * * @return a chart. */ private JFreeChart createChart(final XYDataset dataset, String title, boolean gofr) { // create the chart... final JFreeChart chart = ChartFactory.createXYLineChart(null, // chart // title "Radial Distance, r/\u03c3", // x axis label title, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); chart.getLegend().setPosition(RectangleEdge.RIGHT); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // get a reference to the plot for further customisation... final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYTitleAnnotation xyta = new XYTitleAnnotation(0.98, 0.98, chart.getLegend(), RectangleAnchor.TOP_RIGHT); chart.removeLegend(); plot.addAnnotation(xyta); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); for (int i = 0; i < 2; i++) { renderer.setSeriesPaint(i * 6 + 0, new Color(255, 0, 0)); renderer.setSeriesPaint(i * 6 + 1, new Color(0, 0, 255)); renderer.setSeriesPaint(i * 6 + 2, new Color(0, 139, 0)); renderer.setSeriesPaint(i * 6 + 3, new Color(255, 165, 0)); renderer.setSeriesPaint(i * 6 + 4, new Color(255, 0, 255)); renderer.setSeriesPaint(i * 6 + 5, new Color(0, 0, 0)); renderer.setSeriesStroke(i * 6 + 0, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 10.0f }, 0.0f)); renderer.setSeriesStroke(i * 6 + 1, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 50.0f, 2.0f }, 0.0f)); renderer.setSeriesStroke(i * 6 + 2, new BasicStroke(1.3f, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_MITER, 10.0f, new float[] { 30.0f, 1.0f, 1.0f }, 0.0f)); renderer.setSeriesStroke(i * 6 + 3, new BasicStroke(1.3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10.0f, new float[] { 1.0f, 3.0f }, 0.0f)); renderer.setSeriesStroke(i * 6 + 4, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 1.0f, 2.0f, 3.0f, 4.0f }, 0.0f)); renderer.setSeriesStroke(i * 6 + 5, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 5.0f, 1.0f, 20.0f, 1.0f }, 0.0f)); } plot.setRenderer(renderer); return chart; }
From source file:mekhq.gui.FinancesTab.java
private JFreeChart createAmountChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("", // title resourceMap.getString("graphDate.text"), // x-axis label resourceMap.getString("graphCBills.text"), // y-axis label dataset);/*from ww w. j a v a 2 s .c o m*/ chart.setBackgroundPaint(Color.WHITE); XYPlot plot = (XYPlot) chart.getPlot(); 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); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setDefaultShapesVisible(true); renderer.setDefaultShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); chart.removeLegend(); return chart; }
From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java
/** Generate CGI chart output. */ @Override//from w ww. j a va 2 s. c o m protected void writeContents() throws IOException { buildData(); // get the data for display chromeless = (parameters.get("chromeless") != null); JFreeChart chart = createChart(); int width = getIntSetting("width"); int height = getIntSetting("height"); Color initGradColor = getColorSetting("initGradColor"); Color finalGradColor = getColorSetting("finalGradColor"); chart.setBackgroundPaint(new GradientPaint(0, 0, initGradColor, width, height, finalGradColor)); if (parameters.get("hideOutline") != null) chart.getPlot().setOutlinePaint(INVISIBLE); String title = getSetting("title"); if (chromeless || title == null || title.length() == 0) chart.setTitle((TextTitle) null); else { chart.setTitle(Translator.translate(title)); String titleFontSize = getSetting("titleFontSize"); if (titleFontSize != null) try { float fontSize = Float.parseFloat(titleFontSize); TextTitle t = chart.getTitle(); t.setFont(t.getFont().deriveFont(fontSize)); } catch (Exception tfe) { } } if (chromeless || parameters.get("hideLegend") != null) chart.removeLegend(); else { LegendTitle l = chart.getLegend(); String legendFontSize = getSetting("legendFontSize"); if (l != null && legendFontSize != null) try { float fontSize = Float.parseFloat(legendFontSize); l.setItemFont(l.getItemFont().deriveFont(fontSize)); } catch (Exception lfe) { } } chart.getPlot().setNoDataMessage(resources.getString("No_Data_Message")); Axis xAxis = getHorizontalAxis(chart); if (xAxis != null) { if (parameters.get("hideTickLabels") != null || parameters.get("hideXTickLabels") != null) { xAxis.setTickLabelsVisible(false); } else if (parameters.get("tickLabelFontSize") != null || parameters.get("xTickLabelFontSize") != null) { String tfs = getParameter("xTickLabelFontSize"); if (tfs == null) tfs = getParameter("tickLabelFontSize"); float fontSize = Float.parseFloat(tfs); xAxis.setTickLabelFont(xAxis.getTickLabelFont().deriveFont(fontSize)); } } Axis yAxis = getVerticalAxis(chart); if (yAxis != null) { if (parameters.get("hideTickLabels") != null || parameters.get("hideYTickLabels") != null) { yAxis.setTickLabelsVisible(false); } else if (parameters.get("tickLabelFontSize") != null || parameters.get("yTickLabelFontSize") != null) { String tfs = getParameter("yTickLabelFontSize"); if (tfs == null) tfs = getParameter("tickLabelFontSize"); float fontSize = Float.parseFloat(tfs); yAxis.setTickLabelFont(yAxis.getTickLabelFont().deriveFont(fontSize)); } } String axisFontSize = getSetting("axisLabelFontSize"); if (axisFontSize != null) try { float fontSize = Float.parseFloat(axisFontSize); if (xAxis != null) xAxis.setLabelFont(xAxis.getLabelFont().deriveFont(fontSize)); if (yAxis != null) yAxis.setLabelFont(yAxis.getLabelFont().deriveFont(fontSize)); } catch (Exception afs) { } ChartRenderingInfo info = (isHtmlMode() ? new ChartRenderingInfo() : null); BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = img.createGraphics(); if ("auto".equals(getSetting("titleFontSize"))) maybeAdjustTitleFontSize(chart, g2, width); chart.draw(g2, new Rectangle2D.Double(0, 0, width, height), info); g2.dispose(); String outputFormat = getSetting("outputFormat"); OutputStream imgOut; if (isHtmlMode()) { imgOut = PngCache.getOutputStream(); } else { imgOut = outStream; } ImageIO.write(img, outputFormat, imgOut); imgOut.flush(); imgOut.close(); if (isHtmlMode()) writeImageHtml(width, height, imgOut.hashCode(), info); }
From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java
protected void setupCategoryChart(JFreeChart chart) { if (!(chart.getPlot() instanceof CategoryPlot)) return;// ww w. j a v a2 s .c o m CategoryPlot cp = chart.getCategoryPlot(); CategoryAxis catAxis = cp.getDomainAxis(); ValueAxis otherAxis = cp.getRangeAxis(); if (!chromeless) { String catAxisLabel = data.getColName(0); if (catAxisLabel == null) catAxisLabel = Translator.translate("Project/Task"); String otherAxisLabel = Translator.translate(getSetting("units")); if ((otherAxisLabel == null || otherAxisLabel.length() == 0) && data.numCols() == 1) otherAxisLabel = data.getColName(1); if (otherAxisLabel == null) otherAxisLabel = Translator.translate("Value"); String catLabels = getParameter("categoryLabels"); catAxis.setLabel(catAxisLabel); otherAxis.setLabel(otherAxisLabel); if ("vertical".equalsIgnoreCase(catLabels)) catAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); else if ("none".equalsIgnoreCase(catLabels)) catAxis.setTickLabelsVisible(false); } if (data.numCols() == 1 && getParameter("noSkipLegend") == null) { chart.removeLegend(); chart.getPlot().setInsets(new RectangleInsets(5, 2, 2, 5)); } }
From source file:ro.nextreports.engine.chart.JFreeChartExporter.java
private JFreeChart createAreaChart() throws QueryException { barDataset = new DefaultCategoryDataset(); String chartTitle = replaceParameters(chart.getTitle().getTitle()); chartTitle = StringUtil.getI18nString(chartTitle, I18nUtil.getLanguageByName(chart, language)); Object[] charts = new Object[chart.getYColumns().size()]; List<String> legends = chart.getYColumnsLegends(); boolean hasLegend = false; for (int i = 0; i < charts.length; i++) { String legend = ""; try {/* ww w . j a va2 s. c om*/ legend = replaceParameters(legends.get(i)); legend = StringUtil.getI18nString(legend, I18nUtil.getLanguageByName(chart, language)); } catch (IndexOutOfBoundsException ex) { // no legend set } // Important : must have default different legends used in barDataset.addValue if ((legend == null) || "".equals(legend.trim())) { legend = DEFAULT_LEGEND_PREFIX + String.valueOf(i + 1); } else { hasLegend = true; } charts[i] = legend; } String xLegend = StringUtil.getI18nString(replaceParameters(chart.getXLegend().getTitle()), I18nUtil.getLanguageByName(chart, language)); String yLegend = StringUtil.getI18nString(replaceParameters(chart.getYLegend().getTitle()), I18nUtil.getLanguageByName(chart, language)); byte style = chart.getType().getStyle(); JFreeChart jfreechart = ChartFactory.createAreaChart("Area Chart", // chart title xLegend, // x-axis Label yLegend, // y-axis Label barDataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // hide legend if necessary if (!hasLegend) { jfreechart.removeLegend(); } // hide border jfreechart.setBorderVisible(false); // title setTitle(jfreechart); // chart colors & values shown on bars boolean showValues = (chart.getShowYValuesOnChart() == null) ? false : chart.getShowYValuesOnChart(); CategoryPlot plot = (CategoryPlot) jfreechart.getPlot(); plot.setForegroundAlpha(transparency); AreaRenderer renderer = (AreaRenderer) plot.getRenderer(); DecimalFormat decimalformat; DecimalFormat percentageFormat; if (chart.getYTooltipPattern() == null) { decimalformat = new DecimalFormat("#"); percentageFormat = new DecimalFormat("0.00%"); } else { decimalformat = new DecimalFormat(chart.getYTooltipPattern()); percentageFormat = decimalformat; } for (int i = 0; i < charts.length; i++) { renderer.setSeriesPaint(i, chart.getForegrounds().get(i)); if (showValues) { renderer.setSeriesItemLabelsVisible(i, true); renderer.setSeriesItemLabelGenerator(i, new StandardCategoryItemLabelGenerator("{2}", decimalformat, percentageFormat)); } } if (showValues) { // increase a little bit the range axis to view all item label values over bars plot.getRangeAxis().setUpperMargin(0.2); } // grid axis visibility & colors if ((chart.getXShowGrid() != null) && !chart.getXShowGrid()) { plot.setDomainGridlinesVisible(false); } else { if (chart.getXGridColor() != null) { plot.setDomainGridlinePaint(chart.getXGridColor()); } else { plot.setDomainGridlinePaint(Color.BLACK); } } if ((chart.getYShowGrid() != null) && !chart.getYShowGrid()) { plot.setRangeGridlinesVisible(false); } else { if (chart.getYGridColor() != null) { plot.setRangeGridlinePaint(chart.getYGridColor()); } else { plot.setRangeGridlinePaint(Color.BLACK); } } // chart background plot.setBackgroundPaint(chart.getBackground()); // labels color plot.getDomainAxis().setTickLabelPaint(chart.getXColor()); plot.getRangeAxis().setTickLabelPaint(chart.getYColor()); // legend color plot.getDomainAxis().setLabelPaint(chart.getXLegend().getColor()); plot.getRangeAxis().setLabelPaint(chart.getYLegend().getColor()); // legend font plot.getDomainAxis().setLabelFont(chart.getXLegend().getFont()); plot.getRangeAxis().setLabelFont(chart.getYLegend().getFont()); // axis color plot.getDomainAxis().setAxisLinePaint(chart.getxAxisColor()); plot.getRangeAxis().setAxisLinePaint(chart.getyAxisColor()); // hide labels if ((chart.getXShowLabel() != null) && !chart.getXShowLabel()) { plot.getDomainAxis().setTickLabelsVisible(false); plot.getDomainAxis().setTickMarksVisible(false); } if ((chart.getYShowLabel() != null) && !chart.getYShowLabel()) { plot.getRangeAxis().setTickLabelsVisible(false); plot.getRangeAxis().setTickMarksVisible(false); } // label orientation CategoryAxis domainAxis = plot.getDomainAxis(); if (chart.getXorientation() == Chart.VERTICAL) { domainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2)); } else if (chart.getXorientation() == Chart.DIAGONAL) { domainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4)); } else if (chart.getXorientation() == Chart.HALF_DIAGONAL) { domainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8)); } // labels fonts plot.getDomainAxis().setTickLabelFont(chart.getXLabelFont()); plot.getRangeAxis().setTickLabelFont(chart.getYLabelFont()); createChart(plot.getRangeAxis(), charts); return jfreechart; }
From source file:com.peterbochs.instrument.InstrumentPanel.java
private static JFreeChart createChart(XYZDataset dataset) { NumberAxis xAxis = new NumberAxis("address (" + jBlockSizeComboBox.getSelectedItem() + ")"); xAxis.setLowerMargin(0.0);/* ww w . j a v a 2s .c om*/ xAxis.setUpperMargin(0.0); xAxis.setAxisLinePaint(Color.cyan); xAxis.setTickMarkPaint(Color.cyan); // xAxis.setAutoTickUnitSelection(false); // xAxis.setTickUnit(new NumberTickUnit(1)); // NumberFormat nf = NumberFormat.getPercentInstance(); // xAxis.setNumberFormatOverride(nf); // xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis yAxis = new NumberAxis("address (" + jBlockSizeComboBox.getSelectedItem() + " KB)"); // yAxis.setAutoRangeIncludesZero(true); // yAxis.setInverted(false); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); yAxis.setAxisLinePaint(Color.pink); yAxis.setTickMarkPaint(Color.pink); // yAxis.setTickUnit(new NumberTickUnit(10)); // yAxis.setTickLabelFont(new Font("Dialog", 0, 7)); // yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); MyXYBlockRenderer renderer = new MyXYBlockRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); // plot.setBackgroundPaint(Color.white); // plot.setDomainGridlineStroke(new BasicStroke(1)); plot.setDomainGridlinePaint(Color.white); // plot.setRangeGridlineStroke(new BasicStroke(1)); plot.setRangeGridlinePaint(Color.white); // JFreeChart chart = new JFreeChart("Memory read/write hot zone", new // Font("Serif", Font.PLAIN, 12), plot, true); JFreeChart chart = new JFreeChart("Memory read/write hot zone", plot); chart.removeLegend(); chart.setBackgroundPaint(Color.white); return chart; }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java
/** * @param chart/*from w w w .j a va 2 s . c o m*/ */ private void formatLegend(JFreeChart chart) { List<LegendTitle> legendTitles = createLegendTitles(); while (chart.getLegend() != null) { chart.removeLegend(); } for (LegendTitle legendTitle : legendTitles) { chart.addLegend(legendTitle); } // set legend font Font legendFont = plotInstance.getCurrentPlotConfigurationClone().getLegendConfiguration().getLegendFont(); if (legendFont != null) { for (LegendTitle legendTitle : legendTitles) { legendTitle.setItemFont(legendFont); } } }