List of usage examples for org.jfree.chart.title LegendTitle setFrame
public void setFrame(BlockFrame frame)
From source file:com.rapidminer.gui.plotter.charts.ParallelPlotter2.java
@Override public void updatePlotter() { prepareData();/*www . j a v a 2s . c om*/ JFreeChart chart = createChart(this.dataset); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // general plot settings XYPlot plot = chart.getXYPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis SymbolAxis axis = null; if (this.dataTable.isSupportingColumnWeights()) { List<Double> weightList = new LinkedList<>(); for (int column = 0; column < dataTable.getNumberOfColumns(); column++) { if ((!dataTable.isSpecial(column)) && (column != colorColumn)) { weightList.add(this.dataTable.getColumnWeight(column)); } } double[] weights = new double[weightList.size()]; int index = 0; for (Double d : weightList) { weights[index++] = d; } axis = new WeightBasedSymbolAxis(null, domainAxisMap, weights); } else { axis = new SymbolAxis(null, domainAxisMap); } axis.setTickLabelFont(LABEL_FONT); axis.setLabelFont(LABEL_FONT_BOLD); // rotate labels if (isLabelRotating()) { axis.setTickLabelsVisible(true); axis.setVerticalTickLabels(true); } chart.getXYPlot().setDomainAxis(axis); // renderer final ColorizedLineAndShapeRenderer renderer = new ColorizedLineAndShapeRenderer(this.colorMap); plot.setRenderer(renderer); // legend settings if ((colorColumn >= 0) && (this.dataTable.isNominal(colorColumn))) { final LegendItemCollection legendItemCollection = new LegendItemCollection(); for (int i = 0; i < this.dataTable.getNumberOfValues(colorColumn); i++) { legendItemCollection.add(new LegendItem(this.dataTable.mapIndex(colorColumn, i), null, null, null, new Rectangle2D.Double(0, 0, 7, 7), getColorProvider() .getPointColor(i / (double) (this.dataTable.getNumberOfValues(colorColumn) - 1)), new BasicStroke(0.75f), Color.GRAY)); } chart.addLegend(new LegendTitle(new LegendItemSource() { @Override public LegendItemCollection getLegendItems() { return legendItemCollection; } })); LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } } else if (colorColumn >= 0) { chart.addLegend(new LegendTitle(new LegendItemSource() { @Override public LegendItemCollection getLegendItems() { LegendItemCollection itemCollection = new LegendItemCollection(); itemCollection.add(new LegendItem("Dummy")); return itemCollection; } }) { private static final long serialVersionUID = 1288380309936848376L; @Override public Object draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, java.lang.Object params) { if (dataTable.isDate(colorColumn) || dataTable.isTime(colorColumn) || dataTable.isDateTime(colorColumn)) { drawSimpleDateLegend(g2, (int) (area.getCenterX() - 170), (int) (area.getCenterY() + 7), dataTable, colorColumn, renderer.getMinColorValue(), renderer.getMaxColorValue()); return new BlockResult(); } else { final String minColorString = Tools.formatNumber(renderer.getMinColorValue()); final String maxColorString = Tools.formatNumber(renderer.getMaxColorValue()); drawSimpleNumericalLegend(g2, (int) (area.getCenterX() - 90), (int) (area.getCenterY() + 7), dataTable.getColumnName(colorColumn), minColorString, maxColorString); return new BlockResult(); } } @Override public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area) { draw(g2, area, null); } }); } // chart panel 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); }
From source file:com.rapidminer.gui.plotter.charts.HistogramColorChart.java
@Override protected void updatePlotter() { prepareData();//from w w w . ja va2s. c o m 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("Deviation 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.HistogramColorChart.parsing_property_error"); } JFreeChart chart = null; if (nominal) { // ** nominal ** int categoryCount = this.categoryDataset.getRowCount(); boolean createLegend = categoryCount > 0 && categoryCount < maxClasses && this.drawLegend; String domainName = valueColumn >= 0 ? this.dataTable.getColumnName(valueColumn) : "Value"; chart = ChartFactory.createBarChart(null, // title domainName, "Frequency", categoryDataset, PlotOrientation.VERTICAL, createLegend, true, // tooltips false); // urls CategoryPlot plot = chart.getCategoryPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setBackgroundPaint(Color.WHITE); plot.setForegroundAlpha(this.opaqueness); BarRenderer renderer = new BarRenderer(); if (categoryDataset.getRowCount() == 1) { renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesFillPaint(0, Color.RED); } else { for (int i = 0; i < categoryDataset.getRowCount(); i++) { Color color = getColorProvider(true) .getPointColor((double) i / (double) (categoryDataset.getRowCount() - 1)); renderer.setSeriesPaint(i, color); renderer.setSeriesFillPaint(i, color); } } renderer.setBarPainter(new RapidBarPainter()); renderer.setDrawBarOutline(true); plot.setRenderer(renderer); plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } } else { // ** numerical ** int categoryCount = this.histogramDataset.getSeriesCount(); boolean createLegend = categoryCount > 0 && categoryCount < maxClasses && this.drawLegend; String domainName = valueColumn >= 0 ? this.dataTable.getColumnName(valueColumn) : "Value"; chart = ChartFactory.createHistogram(null, // title domainName, "Frequency", histogramDataset, PlotOrientation.VERTICAL, createLegend, true, // tooltips false); // urls XYPlot plot = chart.getXYPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setBackgroundPaint(Color.WHITE); plot.setForegroundAlpha(this.opaqueness); XYBarRenderer renderer = new XYBarRenderer(); if (histogramDataset.getSeriesCount() == 1) { renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesFillPaint(0, Color.RED); } else { for (int i = 0; i < histogramDataset.getSeriesCount(); i++) { Color color = getColorProvider(true) .getPointColor((double) i / (double) (histogramDataset.getSeriesCount() - 1)); renderer.setSeriesPaint(i, color); renderer.setSeriesFillPaint(i, color); } } renderer.setBarPainter(new RapidXYBarPainter()); renderer.setDrawBarOutline(true); plot.setRenderer(renderer); plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); // Correctly displays dates on x-axis if (datetime) { DateAxis dateAxis = new DateAxis(); dateAxis.setDateFormatOverride(Tools.DATE_TIME_FORMAT.get()); plot.setDomainAxis(dateAxis); } // range axis Range range = getRangeForDimension(valueColumn); if (range != null) { plot.getDomainAxis().setRange(range); } // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setVerticalTickLabels(true); } if (histogramDataset.getSeriesCount() == 1) { String key = histogramDataset.getSeriesKey(0).toString(); int index = this.dataTable.getColumnIndex(key); if (index >= 0) { if (this.dataTable.isNominal(index)) { String[] values = new String[dataTable.getNumberOfValues(index)]; for (int i = 0; i < values.length; i++) { values[i] = dataTable.mapIndex(index, i); } plot.setDomainAxis(new SymbolAxis(key, values)); // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setVerticalTickLabels(true); } } } } } // 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); } AbstractChartPanel panel = getPlotterPanel(); if (panel == null) { panel = createPanel(chart); } else { panel.setChart(chart); } // Disable zooming for Histogram-Charts panel.setRangeZoomable(false); panel.setDomainZoomable(false); // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); }
From source file:MWC.GUI.JFreeChart.NewFormattedJFreeChart.java
public void setShowLegend(final boolean showLegend) { if (showLegend) { if (!isShowLegend()) { LegendTitle legend = new LegendTitle(getPlot()); legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setFrame(new LineBorder()); legend.setBackgroundPaint(Color.white); legend.setPosition(RectangleEdge.BOTTOM); addLegend(legend);// w w w.j a v a2 s . c o m } } else { if (isShowLegend()) { removeLegend(); } } this.fireChartChanged(); }
From source file:com.rapidminer.gui.plotter.charts.SeriesChartPlotter.java
@Override protected void updatePlotter() { int categoryCount = prepareData(); String maxClassesProperty = ParameterService .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT); int maxClasses = 20; try {/* w w w.jav a2s . com*/ 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); }
From source file:org.martus.client.swingui.actions.ActionMenuCharts.java
private LegendTitle createLegend(JFreeChart chart) { LegendTitle legend = new LegendTitle(chart.getPlot()); legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setFrame(new LineBorder()); legend.setBackgroundPaint(Color.white); legend.setPosition(RectangleEdge.BOTTOM); legend.addChangeListener(chart);/*from w w w .j a va 2 s . c om*/ legend.setItemFont(FontHandler.getDefaultFont()); return legend; }
From source file:com.rapidminer.gui.plotter.charts.HistogramChart.java
@Override protected void updatePlotter() { prepareData();//from ww w . j a va 2 s . c o m 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("Deviation 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.HistogramChart.parsing_property_error"); } int categoryCount = this.histogramDataset.getSeriesCount(); boolean createLegend = categoryCount > 0 && categoryCount < maxClasses && this.drawLegend; JFreeChart chart = ChartFactory.createHistogram(null, // title "Value", "Frequency", histogramDataset, PlotOrientation.VERTICAL, createLegend, true, // tooltips false); // urls XYPlot plot = chart.getXYPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setBackgroundPaint(Color.WHITE); plot.setForegroundAlpha(this.opaqueness); XYBarRenderer renderer = new XYBarRenderer(); if (histogramDataset.getSeriesCount() == 1) { renderer.setSeriesPaint(0, ColorProvider.reduceColorBrightness(Color.RED)); renderer.setSeriesFillPaint(0, ColorProvider.reduceColorBrightness(Color.RED)); } else { for (int i = 0; i < histogramDataset.getSeriesCount(); i++) { Color color = getColorProvider(true) .getPointColor((double) i / (double) (histogramDataset.getSeriesCount() - 1)); renderer.setSeriesPaint(i, color); renderer.setSeriesFillPaint(i, color); } } renderer.setBarPainter(new RapidXYBarPainter()); // renderer.setBarPainter(new StandardXYBarPainter()); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); plot.setRenderer(renderer); plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); setRange(plot.getDomainAxis()); // display correct x-Axis labels int count = histogramDataset.getSeriesCount(); if (count > 0) { String key = histogramDataset.getSeriesKey(0).toString(); int index = this.dataTable.getColumnIndex(key); if (index >= 0) { // Correctly displays nominal values on x-axis if (count == 1 && this.dataTable.isNominal(index)) { String[] values = new String[dataTable.getNumberOfValues(index)]; for (int i = 0; i < values.length; i++) { values[i] = dataTable.mapIndex(index, i); } plot.setDomainAxis(new SymbolAxis(key, values)); } // Correctly displays dates on x-axis if (this.dataTable.isDateTime(index)) { boolean applyDateAxis = true; if (count > 1) { for (int i = 1; i < count; i++) { index = this.dataTable.getColumnIndex(histogramDataset.getSeriesKey(i).toString()); if (index < 0 || !this.dataTable.isDateTime(index)) { applyDateAxis = false; break; } } } if (applyDateAxis) { DateAxis dateAxis = new DateAxis(); dateAxis.setDateFormatOverride(Tools.DATE_TIME_FORMAT.get()); plot.setDomainAxis(dateAxis); } } } // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setVerticalTickLabels(true); } } // 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); } AbstractChartPanel panel = getPlotterPanel(); if (panel == null) { panel = createPanel(chart); } else { panel.setChart(chart); } // Disable zooming for Histogram-Charts panel.setRangeZoomable(false); panel.setDomainZoomable(false); // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); }
From source file:net.sf.mzmine.modules.visualization.tic.TICPlot.java
public TICPlot(final ActionListener listener) { super(null, true); // Initialize. visualizer = listener;/*from ww w.java 2s .com*/ labelsVisible = 1; havePeakLabels = false; numOfDataSets = 0; numOfPeaks = 0; showSpectrumRequest = false; // Set cursor. setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); // Y-axis label. final String yAxisLabel; if (listener instanceof TICVisualizerWindow) { yAxisLabel = ((TICVisualizerWindow) listener).getPlotType() == PlotType.BASEPEAK ? "Base peak intensity" : "Total ion intensity"; } else { yAxisLabel = "Base peak intensity"; } // Initialize the chart by default time series chart from factory. final JFreeChart chart = ChartFactory.createXYLineChart("", // title "Retention time", // x-axis label yAxisLabel, // y-axis label null, // data set PlotOrientation.VERTICAL, // orientation true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); setChart(chart); // Title. chartTitle = chart.getTitle(); chartTitle.setFont(TITLE_FONT); chartTitle.setMargin(TITLE_TOP_MARGIN, 0.0, 0.0, 0.0); // Subtitle. chartSubTitle = new TextTitle(); chartSubTitle.setFont(SUBTITLE_FONT); chartSubTitle.setMargin(TITLE_TOP_MARGIN, 0.0, 0.0, 0.0); chart.addSubtitle(chartSubTitle); // Disable maximum size (we don't want scaling). setMaximumDrawWidth(Integer.MAX_VALUE); setMaximumDrawHeight(Integer.MAX_VALUE); // Legend constructed by ChartFactory. final LegendTitle legend = chart.getLegend(); legend.setItemFont(LEGEND_FONT); legend.setFrame(BlockBorder.NONE); // Set the plot properties. plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setAxisOffset(AXIS_OFFSET); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // Set grid properties. plot.setDomainGridlinePaint(GRID_COLOR); plot.setRangeGridlinePaint(GRID_COLOR); // Set cross-hair (selection) properties. if (listener instanceof TICVisualizerWindow) { plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.setDomainCrosshairPaint(CROSS_HAIR_COLOR); plot.setRangeCrosshairPaint(CROSS_HAIR_COLOR); plot.setDomainCrosshairStroke(CROSS_HAIR_STROKE); plot.setRangeCrosshairStroke(CROSS_HAIR_STROKE); } // Set the x-axis (retention time) properties. final NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setNumberFormatOverride(MZmineCore.getConfiguration().getRTFormat()); xAxis.setUpperMargin(AXIS_MARGINS); xAxis.setLowerMargin(AXIS_MARGINS); // Set the y-axis (intensity) properties. final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setNumberFormatOverride(MZmineCore.getConfiguration().getIntensityFormat()); // Set default renderer properties. defaultRenderer = new TICPlotRenderer(); defaultRenderer.setBaseShapesFilled(true); defaultRenderer.setDrawOutlines(false); defaultRenderer.setUseFillPaint(true); defaultRenderer.setBaseItemLabelPaint(LABEL_COLOR); // Set label generator final XYItemLabelGenerator labelGenerator = new TICItemLabelGenerator(this); defaultRenderer.setBaseItemLabelGenerator(labelGenerator); defaultRenderer.setBaseItemLabelsVisible(true); // Set toolTipGenerator final XYToolTipGenerator toolTipGenerator = new TICToolTipGenerator(); defaultRenderer.setBaseToolTipGenerator(toolTipGenerator); // Set focus state to receive key events. setFocusable(true); // Register key handlers. GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("LEFT"), listener, "MOVE_CURSOR_LEFT"); GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("RIGHT"), listener, "MOVE_CURSOR_RIGHT"); GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("SPACE"), listener, "SHOW_SPECTRUM"); GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke('+'), this, "ZOOM_IN"); GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke('-'), this, "ZOOM_OUT"); // Add items to popup menu. final JPopupMenu popupMenu = getPopupMenu(); popupMenu.addSeparator(); if (listener instanceof TICVisualizerWindow) { popupMenu.add(new ExportPopUpMenu((TICVisualizerWindow) listener)); popupMenu.addSeparator(); popupMenu.add(new AddFilePopupMenu((TICVisualizerWindow) listener)); popupMenu.add(new RemoveFilePopupMenu((TICVisualizerWindow) listener)); popupMenu.add(new ExportPopUpMenu((TICVisualizerWindow) listener)); popupMenu.addSeparator(); } GUIUtils.addMenuItem(popupMenu, "Toggle showing peak values", this, "SHOW_ANNOTATIONS"); GUIUtils.addMenuItem(popupMenu, "Toggle showing data points", this, "SHOW_DATA_POINTS"); if (listener instanceof TICVisualizerWindow) { popupMenu.addSeparator(); GUIUtils.addMenuItem(popupMenu, "Show spectrum of selected scan", listener, "SHOW_SPECTRUM"); } popupMenu.addSeparator(); GUIUtils.addMenuItem(popupMenu, "Set axes range", this, "SETUP_AXES"); if (listener instanceof TICVisualizerWindow) { GUIUtils.addMenuItem(popupMenu, "Set same range to all windows", this, "SET_SAME_RANGE"); } }
From source file:com.rapidminer.gui.plotter.charts.WebPlotter.java
@Override public void updatePlotter() { final int categoryCount = prepareData(); SwingUtilities.invokeLater(new Runnable() { @Override//from www. j ava 2 s . c o m 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 }); } }
From source file:org.tiefaces.components.websheet.chart.ChartHelper.java
/** * finalize the style for jfreechart. The default setting is different from * jfreechart and Excel. We try to minimize the difference. * //from w w w . j av a 2 s . co m * @param chart * jfreechart. * @param chartData * contain information gathered from excel chart object. */ private void setupStyle(final JFreeChart chart, final ChartData chartData) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); List<ChartSeries> seriesList = chartData.getSeriesList(); BasicStroke bLine = new BasicStroke(2.0f); for (int i = 0; i < seriesList.size(); i++) { Color cColor = ColorUtility.xssfClrToClr(seriesList.get(i).getSeriesColor().getXssfColor()); plot.getRenderer().setSeriesPaint(i, cColor); plot.getRenderer().setSeriesStroke(i, bLine); } plot.setBackgroundPaint(ColorUtility.xssfClrToClr(chartData.getBgColor().getXssfColor())); // below are modifications for default setting in excel chart // to-do: need read setting from xml in future plot.setOutlineVisible(false); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); plot.setRangeGridlineStroke(new BasicStroke(TieConstants.DEFAULT_BASIC_STROKE)); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); chart.setBackgroundPaint(Color.WHITE); LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); legend.setFrame(BlockBorder.NONE); }
From source file:com.rapidminer.gui.plotter.charts.ParetoChartPlotter.java
public void paintParetoChart(Graphics graphics) { prepareData();//from w w w . j a va 2s.co m 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); } }