Java Code Examples for org.jfree.chart.JFreeChart#removeLegend()
The following examples show how to use
org.jfree.chart.JFreeChart#removeLegend() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JFreeChartPlotEngine.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
private void legendPositionChanged(LegendPosition legendPosition) { JFreeChart chart = getCurrentChart(); if (chart != null) { LegendTitle legend = chart.getLegend(); RectangleEdge position = legendPosition.getPosition(); if (legend != null) { if (position != null) { legend.setPosition(position); } else { while (chart.getLegend() != null) { chart.removeLegend(); } } } else { if (position != null) { resetLegend(); } } } }
Example 2
Source File: DensityPlotPanel.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private void createUI() { plot = new XYImagePlot(); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); domainAxis.setAutoRangeIncludesZero(false); rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setUpperMargin(0); domainAxis.setLowerMargin(0); rangeAxis.setUpperMargin(0); rangeAxis.setLowerMargin(0); plot.setNoDataMessage(NO_DATA_MESSAGE); plot.getRenderer().setBaseToolTipGenerator(new XYPlotToolTipGenerator()); JFreeChart chart = new JFreeChart(CHART_TITLE, plot); ChartFactory.getChartTheme().apply(chart); chart.removeLegend(); createUI(createChartPanel(chart), createOptionsPanel(), bindingContext); updateUIState(); }
Example 3
Source File: ChartImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
public void drawLegend(JFreeChart chart){ //remove ipotetical other legend chart.removeLegend(); 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)); titleBlock.setPadding(5, 5, 5, 5); wrapper.add(titleBlock, RectangleEdge.TOP);*/ LegendTitle legend = new LegendTitle(chart.getPlot()); BlockContainer items = legend.getItemContainer(); if(styleLegend!=null && styleLegend.getFont()!=null){ legend.setItemFont(new Font(styleLegend.getFontName(), Font.BOLD, styleLegend.getSize())); } items.setPadding(2, 5, 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.CENTER); chart.addSubtitle(legend); }
Example 4
Source File: ChartFactory.java From graylog-plugin-aggregates with GNU General Public License v3.0 | 5 votes |
public static JFreeChart generateTimeSeriesChart(String title, List<HistoryAggregateItem> history, String timespan, Calendar cal) throws ParseException { TimeSeries series = initializeSeries(timespan, cal, history); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); IntervalXYDataset idataset = new XYBarDataset(dataset, 1); JFreeChart chart = org.jfree.chart.ChartFactory.createXYBarChart( title, // Title "Date/time", // X-axis Label true, "Hits", // Y-axis Label idataset, // Dataset PlotOrientation.VERTICAL, true, // Show legend true, // Use tooltips false // Generate URLs ); chart.setBackgroundPaint(Color.WHITE); chart.setBorderPaint(Color.BLACK); XYPlot plot = (XYPlot)chart.getPlot(); plot.setBackgroundPaint(Color.LIGHT_GRAY); plot.getRenderer().setSeriesPaint(0, Color.BLUE); plot.setDomainGridlinePaint(Color.GRAY); plot.setRangeGridlinePaint(Color.GRAY); chart.removeLegend(); return chart; }
Example 5
Source File: DefaultChartService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private JFreeChart getGaugeChart( BaseChart chart, ValueDataset dataSet ) { MeterPlot meterPlot = new MeterPlot( dataSet ); meterPlot.setUnits( "" ); meterPlot.setRange( new Range( 0.0d, 100d ) ); for ( int i = 0; i < 10; i++ ) { double start = i * 10d; double end = start + 10d; String label = String.valueOf( start ); meterPlot.addInterval( new MeterInterval( label, new Range( start, end ), COLOR_LIGHT_GRAY, null, COLOR_LIGHT_GRAY ) ); } meterPlot.setMeterAngle( 180 ); meterPlot.setDialBackgroundPaint( COLOR_LIGHT_GRAY ); meterPlot.setDialShape( DialShape.CHORD ); meterPlot.setNeedlePaint( COLORS[0] ); meterPlot.setTickLabelsVisible( true ); meterPlot.setTickLabelFont( LABEL_FONT ); meterPlot.setTickLabelPaint( Color.BLACK ); meterPlot.setTickPaint( COLOR_LIGHTER_GRAY ); meterPlot.setValueFont( TITLE_FONT ); meterPlot.setValuePaint( Color.BLACK ); JFreeChart meterChart = new JFreeChart( chart.getName(), meterPlot ); setBasicConfig( meterChart, chart ); meterChart.removeLegend(); return meterChart; }
Example 6
Source File: ChartImageGenerator.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private JFreeChart getGaugeChart( final Visualization visualization, ValueDataset dataSet ) { MeterPlot meterPlot = new MeterPlot( dataSet ); meterPlot.setUnits( "" ); meterPlot.setRange( new Range( 0.0d, 100d ) ); for ( int i = 0; i < 10; i++ ) { double start = i * 10d; double end = start + 10d; String label = String.valueOf( start ); meterPlot.addInterval( new MeterInterval( label, new Range( start, end ), COLOR_LIGHT_GRAY, null, COLOR_LIGHT_GRAY ) ); } meterPlot.setMeterAngle( 180 ); meterPlot.setDialBackgroundPaint( COLOR_LIGHT_GRAY ); meterPlot.setDialShape( DialShape.CHORD ); meterPlot.setNeedlePaint( COLORS[0] ); meterPlot.setTickLabelsVisible( true ); meterPlot.setTickLabelFont( LABEL_FONT ); meterPlot.setTickLabelPaint( Color.BLACK ); meterPlot.setTickPaint( COLOR_LIGHTER_GRAY ); meterPlot.setValueFont( TITLE_FONT ); meterPlot.setValuePaint( Color.BLACK ); JFreeChart meterChart = new JFreeChart( visualization.getName(), meterPlot ); setBasicConfig( meterChart, visualization ); meterChart.removeLegend(); return meterChart; }
Example 7
Source File: EStandardChartTheme.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
/** * Fixes the legend item's colour after the colours of the datasets/series in the plot were * changed. * * @param chart The chart. */ public static void fixLegend(JFreeChart chart) { XYPlot plot = chart.getXYPlot(); LegendTitle oldLegend = chart.getLegend(); RectangleEdge pos = oldLegend.getPosition(); chart.removeLegend(); LegendTitle newLegend = new LegendTitle(plot); newLegend.setPosition(pos); newLegend.setItemFont(oldLegend.getItemFont()); chart.addLegend(newLegend); newLegend.setVisible(oldLegend.isVisible()); }
Example 8
Source File: SpectrumTopComponent.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private void setLegend(JFreeChart chart) { chart.removeLegend(); final LegendTitle legend = new LegendTitle(new SpectrumLegendItemSource()); legend.setPosition(RectangleEdge.BOTTOM); LineBorder border = new LineBorder(Color.BLACK, new BasicStroke(), new RectangleInsets(2, 2, 2, 2)); legend.setFrame(border); chart.addLegend(legend); }
Example 9
Source File: EESGenerator.java From SensorWebClient with GNU General Public License v2.0 | 5 votes |
public void createChartToOutputStream(DesignOptions options, ChartRenderingInfo renderingInfo, OutputStream outputStream) { try { Map<String, OXFFeatureCollection> entireCollMap = getFeatureCollectionFor(options, true); JFreeChart chart = producePresentation(entireCollMap, options); chart.removeLegend(); int width = options.getWidth(); int height = options.getHeight(); ChartUtilities.writeChartAsPNG(outputStream, chart, width, height, renderingInfo); } catch (Exception e) { LOGGER.warn("Error while rendering chart.", e); } }
Example 10
Source File: DiagramGenerator.java From SensorWebClient with GNU General Public License v2.0 | 5 votes |
/** * Creates a time series chart diagram and writes it to the OutputStream. */ public void producePresentation(Map<String, OXFFeatureCollection> entireCollMap, DesignOptions options, FileOutputStream out, boolean compress) throws OXFException, IOException { // render features: int width = options.getWidth(); int height = options.getHeight(); Calendar begin = Calendar.getInstance(); begin.setTimeInMillis(options.getBegin()); Calendar end = Calendar.getInstance(); end.setTimeInMillis(options.getEnd()); DiagramRenderer renderer = new DiagramRenderer(false); JFreeChart diagramChart = renderer.renderChart(entireCollMap, options, begin, end, compress); diagramChart.removeLegend(); // draw chart into image: BufferedImage diagramImage = new BufferedImage(width, height, TYPE_INT_RGB); Graphics2D chartGraphics = diagramImage.createGraphics(); chartGraphics.setColor(Color.white); chartGraphics.fillRect(0, 0, width, height); diagramChart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height)); JPEGImageWriteParam p = new JPEGImageWriteParam(null); p.setCompressionMode(JPEGImageWriteParam.MODE_DEFAULT); write(diagramImage, FORMAT, out); }
Example 11
Source File: LineChart.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
public JFreeChart createChart(){ logger.debug("IN"); CategoryPlot plot = new CategoryPlot(); NumberAxis rangeAxis = new NumberAxis("Kpi Values"); rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12 )); Color colorLabel= Color.decode("#000000"); rangeAxis.setLabelPaint(colorLabel); rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10 )); rangeAxis.setTickLabelPaint(colorLabel); plot.setRangeAxis(rangeAxis); CategoryAxis domainAxis = new CategoryAxis(); domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10 )); domainAxis.setLabelPaint(colorLabel); domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10 )); domainAxis.setTickLabelPaint(colorLabel); plot.setDomainAxis(domainAxis); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); //I create a line renderer MyStandardCategoryItemLabelGenerator generator=null; LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(); lineRenderer.setShapesFilled(true); lineRenderer.setBaseItemLabelGenerator(generator); lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12 )); lineRenderer.setBaseItemLabelPaint(colorLabel); lineRenderer.setBaseItemLabelsVisible(true); DefaultCategoryDataset datasetLine=(DefaultCategoryDataset)datasetMap.getDatasets().get("line"); for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) { String serName = (String) iterator.next(); String labelName = ""; int index=-1; index=datasetLine.getRowIndex(serName); Color color=Color.decode("#990200"); lineRenderer.setSeriesPaint(index, color); } plot.setDataset(0,datasetLine); plot.setRenderer(0,lineRenderer); plot.getDomainAxis().setCategoryLabelPositions( CategoryLabelPositions.UP_45); JFreeChart chart = new JFreeChart(plot); logger.debug("Chart created"); TextTitle title=new TextTitle(name,new Font("Arial", Font.BOLD, 16 ),Color.decode("#990200"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.setTitle(title); TextTitle subTitle =new TextTitle(subName,new Font("Arial", Font.PLAIN, 12 ),Color.decode("#000000"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle); TextTitle subTitle2 =new TextTitle(subName,new Font("Arial", Font.PLAIN, 8 ),Color.decode("#FFFFFF"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle2); chart.removeLegend(); chart.setBackgroundPaint(Color.white); logger.debug("OUT"); return chart; }
Example 12
Source File: StatsGraphServlet.java From document-management-system with GNU General Public License v2.0 | 4 votes |
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String action = WebUtils.getString(request, "action", "graph"); String type = WebUtils.getString(request, "t"); JFreeChart chart = null; updateSessionManager(request); try { if ("refresh".equals(action)) { new RepositoryInfo().runAs(null); ServletContext sc = getServletContext(); sc.getRequestDispatcher("/admin/stats.jsp").forward(request, response); } else { response.setContentType("image/png"); OutputStream out = response.getOutputStream(); if (DOCUMENTS.equals(type) || DOCUMENTS_SIZE.equals(type) || FOLDERS.equals(type)) { chart = repoStats(type); } else if (DISK.equals(type)) { chart = diskStats(); } else if (JVM_MEMORY.equals(type)) { chart = jvmMemStats(); } else if (OS_MEMORY.equals(type)) { chart = osMemStats(); } if (chart != null) { // Customize title font chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 16)); // Match body { background-color:#F6F6EE; } chart.setBackgroundPaint(new Color(246, 246, 238)); // Customize no data PiePlot plot = (PiePlot) chart.getPlot(); plot.setNoDataMessage("No data to display"); // Customize labels plot.setLabelGenerator(null); // Customize legend LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement()); legend.setPosition(RectangleEdge.BOTTOM); legend.setFrame(BlockBorder.NONE); legend.setItemFont(new Font("Tahoma", Font.PLAIN, 12)); chart.removeLegend(); chart.addLegend(legend); if (DISK.equals(type) || JVM_MEMORY.equals(type) || OS_MEMORY.equals(type)) { ChartUtilities.writeChartAsPNG(out, chart, 225, 225); } else { ChartUtilities.writeChartAsPNG(out, chart, 250, 250); } } out.flush(); out.close(); } } catch (Exception e) { e.printStackTrace(); } }
Example 13
Source File: WebPlotter.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
@Override public void updatePlotter() { final int categoryCount = prepareData(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { scrollablePlotterPanel.remove(viewScrollBar); } }); if (categoryCount > MAX_CATEGORY_VIEW_COUNT && showScrollbar) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { viewScrollBar.setOrientation(Adjustable.HORIZONTAL); scrollablePlotterPanel.add(viewScrollBar, BorderLayout.SOUTH); } }); this.slidingCategoryDataSet = new SlidingCategoryDataset(categoryDataSet, 0, MAX_CATEGORY_VIEW_COUNT); viewScrollBar.setMaximum(categoryCount); viewScrollBar.setValue(0); } else { this.slidingCategoryDataSet = null; } if (categoryCount <= MAX_CATEGORIES) { SpiderWebPlot plot = new SpiderWebPlot(categoryDataSet); plot.setAxisLinePaint(Color.LIGHT_GRAY); plot.setOutlinePaint(Color.WHITE); plot.setLabelGenerator(new StandardCategoryItemLabelGenerator()); JFreeChart chart = new JFreeChart("", TextTitle.DEFAULT_FONT, plot, true); double[] colorValues = null; if (groupByColumn >= 0 && this.dataTable.isNominal(groupByColumn)) { colorValues = new double[this.dataTable.getNumberOfValues(groupByColumn)]; } else { colorValues = new double[categoryDataSet.getColumnCount()]; } for (int i = 0; i < colorValues.length; i++) { colorValues[i] = i; } if (panel != null) { panel.setChart(chart); } else { panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN); scrollablePlotterPanel.add(panel, BorderLayout.CENTER); final ChartPanelShiftController controller = new ChartPanelShiftController(panel); panel.addMouseListener(controller); panel.addMouseMotionListener(controller); } // set the background color for the chart... chart.setBackgroundPaint(Color.white); // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } if (groupByColumn < 0) { // no legend is needed when there is no group-by selection chart.removeLegend(); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); } else { LogService.getRoot().log(Level.INFO, "com.rapidminer.gui.plotter.charts.BarChartPlotter.too_many_columns", new Object[] { categoryCount, MAX_CATEGORIES }); } }
Example 14
Source File: AbstractChartExpression.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
protected void configureChart( final JFreeChart chart ) { // Misc Properties final TextTitle chartTitle = chart.getTitle(); if ( chartTitle != null ) { final Font titleFont = Font.decode( getTitleFont() ); chartTitle.setFont( titleFont ); } if ( isAntiAlias() == false ) { chart.setAntiAlias( false ); } chart.setBorderVisible( isShowBorder() ); final Color backgroundColor = parseColorFromString( getBackgroundColor() ); if ( backgroundColor != null ) { chart.setBackgroundPaint( backgroundColor ); } if ( plotBackgroundColor != null ) { chart.getPlot().setBackgroundPaint( plotBackgroundColor ); } chart.getPlot().setBackgroundAlpha( plotBackgroundAlpha ); chart.getPlot().setForegroundAlpha( plotForegroundAlpha ); final Color borderCol = parseColorFromString( getBorderColor() ); if ( borderCol != null ) { chart.setBorderPaint( borderCol ); } //remove legend if showLegend = false if ( !isShowLegend() ) { chart.removeLegend(); } else { //if true format legend final LegendTitle chLegend = chart.getLegend(); if ( chLegend != null ) { final RectangleEdge loc = translateEdge( legendLocation.toLowerCase() ); if ( loc != null ) { chLegend.setPosition( loc ); } if ( getLegendFont() != null ) { chLegend.setItemFont( Font.decode( getLegendFont() ) ); } if ( !isDrawLegendBorder() ) { chLegend.setBorder( BlockBorder.NONE ); } if ( legendBackgroundColor != null ) { chLegend.setBackgroundPaint( legendBackgroundColor ); } if ( legendTextColor != null ) { chLegend.setItemPaint( legendTextColor ); } } } final Plot plot = chart.getPlot(); plot.setNoDataMessageFont( Font.decode( getLabelFont() ) ); final String message = getNoDataMessage(); if ( message != null ) { plot.setNoDataMessage( message ); } plot.setOutlineVisible( isChartSectionOutline() ); if ( backgroundImage != null ) { if ( plotImageCache != null ) { plot.setBackgroundImage( plotImageCache ); } else { final ExpressionRuntime expressionRuntime = getRuntime(); final ProcessingContext context = expressionRuntime.getProcessingContext(); final ResourceKey contentBase = context.getContentBase(); final ResourceManager manager = context.getResourceManager(); try { final ResourceKey key = createKeyFromString( manager, contentBase, backgroundImage ); final Resource resource = manager.create( key, null, Image.class ); final Image image = (Image) resource.getResource(); plot.setBackgroundImage( image ); plotImageCache = image; } catch ( Exception e ) { logger.error( "ABSTRACTCHARTEXPRESSION.ERROR_0007_ERROR_RETRIEVING_PLOT_IMAGE", e ); //$NON-NLS-1$ throw new IllegalStateException( "Failed to process chart" ); } } } }
Example 15
Source File: Volcanoplot.java From chipster with MIT License | 4 votes |
@Override public JComponent getVisualisation(DataBean data) throws Exception { this.data = data; refreshAxisBoxes(data); List<Variable> vars = getFrame().getVariables(); // If this a redraw from the settings panel, use asked columns if (vars != null && vars.size() == 2) { xBox.setSelectedItem(vars.get(0)); yBox.setSelectedItem(vars.get(1)); } xVar = (Variable) xBox.getSelectedItem(); yVar = (Variable) yBox.getSelectedItem(); PlotDescription description = new PlotDescription(data.getName(), "fold change (log2)", "-log(p)"); NumberAxis domainAxis = new NumberAxis(description.xTitle); NumberAxis rangeAxis = new NumberAxis(description.yTitle); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setLinesVisible(false); renderer.setShapesVisible(true); renderer.setSeriesPaint(0, Color.green); renderer.setSeriesPaint(1, Color.red); renderer.setSeriesPaint(2, Color.black); renderer.setSeriesPaint(3, Color.lightGray); renderer.setShape(new Ellipse2D.Float(-2, -2, 4, 4)); plot = new XYPlot(new XYSeriesCollection(), domainAxis, rangeAxis, renderer); this.updateSelectionsFromApplication(false); // rounding limit is calculated in updateSelectionsFromApplication plot.getRangeAxis().setRange(new Range(0, -Math.log10(ROUNDING_LIMIT))); JFreeChart chart = new JFreeChart(description.plotTitle, plot); chart.removeLegend(); application.addClientEventListener(this); selectableChartPanel = new SelectableChartPanel(chart, this); return selectableChartPanel; }