Java Code Examples for org.jfree.chart.JFreeChart#getLegend()
The following examples show how to use
org.jfree.chart.JFreeChart#getLegend() .
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: TaChart.java From TAcharting with GNU Lesser General Public License v2.1 | 6 votes |
/** * Constructor. * @param box a ChartIndicatorBox */ public TaChart(IndicatorBox box){ mapTradingRecordMarker = new HashMap<>(); this.chartIndicatorBox = box; this.chartIndicatorBox.getIndicartors().addListener(this); XYDataset candlesBarData = createOHLCDataset(chartIndicatorBox.getBarSeries()); this.mainPlot = createMainPlot(candlesBarData); this.combinedXYPlot = createCombinedDomainXYPlot(mainPlot); this.setCache(true); this.setCacheHint(CacheHint.SPEED); final JFreeChart chart = new JFreeChart(combinedXYPlot); TaChartViewer viewer = new TaChartViewer(chart); Color chartBackground = Color.WHITE; chart.setBackgroundPaint(chartBackground); getChildren().add(viewer); LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.TOP); legend.setItemFont(new Font("Arial", Font.BOLD, 12)); Color legendBackground = new Color(0, 0, 0, 0); legend.setBackgroundPaint(legendBackground); chartIndicatorBox.getObservableBarSeries().addListener((ob, o, n) -> reloadBarSeries(n)); }
Example 2
Source File: ScheduleReport.java From ezScrum with GNU General Public License v2.0 | 6 votes |
private void setAttribute(JFreeChart chart) { // 圖案與文字的間隔 LegendTitle legend = chart.getLegend(); legend.setBorder(1, 1, 1, 1); CategoryPlot plot = chart.getCategoryPlot(); // 設定WorkItem的屬性 CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); // 字體角度 domainAxis.setTickLabelFont(new Font("新細明體", Font.TRUETYPE_FONT, 12)); // 字體 // 設定Date的屬性 DateAxis da = (DateAxis) plot.getRangeAxis(0); setDateAxis(da); // 設定實體的顯示名稱 CategoryItemRenderer render = plot.getRenderer(0); DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); CategoryItemLabelGenerator generator = new IntervalCategoryItemLabelGenerator( "{3} ~ {4}", format); render.setBaseItemLabelGenerator(generator); render.setBaseItemLabelPaint(Color.BLUE); render.setBaseItemLabelsVisible(true); render.setBaseItemLabelFont(new Font("黑體", Font.TRUETYPE_FONT, 8)); render.setSeriesPaint(0, Color.RED); }
Example 3
Source File: ROCChartPlotter.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
public void paintDeviationChart(Graphics graphics, int width, int height) { prepareData(); JFreeChart chart = createChart(this.dataset); // 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); } Rectangle2D drawRect = new Rectangle2D.Double(0, 0, width, height); chart.draw((Graphics2D) graphics, drawRect); }
Example 4
Source File: ChartExportUtil.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width, int height, File fileName, int resolution) throws IOException { // Background color Paint saved = chart.getBackgroundPaint(); if (((Color) saved).getAlpha() == 0) { chart.setBackgroundPaint(Color.WHITE); chart.setBackgroundImageAlpha(255); if (chart.getLegend() != null) chart.getLegend().setBackgroundPaint(Color.WHITE); // legends and stuff for (int i = 0; i < chart.getSubtitleCount(); i++) if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass())) ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE); // apply bg chart.getPlot().setBackgroundPaint(Color.WHITE); } // if (resolution == 72) writeChartToJPEG(chart, width, height, fileName); else { OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName)); try { BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height, resolution, BufferedImage.TYPE_INT_RGB); EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f); } finally { out.close(); } } }
Example 5
Source File: ChartExportUtil.java From old-mzmine3 with GNU General Public License v2.0 | 5 votes |
public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width, int height, File fileName, int resolution) throws IOException { // Background color Paint saved = chart.getBackgroundPaint(); if (((Color) saved).getAlpha() == 0) { chart.setBackgroundPaint(Color.WHITE); chart.setBackgroundImageAlpha(255); if (chart.getLegend() != null) chart.getLegend().setBackgroundPaint(Color.WHITE); // legends and stuff for (int i = 0; i < chart.getSubtitleCount(); i++) if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass())) ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE); // apply bg chart.getPlot().setBackgroundPaint(Color.WHITE); } // if (resolution == 72) writeChartToJPEG(chart, width, height, fileName); else { OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName)); try { BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height, resolution, BufferedImage.TYPE_INT_RGB); EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f); } finally { out.close(); } } }
Example 6
Source File: ChartExportUtil.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width, int height, File fileName, int resolution) throws IOException { // Background color Paint saved = chart.getBackgroundPaint(); if (((Color) saved).getAlpha() == 0) { chart.setBackgroundPaint(Color.WHITE); chart.setBackgroundImageAlpha(255); if (chart.getLegend() != null) chart.getLegend().setBackgroundPaint(Color.WHITE); // legends and stuff for (int i = 0; i < chart.getSubtitleCount(); i++) if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass())) ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE); // apply bg chart.getPlot().setBackgroundPaint(Color.WHITE); } // if (resolution == 72) writeChartToJPEG(chart, width, height, fileName); else { OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName)); try { BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height, resolution, BufferedImage.TYPE_INT_RGB); EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f); } finally { out.close(); } } }
Example 7
Source File: ChartImageGenerator.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private JFreeChart getMultiplePieChart( final Visualization visualization, CategoryDataset[] dataSets ) { JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart( visualization.getName(), dataSets[0], TableOrder.BY_ROW, !visualization.isHideLegend(), false, false ); setBasicConfig( multiplePieChart, visualization ); if ( multiplePieChart.getLegend() != null ) { multiplePieChart.getLegend().setItemFont( SUB_TITLE_FONT ); } MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot(); JFreeChart pieChart = multiplePiePlot.getPieChart(); pieChart.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR ); pieChart.getTitle().setFont( SUB_TITLE_FONT ); PiePlot piePlot = (PiePlot) pieChart.getPlot(); piePlot.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR ); piePlot.setOutlinePaint( DEFAULT_BACKGROUND_COLOR ); piePlot.setLabelFont( LABEL_FONT ); piePlot.setLabelGenerator( new StandardPieSectionLabelGenerator( "{2}" ) ); piePlot.setSimpleLabels( true ); piePlot.setIgnoreZeroValues( true ); piePlot.setIgnoreNullValues( true ); piePlot.setShadowXOffset( 0d ); piePlot.setShadowYOffset( 0d ); for ( int i = 0; i < dataSets[0].getColumnCount(); i++ ) { piePlot.setSectionPaint( dataSets[0].getColumnKey( i ), COLORS[(i % COLORS.length)] ); } return multiplePieChart; }
Example 8
Source File: DefaultChartService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private JFreeChart getMultiplePieChart( BaseChart chart, CategoryDataset[] dataSets ) { JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart( chart.getName(), dataSets[0], TableOrder.BY_ROW, !chart.isHideLegend(), false, false ); setBasicConfig( multiplePieChart, chart ); if ( multiplePieChart.getLegend() != null ) { multiplePieChart.getLegend().setItemFont( SUB_TITLE_FONT ); } MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot(); JFreeChart pieChart = multiplePiePlot.getPieChart(); pieChart.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR ); pieChart.getTitle().setFont( SUB_TITLE_FONT ); PiePlot piePlot = (PiePlot) pieChart.getPlot(); piePlot.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR ); piePlot.setOutlinePaint( DEFAULT_BACKGROUND_COLOR ); piePlot.setLabelFont( LABEL_FONT ); piePlot.setLabelGenerator( new StandardPieSectionLabelGenerator( "{2}" ) ); piePlot.setSimpleLabels( true ); piePlot.setIgnoreZeroValues( true ); piePlot.setIgnoreNullValues( true ); piePlot.setShadowXOffset( 0d ); piePlot.setShadowYOffset( 0d ); for ( int i = 0; i < dataSets[0].getColumnCount(); i++ ) { piePlot.setSectionPaint( dataSets[0].getColumnKey( i ), COLORS[(i % COLORS.length)] ); } return multiplePieChart; }
Example 9
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 10
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); chart.addChangeListener(this); this.lastChartChangeEvent = null; LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.TOP); assertNotNull(this.lastChartChangeEvent); }
Example 11
Source File: EStandardChartTheme.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
public void applyToLegend(@Nonnull JFreeChart chart) { if (chart.getLegend() != null) { chart.getLegend().setBackgroundPaint(this.getChartBackgroundPaint()); } fixLegend(chart); }
Example 12
Source File: SimpleChartTheme.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
protected void setChartLegend(JFreeChart jfreeChart) { //The legend visibility is already taken into account in the jfreeChart object's constructor LegendTitle legend = jfreeChart.getLegend(); if (legend != null) { LegendSettings legendSettings = getLegendSettings(); JRBaseFont font = new JRBaseFont(); FontUtil.copyNonNullOwnProperties(legendSettings.getFont(), font); FontUtil.copyNonNullOwnProperties(getChart().getLegendFont(), font); font = new JRBaseFont(getChart(), font); legend.setItemFont(getFontUtil().getAwtFont(font, getLocale())); Paint forePaint = getChart().getOwnLegendColor(); if (forePaint == null && legendSettings.getForegroundPaint() != null) { forePaint = legendSettings.getForegroundPaint().getPaint(); } if (forePaint == null) { forePaint = getChart().getLegendColor(); } if (forePaint != null) legend.setItemPaint(forePaint); Paint backPaint = getChart().getOwnLegendBackgroundColor(); if (backPaint == null && legendSettings.getBackgroundPaint() != null) { backPaint = legendSettings.getBackgroundPaint().getPaint(); } if (backPaint == null) { backPaint = getChart().getLegendBackgroundColor(); } if (backPaint != null) legend.setBackgroundPaint(backPaint); BlockFrame blockFrame = legendSettings.getBlockFrame(); if (blockFrame != null) legend.setFrame(blockFrame); HorizontalAlignment hAlign = legendSettings.getHorizontalAlignment(); if (hAlign != null) legend.setHorizontalAlignment(hAlign); VerticalAlignment vAlign = legendSettings.getVerticalAlignment(); if (vAlign != null) legend.setVerticalAlignment(vAlign); RectangleInsets padding = legendSettings.getPadding(); if (padding != null) legend.setPadding(padding); legend.setPosition( getEdge( getChart().getLegendPositionValue(), getEdge( legendSettings.getPositionValue() , RectangleEdge.BOTTOM ) ) ); } }
Example 13
Source File: SeriesChartPlotter.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
@Override protected void updatePlotter() { int categoryCount = prepareData(); String maxClassesProperty = ParameterService .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT); int maxClasses = 20; try { if (maxClassesProperty != null) { maxClasses = Integer.parseInt(maxClassesProperty); } } catch (NumberFormatException e) { // LogService.getGlobal().log("Series plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.", // LogService.WARNING); LogService.getRoot().log(Level.WARNING, "com.rapidminer.gui.plotter.charts.SeriesChartPlotter.parsing_property_error"); } boolean createLegend = categoryCount > 0 && categoryCount < maxClasses; JFreeChart chart = createChart(this.dataset, createLegend); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // domain axis if (axis[INDEX] >= 0) { if (!dataTable.isNominal(axis[INDEX])) { if (dataTable.isDate(axis[INDEX]) || dataTable.isDateTime(axis[INDEX])) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[INDEX])); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); chart.getXYPlot().setDomainAxis(domainAxis); if (getRangeForDimension(axis[INDEX]) != null) { domainAxis.setRange(getRangeForDimension(axis[INDEX])); } domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); domainAxis.setVerticalTickLabels(isLabelRotating()); } } else { LinkedHashSet<String> values = new LinkedHashSet<String>(); for (DataTableRow row : dataTable) { String stringValue = dataTable.mapIndex(axis[INDEX], (int) row.getValue(axis[INDEX])); if (stringValue.length() > 40) { stringValue = stringValue.substring(0, 40); } values.add(stringValue); } ValueAxis categoryAxis = new SymbolAxis(dataTable.getColumnName(axis[INDEX]), values.toArray(new String[values.size()])); categoryAxis.setLabelFont(LABEL_FONT_BOLD); categoryAxis.setTickLabelFont(LABEL_FONT); categoryAxis.setVerticalTickLabels(isLabelRotating()); chart.getXYPlot().setDomainAxis(categoryAxis); } } // 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); } AbstractChartPanel panel = getPlotterPanel(); if (panel == null) { panel = createPanel(chart); } else { panel.setChart(chart); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); }
Example 14
Source File: AbstractPieChartPlotter.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
public void updatePlotter() { int categoryCount = prepareData(); String maxClassesProperty = ParameterService .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_LEGEND_CLASSLIMIT); int maxClasses = 20; try { if (maxClassesProperty != null) { maxClasses = Integer.parseInt(maxClassesProperty); } } catch (NumberFormatException e) { // LogService.getGlobal().log("Pie Chart plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.", // LogService.WARNING); LogService.getRoot().log(Level.WARNING, "com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.pie_chart_plotter_parsing_error"); } boolean createLegend = categoryCount > 0 && categoryCount < maxClasses; if (categoryCount <= MAX_CATEGORIES) { JFreeChart chart = createChart(pieDataSet, createLegend); // set the background color for the chart... chart.setBackgroundPaint(Color.white); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setSectionOutlinesVisible(true); plot.setShadowPaint(new Color(104, 104, 104, 100)); int size = pieDataSet.getKeys().size(); for (int i = 0; i < size; i++) { Comparable<?> key = pieDataSet.getKey(i); plot.setSectionPaint(key, getColorProvider(true).getPointColor(i / (double) (size - 1))); boolean explode = false; for (String explosionGroup : explodingGroups) { if (key.toString().startsWith(explosionGroup) || explosionGroup.startsWith(key.toString())) { explode = true; break; } } if (explode) { plot.setExplodePercent(key, this.explodingAmount); } } plot.setLabelFont(LABEL_FONT); plot.setNoDataMessage("No data available"); plot.setCircular(true); plot.setLabelGap(0.02); plot.setOutlinePaint(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 (panel instanceof AbstractChartPanel) { panel.setChart(chart); } else { panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN); final ChartPanelShiftController controller = new ChartPanelShiftController(panel); panel.addMouseListener(controller); panel.addMouseMotionListener(controller); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); } else { // LogService.getGlobal().logNote("Too many columns (" + categoryCount + // "), this chart is only able to plot up to " + MAX_CATEGORIES + // " different categories."); LogService.getRoot().log(Level.INFO, "com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.too_many_columns", new Object[] { categoryCount, MAX_CATEGORIES }); } }
Example 15
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 16
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 17
Source File: VanKrevelenDiagramTask.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
@Override public void run() { try { setStatus(TaskStatus.PROCESSING); logger.info("Create Van Krevelen diagram of " + peakList); // Task canceled? if (isCanceled()) return; JFreeChart chart = null; // 2D, if no third dimension was selected if (zAxisLabel.equals("none")) { chart = create2DVanKrevelenDiagram(); } // 3D, if a third dimension was selected else { chart = create3DVanKrevelenDiagram(); } chart.setBackgroundPaint(Color.white); // create chart JPanel EChartPanel chartPanel = new EChartPanel(chart, true, true, true, true, false); // Create Van Krevelen Diagram window VanKrevelenDiagramWindow frame = new VanKrevelenDiagramWindow(chart, chartPanel, filteredRows); // create chart JPanel frame.add(chartPanel, BorderLayout.CENTER); // set title properties TextTitle chartTitle = chart.getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); LegendTitle legend = chart.getLegend(); legend.setVisible(false); frame.setTitle(title); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setBackground(Color.white); frame.setVisible(true); frame.pack(); logger.info("Finished creating van Krevelen diagram of " + peakList); JOptionPane.showMessageDialog(frame, "Results summary:\n" + displayedFeatures + " feature list rows are displayed in the Van Krevelen diagram.\n" + featuresWithFormulasWithoutCHO + " feature list rows are not displayed, because the annotated molecular formula does not contain the elements C, H, and O.\n" + featuresWithoutFormula + " feature list rows are not displayed, because no molecular formula was assigned."); setStatus(TaskStatus.FINISHED); } catch (Throwable t) { setErrorMessage( "Nothing to plot here or some peaks have other identities than molecular formulas.\n" + "Have you annotated your features with molecular formulas?\n" + "You can use the feature list method \"Formula prediction\" to handle the task."); setStatus(TaskStatus.ERROR); } }
Example 18
Source File: ROCChartPlotter.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
private JFreeChart createChart(XYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title null, // x axis label null, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); ValueAxis valueAxis = plot.getRangeAxis(); valueAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD); valueAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD); domainAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT); DeviationRenderer renderer = new DeviationRenderer(true, false); Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); if (dataset.getSeriesCount() == 1) { renderer.setSeriesStroke(0, stroke); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesFillPaint(0, Color.RED); } else if (dataset.getSeriesCount() == 2) { renderer.setSeriesStroke(0, stroke); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesFillPaint(0, Color.RED); renderer.setSeriesStroke(1, stroke); renderer.setSeriesPaint(1, Color.BLUE); renderer.setSeriesFillPaint(1, Color.BLUE); } else { for (int i = 0; i < dataset.getSeriesCount(); i++) { renderer.setSeriesStroke(i, stroke); Color color = colorProvider.getPointColor((double) i / (double) (dataset.getSeriesCount() - 1)); renderer.setSeriesPaint(i, color); renderer.setSeriesFillPaint(i, color); } } renderer.setAlpha(0.12f); plot.setRenderer(renderer); // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(PlotterAdapter.LABEL_FONT); } return chart; }
Example 19
Source File: MultiPieChartExpression.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
protected void configureSubChart( final JFreeChart chart ) { final TextTitle chartTitle = chart.getTitle(); if ( chartTitle != null ) { if ( getPieTitleFont() != null ) { chartTitle.setFont( getPieTitleFont() ); } else { final Font titleFont = Font.decode( getTitleFont() ); chartTitle.setFont( titleFont ); } } if ( isAntiAlias() == false ) { chart.setAntiAlias( false ); } final LegendTitle chLegend = chart.getLegend(); if ( chLegend != null ) { final RectangleEdge loc = translateEdge( getLegendLocation().toLowerCase() ); if ( loc != null ) { chLegend.setPosition( loc ); } if ( getLegendFont() != null ) { chLegend.setItemFont( Font.decode( getLegendFont() ) ); } if ( !isDrawLegendBorder() ) { chLegend.setBorder( BlockBorder.NONE ); } if ( getLegendBackgroundColor() != null ) { chLegend.setBackgroundPaint( getLegendBackgroundColor() ); } if ( getLegendTextColor() != null ) { chLegend.setItemPaint( getLegendTextColor() ); } } final Plot plot = chart.getPlot(); plot.setNoDataMessageFont( Font.decode( getLabelFont() ) ); final String pieNoData = getPieNoDataMessage(); if ( pieNoData != null ) { plot.setNoDataMessage( pieNoData ); } else { final String message = getNoDataMessage(); if ( message != null ) { plot.setNoDataMessage( message ); } } }
Example 20
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" ); } } } }