org.jfree.chart.title.LegendTitle Java Examples
The following examples show how to use
org.jfree.chart.title.LegendTitle.
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: JFreeChart.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * Returns the nth legend for a chart, or <code>null</code>. * * @param index the legend index (zero-based). * * @return The legend (possibly <code>null</code>). * * @see #addLegend(LegendTitle) */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
Example #2
Source File: JGenProg2017_003_s.java From coming with MIT License | 6 votes |
/** * Returns the nth legend for a chart, or <code>null</code>. * * @param index the legend index (zero-based). * * @return The legend (possibly <code>null</code>). * * @see #addLegend(LegendTitle) */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
Example #3
Source File: JGenProg2017_00127_s.java From coming with MIT License | 6 votes |
/** * Returns the nth legend for a chart, or <code>null</code>. * * @param index the legend index (zero-based). * * @return The legend (possibly <code>null</code>). * * @see #addLegend(LegendTitle) */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
Example #4
Source File: JFreeChart.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Returns the nth legend for a chart, or <code>null</code>. * * @param index the legend index (zero-based). * * @return The legend (possibly <code>null</code>). * * @see #addLegend(LegendTitle) */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
Example #5
Source File: Cardumen_0077_t.java From coming with MIT License | 6 votes |
/** * Returns the nth legend for a chart, or <code>null</code>. * * @param index the legend index (zero-based). * * @return The legend (possibly <code>null</code>). * * @see #addLegend(LegendTitle) */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
Example #6
Source File: Cardumen_00193_s.java From coming with MIT License | 6 votes |
/** * Returns the nth legend for a chart, or <code>null</code>. * * @param index the legend index (zero-based). * * @return The legend (possibly <code>null</code>). * * @see #addLegend(LegendTitle) */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
Example #7
Source File: CommonPieChartAction.java From bamboobsc with Apache License 2.0 | 6 votes |
private void fillChart(String title, List<String> names, List<String> colors, List<Float> values) throws Exception { DefaultPieDataset data=new DefaultPieDataset(); for (int ix=0; ix<names.size(); ix++) { data.setValue( names.get(ix), values.get(ix) ); } this.chart=ChartFactory.createPieChart3D( title, data, true, true, false); LegendTitle legend=this.chart.getLegend(); legend.setItemFont(new Font("", Font.TRUETYPE_FONT, 9) ); PiePlot plot=(PiePlot)this.chart.getPlot(); plot.setCircular(true); plot.setBackgroundAlpha(0.9f); plot.setForegroundAlpha(0.5f); plot.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9) ); this.setPlotColor( plot, names, colors ); this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9) ) ); }
Example #8
Source File: JGenProg2017_00104_s.java From coming with MIT License | 6 votes |
/** * Returns the nth legend for a chart, or <code>null</code>. * * @param index the legend index (zero-based). * * @return The legend (possibly <code>null</code>). * * @see #addLegend(LegendTitle) */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
Example #9
Source File: jKali_0052_s.java From coming with MIT License | 6 votes |
/** * Returns the nth legend for a chart, or <code>null</code>. * * @param index the legend index (zero-based). * * @return The legend (possibly <code>null</code>). * * @see #addLegend(LegendTitle) */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
Example #10
Source File: Cardumen_0077_s.java From coming with MIT License | 6 votes |
/** * Returns the nth legend for a chart, or <code>null</code>. * * @param index the legend index (zero-based). * * @return The legend (possibly <code>null</code>). * * @see #addLegend(LegendTitle) */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
Example #11
Source File: Cardumen_003_t.java From coming with MIT License | 6 votes |
/** * Returns the nth legend for a chart, or <code>null</code>. * * @param index the legend index (zero-based). * * @return The legend (possibly <code>null</code>). * * @see #addLegend(LegendTitle) */ public LegendTitle getLegend(int index) { int seen = 0; Iterator iterator = this.subtitles.iterator(); while (iterator.hasNext()) { Title subtitle = (Title) iterator.next(); if (subtitle instanceof LegendTitle) { if (seen == index) { return (LegendTitle) subtitle; } else { seen++; } } } return null; }
Example #12
Source File: LegendTitleTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Check that the equals() method distinguishes all fields. */ public void testEquals() { XYPlot plot1 = new XYPlot(); LegendTitle t1 = new LegendTitle(plot1); LegendTitle t2 = new LegendTitle(plot1); assertEquals(t1, t2); t1.setBackgroundPaint( new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow) ); assertFalse(t1.equals(t2)); t2.setBackgroundPaint( new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow) ); assertTrue(t1.equals(t2)); t1.setLegendItemGraphicEdge(RectangleEdge.BOTTOM); assertFalse(t1.equals(t2)); t2.setLegendItemGraphicEdge(RectangleEdge.BOTTOM); assertTrue(t1.equals(t2)); t1.setLegendItemGraphicAnchor(RectangleAnchor.BOTTOM_LEFT); assertFalse(t1.equals(t2)); t2.setLegendItemGraphicAnchor(RectangleAnchor.BOTTOM_LEFT); assertTrue(t1.equals(t2)); t1.setLegendItemGraphicLocation(RectangleAnchor.TOP_LEFT); assertFalse(t1.equals(t2)); t2.setLegendItemGraphicLocation(RectangleAnchor.TOP_LEFT); assertTrue(t1.equals(t2)); t1.setItemFont(new Font("Dialog", Font.PLAIN, 19)); assertFalse(t1.equals(t2)); t2.setItemFont(new Font("Dialog", Font.PLAIN, 19)); assertTrue(t1.equals(t2)); }
Example #13
Source File: JFreeChartTest.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Some checks for the default legend firing change events. */ @Test public void testLegendEvents() { DefaultPieDataset dataset = new DefaultPieDataset(); JFreeChart chart = ChartFactory.createPieChart("title", dataset); chart.addChangeListener(this); this.lastChartChangeEvent = null; LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.TOP); assertNotNull(this.lastChartChangeEvent); }
Example #14
Source File: StandardChartTheme.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Applies the attributes of this theme to the specified title. * * @param title the title. */ protected void applyToTitle(Title title) { if (title instanceof TextTitle) { TextTitle tt = (TextTitle) title; tt.setFont(this.largeFont); tt.setPaint(this.subtitlePaint); } else if (title instanceof LegendTitle) { LegendTitle lt = (LegendTitle) title; if (lt.getBackgroundPaint() != null) { lt.setBackgroundPaint(this.legendBackgroundPaint); } lt.setItemFont(this.regularFont); lt.setItemPaint(this.legendItemPaint); if (lt.getWrapper() != null) { applyToBlockContainer(lt.getWrapper()); } } else if (title instanceof PaintScaleLegend) { PaintScaleLegend psl = (PaintScaleLegend) title; psl.setBackgroundPaint(this.legendBackgroundPaint); ValueAxis axis = psl.getAxis(); if (axis != null) { applyToValueAxis(axis); } } else if (title instanceof CompositeTitle) { CompositeTitle ct = (CompositeTitle) title; BlockContainer bc = ct.getContainer(); List blocks = bc.getBlocks(); Iterator iterator = blocks.iterator(); while (iterator.hasNext()) { Block b = (Block) iterator.next(); if (b instanceof Title) { applyToTitle((Title) b); } } } }
Example #15
Source File: HistogramPanel.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
/** * Toggles visibility of legends */ private void toggleLegends() { if (pnHisto != null) { LegendTitle legend = pnHisto.getChart().getLegend(); if (legend != null) legend.setVisible(!legend.isVisible()); } }
Example #16
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 #17
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 #18
Source File: BaseChartBuilder.java From nmonvisualizer with Apache License 2.0 | 5 votes |
protected final void addLegend() { if (chart == null) { throw new IllegalStateException("initChart() must be called first"); } LegendTitle legend = new LegendTitle(chart.getPlot()); formatter.formatLegend(legend); chart.addLegend(legend); }
Example #19
Source File: AWSDeviceFarmGraph.java From aws-device-farm-jenkins-plugin with Apache License 2.0 | 5 votes |
/** * Create graph based on the given dataset and constraints. * * @return The JFreeChart graph. */ protected JFreeChart createGraph() { // Create chart. JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.WHITE); // Create chart legend. LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); // Create chart plot. CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.7f); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.darkGray); // Create domain (x) axis. CategoryAxis domain = new ShiftedCategoryAxis(xLabel); domain.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domain.setLowerMargin(0.0); domain.setUpperMargin(0.0); domain.setCategoryMargin(0.0); plot.setDomainAxis(domain); // Create range (y) axis. NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRange(true); range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create renderer and paint the chart. CategoryItemRenderer renderer = plot.getRenderer(); plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); // Set chart colors for sections. for (int i = 0; i < colors.length; i++) { renderer.setSeriesPaint(i, colors[i]); } return chart; }
Example #20
Source File: StandardChartTheme.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Applies the attributes of this theme to the specified title. * * @param title the title. */ protected void applyToTitle(Title title) { if (title instanceof TextTitle) { TextTitle tt = (TextTitle) title; tt.setFont(this.largeFont); tt.setPaint(this.subtitlePaint); } else if (title instanceof LegendTitle) { LegendTitle lt = (LegendTitle) title; if (lt.getBackgroundPaint() != null) { lt.setBackgroundPaint(this.legendBackgroundPaint); } lt.setItemFont(this.regularFont); lt.setItemPaint(this.legendItemPaint); if (lt.getWrapper() != null) { applyToBlockContainer(lt.getWrapper()); } } else if (title instanceof PaintScaleLegend) { PaintScaleLegend psl = (PaintScaleLegend) title; psl.setBackgroundPaint(this.legendBackgroundPaint); ValueAxis axis = psl.getAxis(); if (axis != null) { applyToValueAxis(axis); } } else if (title instanceof CompositeTitle) { CompositeTitle ct = (CompositeTitle) title; BlockContainer bc = ct.getContainer(); List blocks = bc.getBlocks(); Iterator iterator = blocks.iterator(); while (iterator.hasNext()) { Block b = (Block) iterator.next(); if (b instanceof Title) { applyToTitle((Title) b); } } } }
Example #21
Source File: JFreeChartTest.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * Serialize a pie chart, restore it, and check for equality. */ @Test public void testSerialization1() { DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Type 1", 54.5); data.setValue("Type 2", 23.9); data.setValue("Type 3", 45.8); JFreeChart c1 = ChartFactory.createPieChart("Test", data); JFreeChart c2 = (JFreeChart) TestUtilities.serialised(c1); assertEquals(c1, c2); LegendTitle lt2 = c2.getLegend(); assertSame(lt2.getSources()[0], c2.getPlot()); }
Example #22
Source File: StandardChartTheme.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * Applies the attributes of this theme to the specified title. * * @param title the title. */ protected void applyToTitle(Title title) { if (title instanceof TextTitle) { TextTitle tt = (TextTitle) title; tt.setFont(this.largeFont); tt.setPaint(this.subtitlePaint); } else if (title instanceof LegendTitle) { LegendTitle lt = (LegendTitle) title; if (lt.getBackgroundPaint() != null) { lt.setBackgroundPaint(this.legendBackgroundPaint); } lt.setItemFont(this.regularFont); lt.setItemPaint(this.legendItemPaint); if (lt.getWrapper() != null) { applyToBlockContainer(lt.getWrapper()); } } else if (title instanceof PaintScaleLegend) { PaintScaleLegend psl = (PaintScaleLegend) title; psl.setBackgroundPaint(this.legendBackgroundPaint); ValueAxis axis = psl.getAxis(); if (axis != null) { applyToValueAxis(axis); } } else if (title instanceof CompositeTitle) { CompositeTitle ct = (CompositeTitle) title; BlockContainer bc = ct.getContainer(); List blocks = bc.getBlocks(); Iterator iterator = blocks.iterator(); while (iterator.hasNext()) { Block b = (Block) iterator.next(); if (b instanceof Title) { applyToTitle((Title) b); } } } }
Example #23
Source File: EStandardChartTheme.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
public void applyToTitles(@Nonnull JFreeChart chart) { TextTitle title = chart.getTitle(); if(title != null) { title.setVisible(isShowTitle()); if (isChangeTitle()) { title.setText(getTitle()); } } chart.getSubtitles().forEach(s -> { if (s != chart.getTitle() && s instanceof TextTitle) { TextTitle textTitle = (TextTitle)s; // ((TextTitle) s).setFont(getRegularFont()); // ((TextTitle) s).setMargin(TITLE_TOP_MARGIN, 0d, 0d, 0d); textTitle.setVisible(isShowSubtitles()); // ((TextTitle) s).setPaint(subtitleFontColor); // should be set by the theme itself. // subtitle color is set by the chart theme parameters // if (PaintScaleLegend.class.isAssignableFrom(s.getClass())) { // ((PaintScaleLegend) s) // .setBackgroundPaint(this.getChartBackgroundPaint()); // } } if (s instanceof LegendTitle) { LegendTitle legendTitle = (LegendTitle) s; legendTitle.setVisible(isShowLegend()); } }); }
Example #24
Source File: JFreeChartTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Some checks for the default legend firing change events. */ public void testLegendEvents() { DefaultPieDataset dataset = new DefaultPieDataset(); JFreeChart chart = ChartFactory.createPieChart("title", dataset, true, false, false); chart.addChangeListener(this); this.lastChartChangeEvent = null; LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.TOP); assertNotNull(this.lastChartChangeEvent); }
Example #25
Source File: StandardChartTheme.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * Applies the attributes of this theme to the specified title. * * @param title the title. */ protected void applyToTitle(Title title) { if (title instanceof TextTitle) { TextTitle tt = (TextTitle) title; tt.setFont(this.largeFont); tt.setPaint(this.subtitlePaint); } else if (title instanceof LegendTitle) { LegendTitle lt = (LegendTitle) title; if (lt.getBackgroundPaint() != null) { lt.setBackgroundPaint(this.legendBackgroundPaint); } lt.setItemFont(this.regularFont); lt.setItemPaint(this.legendItemPaint); if (lt.getWrapper() != null) { applyToBlockContainer(lt.getWrapper()); } } else if (title instanceof PaintScaleLegend) { PaintScaleLegend psl = (PaintScaleLegend) title; psl.setBackgroundPaint(this.legendBackgroundPaint); ValueAxis axis = psl.getAxis(); if (axis != null) { applyToValueAxis(axis); } } else if (title instanceof CompositeTitle) { CompositeTitle ct = (CompositeTitle) title; BlockContainer bc = ct.getContainer(); List blocks = bc.getBlocks(); Iterator iterator = blocks.iterator(); while (iterator.hasNext()) { Block b = (Block) iterator.next(); if (b instanceof Title) { applyToTitle((Title) b); } } } }
Example #26
Source File: ParetoChartPlotter.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
public void paintParetoChart(Graphics graphics) { prepareData(); JFreeChart chart = createChart(); if (chart != null) { // set the background color for the chart... chart.setBackgroundPaint(Color.white); chart.getPlot().setBackgroundPaint(Color.WHITE); // bar renderer --> own 3D effect CategoryPlot plot = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); // renderer.setBarPainter(new StandardBarPainter()); renderer.setBarPainter(new RapidBarPainter()); renderer.setSeriesPaint(0, getColorProvider(true).getPointColor(1)); // labels on top of bars Map<String, String> barItemLabels = new HashMap<>(); Map<String, String> cumulativeItemLabels = new HashMap<>(); int groupSum = 0; int totalSum = 0; for (Object key : totalData.getKeys()) { String k = (String) key; try { Number groupValue = data.getValue(k); Number totalValue = totalData.getValue(k); groupSum += groupValue.intValue(); totalSum += totalValue.intValue(); barItemLabels.put( k, Tools.formatIntegerIfPossible(groupValue.doubleValue()) + " / " + Tools.formatIntegerIfPossible(totalValue.doubleValue())); cumulativeItemLabels.put(k, groupSum + " / " + totalSum); } catch (UnknownKeyException e) { // do nothing } } renderer.setSeriesItemLabelFont(0, LABEL_FONT); if (showBarLabelsFlag) { renderer.setSeriesItemLabelsVisible(0, true); renderer.setSeriesItemLabelGenerator(0, new ParetoChartItemLabelGenerator(barItemLabels)); if (isLabelRotating()) { renderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0d)); renderer.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0d)); } } LineAndShapeRenderer renderer2 = (LineAndShapeRenderer) chart.getCategoryPlot().getRenderer(1); renderer2.setSeriesPaint(0, Color.GRAY.darker().darker()); renderer2.setSeriesItemLabelFont(0, LABEL_FONT); renderer2.setSeriesItemLabelPaint(0, Color.BLACK); if (isLabelRotating()) { renderer2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0d)); renderer2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0d)); } else { renderer2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BOTTOM_RIGHT)); renderer2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BOTTOM_RIGHT)); } if (showCumulativeLabelsFlag) { renderer2.setSeriesItemLabelsVisible(0, true); renderer2.setSeriesItemLabelGenerator(0, new ParetoChartItemLabelGenerator(cumulativeItemLabels)); } // draw outlines renderer.setDrawBarOutline(true); // gridline colors plot.setRangeGridlinePaint(Color.BLACK); // 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); } Rectangle2D drawRect = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); chart.draw((Graphics2D) graphics, drawRect); } }
Example #27
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 #28
Source File: ChromatogramPlotWindowController.java From old-mzmine3 with GNU General Public License v2.0 | 4 votes |
@FXML public void initialize() { final JFreeChart chart = chartNode.getChart(); final XYPlot plot = chart.getXYPlot(); // Do not set colors and strokes dynamically. They are instead provided // by the dataset and configured in configureRenderer() plot.setDrawingSupplier(null); plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor)); plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor)); plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor)); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.setDomainCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor)); plot.setRangeCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); // chart properties chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor)); // legend properties LegendTitle legend = chart.getLegend(); // legend.setItemFont(legendFont); legend.setFrame(BlockBorder.NONE); // set the X axis (retention time) properties NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setLabel("Retention time (min)"); xAxis.setUpperMargin(0.03); xAxis.setLowerMargin(0.03); xAxis.setRangeType(RangeType.POSITIVE); xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20)); // set the Y axis (intensity) properties NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setLabel("Intensity"); yAxis.setRangeType(RangeType.POSITIVE); yAxis.setAutoRangeIncludesZero(true); // set the fixed number formats, because otherwise JFreeChart sometimes // shows exponent, sometimes it doesn't DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat(); xAxis.setNumberFormatOverride(mzFormat); DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat(); yAxis.setNumberFormatOverride(intensityFormat); chartTitle = chartNode.getChart().getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); chartTitle.setText("Chromatogram"); chartNode.setCursor(Cursor.CROSSHAIR); // Remove the dataset if it is removed from the list datasets.addListener((Change<? extends ChromatogramPlotDataSet> c) -> { while (c.next()) { if (c.wasRemoved()) { for (ChromatogramPlotDataSet ds : c.getRemoved()) { int index = plot.indexOf(ds); plot.setDataset(index, null); } } } }); itemLabelsVisible.addListener((prop, oldVal, newVal) -> { for (ChromatogramPlotDataSet dataset : datasets) { int datasetIndex = plot.indexOf(dataset); XYItemRenderer renderer = plot.getRenderer(datasetIndex); renderer.setBaseItemLabelsVisible(newVal); } }); legendVisible.addListener((prop, oldVal, newVal) -> { legend.setVisible(newVal); }); }
Example #29
Source File: CombinedXYPlotDemo1.java From openstock with GNU General Public License v3.0 | 4 votes |
/** * Creates an overlaid chart. * * @return The chart. */ private static JFreeChart createCombinedChart() { // create plot ... IntervalXYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); renderer1.setSeriesStroke(0, new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesPaint(0, Color.blue); DateAxis domainAxis = new DateAxis("Year"); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.02); ValueAxis rangeAxis = new NumberAxis("$billion"); XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); // add a second dataset and renderer... IntervalXYDataset data2 = createDataset2(); XYBarRenderer renderer2 = new XYBarRenderer() { public Paint getItemPaint(int series, int item) { XYDataset dataset = getPlot().getDataset(); if (dataset.getYValue(series, item) >= 0.0) { return Color.red; } else { return Color.green; } } }; renderer2.setSeriesPaint(0, Color.red); renderer2.setDrawBarOutline(false); renderer2.setBaseToolTipGenerator(new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"), renderer2); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); CombinedXYPlot cplot = new CombinedXYPlot(domainAxis, rangeAxis); cplot.add(plot1, 3); cplot.add(plot2, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart("CombinedXYPlotDemo1", JFreeChart.DEFAULT_TITLE_FONT, cplot, false); chart.setBackgroundPaint(Color.white); LegendTitle legend = new LegendTitle(cplot); chart.addSubtitle(legend); return chart; }
Example #30
Source File: Cardumen_00241_s.java From coming with MIT License | 4 votes |
/** * Creates a new chart with the given title and plot. The * <code>createLegend</code> argument specifies whether or not a legend * should be added to the chart. * <br><br> * Note that the {@link ChartFactory} class contains a range * of static methods that will return ready-made charts, and often this * is a more convenient way to create charts than using this constructor. * * @param title the chart title (<code>null</code> permitted). * @param titleFont the font for displaying the chart title * (<code>null</code> permitted). * @param plot controller of the visual representation of the data * (<code>null</code> not permitted). * @param createLegend a flag indicating whether or not a legend should * be created for the chart. */ public JFreeChart(String title, Font titleFont, Plot plot, boolean createLegend) { if (plot == null) { throw new NullPointerException("Null 'plot' argument."); } // create storage for listeners... this.progressListeners = new EventListenerList(); this.changeListeners = new EventListenerList(); this.notify = true; // default is to notify listeners when the // chart changes this.renderingHints = new RenderingHints( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); this.borderVisible = false; this.borderStroke = new BasicStroke(1.0f); this.borderPaint = Color.black; this.padding = RectangleInsets.ZERO_INSETS; this.plot = plot; plot.addChangeListener(this); this.subtitles = new ArrayList(); // create a legend, if requested... if (createLegend) { LegendTitle legend = new LegendTitle(this.plot); legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setFrame(new LineBorder()); legend.setBackgroundPaint(Color.white); legend.setPosition(RectangleEdge.BOTTOM); this.subtitles.add(legend); legend.addChangeListener(this); } // add the chart title, if one has been specified... if (title != null) { if (titleFont == null) { titleFont = DEFAULT_TITLE_FONT; } this.title = new TextTitle(title, titleFont); this.title.addChangeListener(this); } this.backgroundPaint = DEFAULT_BACKGROUND_PAINT; this.backgroundImage = DEFAULT_BACKGROUND_IMAGE; this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT; this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA; }