List of usage examples for org.jfree.chart.title LegendTitle setBorder
public void setBorder(double top, double left, double bottom, double right)
From source file:org.gbif.portal.web.util.ChartUtils.java
/** * Writes out the image using the supplied file name. * /*from w w w . j a v a 2s .c o m*/ * @param legend * @param fileName * @return */ public static String writePieChartImageToTempFile(Map<String, Double> legend, String fileName) { String filePath = System.getProperty(tmpDirSystemProperty) + File.separator + fileName + defaultExtension; File fileToCheck = new File(filePath); if (fileToCheck.exists()) { return fileName + defaultExtension; } final DefaultPieDataset data = new DefaultPieDataset(); Set<String> keys = legend.keySet(); for (String key : keys) { logger.info("Adding key : " + key); data.setValue(key, legend.get(key)); } // create a pie chart... final boolean withLegend = true; final JFreeChart chart = ChartFactory.createPieChart(null, data, withLegend, false, false); PiePlot piePlot = (PiePlot) chart.getPlot(); piePlot.setLabelFont(new Font("Arial", Font.PLAIN, 10)); piePlot.setLabelBackgroundPaint(Color.WHITE); LegendTitle lt = chart.getLegend(); lt.setBackgroundPaint(Color.WHITE); lt.setWidth(300); lt.setBorder(0, 0, 0, 0); lt.setItemFont(new Font("Arial", Font.PLAIN, 11)); chart.setPadding(new RectangleInsets(0, 0, 0, 0)); chart.setBorderVisible(false); chart.setBackgroundImageAlpha(0); chart.setBackgroundPaint(Color.WHITE); chart.setBorderPaint(Color.LIGHT_GRAY); final BufferedImage image = new BufferedImage(300, 250, BufferedImage.TYPE_INT_RGB); KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter(); adapter.setQuality(1); try { adapter.encode(image); } catch (IOException e) { logger.error(e.getMessage(), e); } final Graphics2D g2 = image.createGraphics(); g2.setFont(new Font("Arial", Font.PLAIN, 11)); final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 300, 250); // draw chart.draw(g2, chartArea, null, null); try { FileOutputStream fOut = new FileOutputStream(fileToCheck); ChartUtilities.writeChartAsPNG(fOut, chart, 300, 250); return fileToCheck.getName(); } catch (IOException e) { logger.error(e.getMessage(), e); return null; } }
From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java
/** * Sets the colours and gradients to be used when painting the given JFreeChart. * // ww w.j a v a2 s. c o m * @param chart * The JFreeChart to make nice. */ public static void makeChartNice(JFreeChart chart) { Plot plot = chart.getPlot(); chart.setBackgroundPaint(null); chart.setBorderStroke(new BasicStroke(1f)); chart.setBorderPaint(new Color(0xDDDDDD)); chart.setBorderVisible(true); // TODO Should we add an option for subtitles, this is where it would go. // TextTitle subTitle = new TextTitle("What's up doc?", // new Font("SansSerif", Font.BOLD, 8)); // chart.addSubtitle(subTitle); // overall plot plot.setOutlinePaint(null); plot.setInsets(new RectangleInsets(0, 5, 0, 5)); // also the overall chart panel plot.setBackgroundPaint(null); plot.setDrawingSupplier(new WabitDrawingSupplier()); // legend LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setBorder(0, 0, 0, 0); legend.setBackgroundPaint(null); legend.setPadding(2, 2, 2, 2); } if (plot instanceof CategoryPlot) { CategoryPlot cplot = (CategoryPlot) plot; CategoryItemRenderer renderer = cplot.getRenderer(); if (renderer instanceof BarRenderer) { BarRenderer brenderer = (BarRenderer) renderer; brenderer.setBarPainter(new StandardBarPainter()); brenderer.setDrawBarOutline(false); brenderer.setShadowVisible(false); brenderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); } else if (renderer instanceof LineAndShapeRenderer) { // it's all taken care of by WabitDrawingSupplier } else { logger.warn("I don't know how to make " + renderer + " pretty. Leaving ugly."); } cplot.setRangeGridlinePaint(Color.BLACK); cplot.setRangeGridlineStroke(GRIDLINE_STROKE); // axes for (int i = 0; i < cplot.getDomainAxisCount(); i++) { CategoryAxis axis = cplot.getDomainAxis(i); axis.setAxisLineVisible(false); } for (int i = 0; i < cplot.getRangeAxisCount(); i++) { ValueAxis axis = cplot.getRangeAxis(i); axis.setAxisLineVisible(false); } } if (plot instanceof MultiplePiePlot) { MultiplePiePlot mpplot = (MultiplePiePlot) plot; JFreeChart pchart = mpplot.getPieChart(); PiePlot3DGradient pplot = (PiePlot3DGradient) pchart.getPlot(); pplot.setBackgroundPaint(null); pplot.setOutlinePaint(null); pplot.setFaceGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); pplot.setSideGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); CategoryDataset data = mpplot.getDataset(); Color[][] colours = WabitDrawingSupplier.SERIES_COLOURS; //Set all colours for (int i = 0; i < colours.length; i++) { if (data.getColumnCount() >= i + 1) { pplot.setSectionOutlinePaint(data.getColumnKey(i), null); GradientPaint gradient = new GradientPaint(0, 0f, colours[i][0], 100, 0f, colours[i][1]); pplot.setSectionPaint(data.getColumnKey(i), gradient); gradient = new GradientPaint(0, 0f, colours[i][1], 100, 0f, colours[i][0]); pplot.setSidePaint(data.getColumnKey(i), gradient); } } } // Tweak the title font size chart.getTitle().setFont(chart.getTitle().getFont().deriveFont(14f)); chart.getTitle().setPadding(5, 0, 5, 0); chart.setAntiAlias(true); // shrink padding chart.setPadding(new RectangleInsets(0, 0, 0, 0)); }
From source file:com.manydesigns.portofino.chart.Chart1DGenerator.java
public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) { DefaultPieDataset dataset = new DefaultPieDataset(); java.util.List<Object[]> result; String query = chartDefinition.getQuery(); logger.info(query);/* w ww.j a v a 2s . c om*/ Session session = persistence.getSession(chartDefinition.getDatabase()); result = QueryUtils.runSql(session, query); for (Object[] current : result) { ComparableWrapper key = new ComparableWrapper((Comparable) current[0]); dataset.setValue(key, (Number) current[1]); if (current.length > 2) { key.setLabel(current[2].toString()); } } JFreeChart chart = createChart(chartDefinition, dataset); chart.setAntiAlias(isAntiAlias()); // impostiamo il bordo invisibile // eventualmente e' il css a fornirne uno // eventualmente e' il css a fornirne uno chart.setBorderVisible(isBorderVisible()); // impostiamo il titolo TextTitle title = chart.getTitle(); title.setFont(titleFont); title.setMargin(10.0, 0.0, 0.0, 0.0); // ottieni il Plot PiePlot plot = (PiePlot) chart.getPlot(); String urlExpression = chartDefinition.getUrlExpression(); if (!StringUtils.isBlank(urlExpression)) { PieURLGenerator urlGenerator = new ChartPieUrlGenerator(urlExpression); plot.setURLGenerator(urlGenerator); } else { plot.setURLGenerator(null); } // il plot ha sfondo e bordo trasparente // (quindi si vede il colore del chart) plot.setBackgroundPaint(transparentColor); plot.setOutlinePaint(transparentColor); // Modifico il toolTip // hongliangpan add // :?{0} {1} {2} ? ,??? plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); // {0}={1}({2}) plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}")); // ?(0.0-1.0) // plot.setForegroundAlpha(1.0f); // imposta la distanza delle etichette dal plot plot.setLabelGap(0.03); // plot.setLabelGenerator(new MyPieSectionLabelGenerator()); // imposta il messaggio se non ci sono dati plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available")); plot.setCircular(true); plot.setBaseSectionOutlinePaint(Color.BLACK); DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier()); plot.setDrawingSupplier(supplier); // ? plot.setForegroundAlpha(1.0f); // impostiamo il titolo della legenda String legendString = chartDefinition.getLegend(); Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0)); subtitle.setMargin(0, 0, 5, 0); chart.addSubtitle(subtitle); // impostiamo la legenda LegendTitle legend = chart.getLegend(); legend.setBorder(0, 0, 0, 0); legend.setItemFont(legendItemFont); int legendMargin = 10; legend.setMargin(0.0, legendMargin, legendMargin, legendMargin); legend.setBackgroundPaint(transparentColor); // impostiamo un gradiente orizzontale Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, getHeight(), Color.WHITE); chart.setBackgroundPaint(chartBgPaint); return chart; }
From source file:guineu.modules.visualization.intensityplot.IntensityPlotFrame.java
public IntensityPlotFrame(ParameterSet parameters) { super("", true, true, true, true); String title = "Intensity plot [" + GuineuCore.getDesktop().getSelectedDataFiles()[0].getDatasetName() + "]"; String xAxisLabel = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue().toString(); // create dataset dataset = new IntensityPlotDataset(parameters); // create new JFreeChart logger.finest("Creating new chart instance"); chart = ChartFactory.createLineChart(title, xAxisLabel, "Height", dataset, PlotOrientation.VERTICAL, true, true, false);//from ww w .j av a2s. c om CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set renderer StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); renderer.setBaseStroke(new BasicStroke(2)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); // set tooltip generator CategoryToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator(); renderer.setBaseToolTipGenerator(toolTipGenerator); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); chart.setBackgroundPaint(Color.white); // create chart JPanel ChartPanel chartPanel = new ChartPanel(chart); add(chartPanel, BorderLayout.CENTER); IntensityPlotToolBar toolBar = new IntensityPlotToolBar(this); add(toolBar, BorderLayout.EAST); // disable maximum size (we don't want scaling) chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); // set title properties TextTitle chartTitle = chart.getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); LegendTitle legend = chart.getLegend(); legend.setItemFont(legendFont); legend.setBorder(0, 0, 0, 0); Plot dplot = chart.getPlot(); // set shape provider IntensityPlotDrawingSupplier shapeSupplier = new IntensityPlotDrawingSupplier(); dplot.setDrawingSupplier(shapeSupplier); // set y axis properties NumberAxis yAxis; yAxis = (NumberAxis) ((CategoryPlot) dplot).getRangeAxis(); NumberFormat yAxisFormat = new DecimalFormat("0.0E0"); yAxis.setNumberFormatOverride(yAxisFormat); setTitle(title); setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE); setBackground(Color.white); pack(); }
From source file:guineu.modules.visualization.intensityboxplot.IntensityBoxPlotFrame.java
public IntensityBoxPlotFrame(ParameterSet parameters) { super("", true, true, true, true); String title = "Intensity box plot [" + GuineuCore.getDesktop().getSelectedDataFiles()[0].getDatasetName() + "]"; String xAxisLabel = parameters.getParameter(IntensityBoxPlotParameters.xAxisValueSource).getValue() .toString();//from ww w.j ava 2 s . c o m this.xAxisValueSource = parameters.getParameter(IntensityBoxPlotParameters.xAxisValueSource).getValue(); // create dataset this.selectedFiles = parameters.getParameter(IntensityBoxPlotParameters.dataFiles).getValue(); this.selectedRows = parameters.getParameter(IntensityBoxPlotParameters.selectedRows).getValue(); this.dataset = this.createSampleDataset(); // create new JFreeChart logger.finest("Creating new chart instance"); // chart = ChartFactory.createLineChart(title, xAxisLabel, "Intensity", // dataset, PlotOrientation.VERTICAL, true, true, false); // CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set renderer BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(true); // set tooltip generator renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); // plot.setRenderer(renderer); // plot.setBackgroundPaint(Color.white); // CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); // xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // set y axis properties final CategoryAxis xAxis = new CategoryAxis("Type"); final NumberAxis yAxis = new NumberAxis("Value"); NumberFormat yAxisFormat = new DecimalFormat("0.0E0"); yAxis.setNumberFormatOverride(yAxisFormat); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); final JFreeChart chart = new JFreeChart("Intensity Box plot", new Font("SansSerif", Font.BOLD, 14), plot, true); chart.setBackgroundPaint(Color.white); // create chart JPanel ChartPanel chartPanel = new ChartPanel(chart); add(chartPanel, BorderLayout.CENTER); // IntensityBoxPlotToolBar toolBar = new IntensityBoxPlotToolBar(this); // add(toolBar, BorderLayout.EAST); // disable maximum size (we don't want scaling) chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); // set title properties TextTitle chartTitle = chart.getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); LegendTitle legend = chart.getLegend(); legend.setItemFont(legendFont); legend.setBorder(0, 0, 0, 0); // set shape provider IntensityBoxPlotDrawingSupplier shapeSupplier = new IntensityBoxPlotDrawingSupplier(); plot.setDrawingSupplier(shapeSupplier); setTitle(title); setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE); setBackground(Color.white); pack(); }
From source file:net.sf.mzmine.modules.visualization.intensityplot.IntensityPlotFrame.java
public IntensityPlotFrame(ParameterSet parameters) { PeakList peakList = parameters.getParameter(IntensityPlotParameters.peakList).getValue()[0]; String title = "Intensity plot [" + peakList + "]"; String xAxisLabel = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue().toString(); String yAxisLabel = parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue().toString(); // create dataset dataset = new IntensityPlotDataset(parameters); // create new JFreeChart logger.finest("Creating new chart instance"); Object xAxisValueSource = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue(); boolean isCombo = (xAxisValueSource instanceof ParameterWrapper) && (((ParameterWrapper) xAxisValueSource).getParameter() instanceof ComboParameter); if ((xAxisValueSource == IntensityPlotParameters.rawDataFilesOption) || isCombo) { chart = ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false);/*from w ww. j a va2 s .c o m*/ CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set renderer StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); renderer.setBaseStroke(new BasicStroke(2)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); // set tooltip generator CategoryToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator(); renderer.setBaseToolTipGenerator(toolTipGenerator); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); } else { chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setBaseStroke(new BasicStroke(2)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); // set tooltip generator XYToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator(); renderer.setBaseToolTipGenerator(toolTipGenerator); } chart.setBackgroundPaint(Color.white); // create chart JPanel ChartPanel chartPanel = new ChartPanel(chart); add(chartPanel, BorderLayout.CENTER); IntensityPlotToolBar toolBar = new IntensityPlotToolBar(this); add(toolBar, BorderLayout.EAST); // disable maximum size (we don't want scaling) chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); // set title properties TextTitle chartTitle = chart.getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); LegendTitle legend = chart.getLegend(); legend.setItemFont(legendFont); legend.setBorder(0, 0, 0, 0); Plot plot = chart.getPlot(); // set shape provider IntensityPlotDrawingSupplier shapeSupplier = new IntensityPlotDrawingSupplier(); plot.setDrawingSupplier(shapeSupplier); // set y axis properties NumberAxis yAxis; if (plot instanceof CategoryPlot) yAxis = (NumberAxis) ((CategoryPlot) plot).getRangeAxis(); else yAxis = (NumberAxis) ((XYPlot) plot).getRangeAxis(); NumberFormat yAxisFormat = MZmineCore.getConfiguration().getIntensityFormat(); if (parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue() == YAxisValueSource.RT) yAxisFormat = MZmineCore.getConfiguration().getRTFormat(); yAxis.setNumberFormatOverride(yAxisFormat); setTitle(title); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBackground(Color.white); pack(); }
From source file:com.manydesigns.portofino.chart.Chart2DGenerator.java
public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); java.util.List<Object[]> result; String query = chartDefinition.getQuery(); logger.info(query);/* w ww .ja va2s. c o m*/ Session session = persistence.getSession(chartDefinition.getDatabase()); result = QueryUtils.runSql(session, query); for (Object[] current : result) { ComparableWrapper x = new ComparableWrapper((Comparable) current[0]); ComparableWrapper y = new ComparableWrapper((Comparable) current[1]); if (current.length > 3) { x.setLabel(current[3].toString()); } if (current.length > 4) { y.setLabel(current[4].toString()); } dataset.setValue((Number) current[2], x, y); } PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL; if (chartDefinition.getActualOrientation() == ChartDefinition.Orientation.VERTICAL) { plotOrientation = PlotOrientation.VERTICAL; } JFreeChart chart = createChart(chartDefinition, dataset, plotOrientation); chart.setAntiAlias(antiAlias); // impostiamo il bordo invisibile // eventualmente e' il css a fornirne uno chart.setBorderVisible(borderVisible); // impostiamo il titolo TextTitle title = chart.getTitle(); title.setFont(titleFont); title.setMargin(10.0, 0.0, 0.0, 0.0); // ottieni il Plot CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); String urlExpression = chartDefinition.getUrlExpression(); if (!StringUtils.isBlank(urlExpression)) { CategoryURLGenerator urlGenerator = new ChartBarUrlGenerator(chartDefinition.getUrlExpression()); renderer.setBaseItemURLGenerator(urlGenerator); } else { renderer.setBaseItemURLGenerator(null); } renderer.setBaseOutlinePaint(Color.BLACK); // /////////////// if (renderer instanceof BarRenderer) { BarRenderer barRenderer = (BarRenderer) renderer; barRenderer.setDrawBarOutline(true); barRenderer.setShadowVisible(false); barRenderer.setBarPainter(new StandardBarPainter()); } // /////////////// // il plot ha sfondo e bordo trasparente // (quindi si vede il colore del chart) plot.setBackgroundPaint(transparentColor); plot.setOutlinePaint(transparentColor); // Modifico il toolTip // plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} ({2})")); // imposta il messaggio se non ci sono dati plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available")); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.GRAY); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); // Category axis CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setAxisLinePaint(Color.BLACK); categoryAxis.setLabelFont(axisFont); categoryAxis.setAxisLineVisible(true); // impostiamo la rotazione dell'etichetta if (plot.getOrientation() == PlotOrientation.VERTICAL) { CategoryLabelPosition pos = new CategoryLabelPosition(RectangleAnchor.TOP_LEFT, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 4.0, CategoryLabelWidthType.CATEGORY, 100); CategoryLabelPositions positions = new CategoryLabelPositions(pos, pos, pos, pos); categoryAxis.setCategoryLabelPositions(positions); categoryAxis.setMaximumCategoryLabelWidthRatio(6.0f); height = 333; } else { categoryAxis.setMaximumCategoryLabelWidthRatio(0.4f); // recuperiamo 8 pixel a sinistra plot.setInsets(new RectangleInsets(4.0, 0.0, 4.0, 8.0)); height = 74; // contiamo gli elementi nel dataset height += 23 * dataset.getColumnCount(); height += 57; } Axis rangeAxis = plot.getRangeAxis(); rangeAxis.setAxisLinePaint(Color.BLACK); rangeAxis.setLabelFont(axisFont); DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier()); plot.setDrawingSupplier(supplier); // ? plot.setForegroundAlpha(1.0f); // impostiamo il titolo della legenda String legendString = chartDefinition.getLegend(); Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0)); subtitle.setMargin(0, 0, 5, 0); chart.addSubtitle(subtitle); // impostiamo la legenda LegendTitle legend = chart.getLegend(); legend.setBorder(0, 0, 0, 0); legend.setItemFont(legendItemFont); int legendMargin = 10; legend.setMargin(0.0, legendMargin, legendMargin, legendMargin); legend.setBackgroundPaint(transparentColor); // impostiamo un gradiente orizzontale Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, height, Color.WHITE); chart.setBackgroundPaint(chartBgPaint); return chart; }
From source file:net.sf.mzmine.modules.visualization.intensityplot.IntensityPlotWindow.java
public IntensityPlotWindow(ParameterSet parameters) { PeakList peakList = parameters.getParameter(IntensityPlotParameters.peakList).getValue() .getMatchingPeakLists()[0];/*from w ww . j a va 2 s . co m*/ String title = "Intensity plot [" + peakList + "]"; String xAxisLabel = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue().toString(); String yAxisLabel = parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue().toString(); // create dataset dataset = new IntensityPlotDataset(parameters); // create new JFreeChart logger.finest("Creating new chart instance"); Object xAxisValueSource = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue(); boolean isCombo = (xAxisValueSource instanceof ParameterWrapper) && (!(((ParameterWrapper) xAxisValueSource).getParameter() instanceof DoubleParameter)); if ((xAxisValueSource == IntensityPlotParameters.rawDataFilesOption) || isCombo) { chart = ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set renderer StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); renderer.setBaseStroke(new BasicStroke(2)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); // set tooltip generator CategoryToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator(); renderer.setBaseToolTipGenerator(toolTipGenerator); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); } else { chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setBaseStroke(new BasicStroke(2)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); // set tooltip generator XYToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator(); renderer.setBaseToolTipGenerator(toolTipGenerator); } chart.setBackgroundPaint(Color.white); // create chart JPanel ChartPanel chartPanel = new ChartPanel(chart); add(chartPanel, BorderLayout.CENTER); IntensityPlotToolBar toolBar = new IntensityPlotToolBar(this); add(toolBar, BorderLayout.EAST); // disable maximum size (we don't want scaling) chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); // set title properties TextTitle chartTitle = chart.getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); LegendTitle legend = chart.getLegend(); legend.setItemFont(legendFont); legend.setBorder(0, 0, 0, 0); Plot plot = chart.getPlot(); // set shape provider IntensityPlotDrawingSupplier shapeSupplier = new IntensityPlotDrawingSupplier(); plot.setDrawingSupplier(shapeSupplier); // set y axis properties NumberAxis yAxis; if (plot instanceof CategoryPlot) yAxis = (NumberAxis) ((CategoryPlot) plot).getRangeAxis(); else yAxis = (NumberAxis) ((XYPlot) plot).getRangeAxis(); NumberFormat yAxisFormat = MZmineCore.getConfiguration().getIntensityFormat(); if (parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue() == YAxisValueSource.RT) yAxisFormat = MZmineCore.getConfiguration().getRTFormat(); yAxis.setNumberFormatOverride(yAxisFormat); setTitle(title); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBackground(Color.white); // Add the Windows menu JMenuBar menuBar = new JMenuBar(); menuBar.add(new WindowsMenu()); setJMenuBar(menuBar); pack(); // get the window settings parameter ParameterSet paramSet = MZmineCore.getConfiguration().getModuleParameters(IntensityPlotModule.class); WindowSettingsParameter settings = paramSet.getParameter(IntensityPlotParameters.windowSettings); // update the window and listen for changes settings.applySettingsToWindow(this); this.addComponentListener(settings); }
From source file:com.manydesigns.portofino.chart.ChartBarGenerator.java
public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); java.util.List<Object[]> result; String query = chartDefinition.getQuery(); logger.info(query);/* w w w. j a va 2s . c o m*/ Session session = persistence.getSession(chartDefinition.getDatabase()); result = QueryUtils.runSql(session, query); for (Object[] current : result) { ComparableWrapper x = new ComparableWrapper((Comparable) current[0]); ComparableWrapper y = new ComparableWrapper((Comparable) current[1]); if (current.length > 3) { x.setLabel(current[3].toString()); } if (current.length > 4) { y.setLabel(current[4].toString()); } dataset.setValue((Number) current[2], x, y); } PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL; if (chartDefinition.getActualOrientation() == ChartDefinition.Orientation.VERTICAL) { plotOrientation = PlotOrientation.VERTICAL; } JFreeChart chart = createChart(chartDefinition, dataset, plotOrientation); chart.setAntiAlias(antiAlias); // impostiamo il bordo invisibile // eventualmente e' il css a fornirne uno chart.setBorderVisible(borderVisible); // impostiamo il titolo TextTitle title = chart.getTitle(); title.setFont(titleFont); title.setMargin(10.0, 0.0, 0.0, 0.0); // ottieni il Plot CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); String urlExpression = chartDefinition.getUrlExpression(); if (!StringUtils.isBlank(urlExpression)) { CategoryURLGenerator urlGenerator = new ChartBarUrlGenerator(chartDefinition.getUrlExpression()); renderer.setBaseItemURLGenerator(urlGenerator); } else { renderer.setBaseItemURLGenerator(null); } renderer.setBaseOutlinePaint(Color.BLACK); // /////////////// if (renderer instanceof BarRenderer || renderer instanceof BarRenderer3D) { BarRenderer barRenderer = (BarRenderer) renderer; barRenderer.setDrawBarOutline(true); barRenderer.setShadowVisible(false); barRenderer.setBarPainter(new StandardBarPainter()); // hongliangpan add barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); barRenderer.setBaseItemLabelsVisible(true); // ? setSeriesItemLabelGenerator barRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); // bar??? barRenderer.setMinimumBarLength(0.02); // barRenderer.setMaximumBarWidth(0.05); // ????? // ??90,??/3.14 ItemLabelPosition itemLabelPositionFallback = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT, TextAnchor.HALF_ASCENT_LEFT, -1.57D); // ??labelposition // barRenderer.setPositiveItemLabelPositionFallback(itemLabelPositionFallback); // barRenderer.setNegativeItemLabelPositionFallback(itemLabelPositionFallback); barRenderer.setItemLabelsVisible(true); // ? barRenderer.setBaseOutlinePaint(Color.BLACK); // ??? barRenderer.setDrawBarOutline(true); // ??? barRenderer.setItemMargin(0.0); // ? barRenderer.setIncludeBaseInRange(true); barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); barRenderer.setBaseItemLabelsVisible(true); // ? plot.setForegroundAlpha(1.0f); } // /////////////// // il plot ha sfondo e bordo trasparente // (quindi si vede il colore del chart) plot.setBackgroundPaint(transparentColor); plot.setOutlinePaint(transparentColor); // Modifico il toolTip // plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} ({2})")); // imposta il messaggio se non ci sono dati plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available")); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.GRAY); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); // Category axis CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setAxisLinePaint(Color.BLACK); categoryAxis.setLabelFont(axisFont); categoryAxis.setAxisLineVisible(true); // impostiamo la rotazione dell'etichetta if (plot.getOrientation() == PlotOrientation.VERTICAL) { CategoryLabelPosition pos = new CategoryLabelPosition(RectangleAnchor.TOP_LEFT, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 4.0, CategoryLabelWidthType.CATEGORY, 100); CategoryLabelPositions positions = new CategoryLabelPositions(pos, pos, pos, pos); categoryAxis.setCategoryLabelPositions(positions); categoryAxis.setMaximumCategoryLabelWidthRatio(6.0f); height = 333; } else { categoryAxis.setMaximumCategoryLabelWidthRatio(0.4f); // recuperiamo 8 pixel a sinistra plot.setInsets(new RectangleInsets(4.0, 0.0, 4.0, 8.0)); height = 74; // contiamo gli elementi nel dataset height += 23 * dataset.getColumnCount(); height += 57; } Axis rangeAxis = plot.getRangeAxis(); rangeAxis.setAxisLinePaint(Color.BLACK); rangeAxis.setLabelFont(axisFont); DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier()); plot.setDrawingSupplier(supplier); // impostiamo il titolo della legenda String legendString = chartDefinition.getLegend(); Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0)); subtitle.setMargin(0, 0, 5, 0); chart.addSubtitle(subtitle); // impostiamo la legenda LegendTitle legend = chart.getLegend(); legend.setBorder(0, 0, 0, 0); legend.setItemFont(legendItemFont); int legendMargin = 10; legend.setMargin(0.0, legendMargin, legendMargin, legendMargin); legend.setBackgroundPaint(transparentColor); // impostiamo un gradiente orizzontale Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, height, Color.WHITE); chart.setBackgroundPaint(chartBgPaint); return chart; }
From source file:com.manydesigns.portofino.chart.ChartStackedBarGenerator.java
public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); java.util.List<Object[]> result; String query = chartDefinition.getQuery(); logger.info(query);// w ww. ja v a2 s. c o m Session session = persistence.getSession(chartDefinition.getDatabase()); result = QueryUtils.runSql(session, query); for (Object[] current : result) { ComparableWrapper x = new ComparableWrapper((Comparable) current[0]); ComparableWrapper y = new ComparableWrapper((Comparable) current[1]); if (current.length > 3) { x.setLabel(current[3].toString()); } if (current.length > 4) { y.setLabel(current[4].toString()); } dataset.setValue((Number) current[2], x, y); } PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL; if (chartDefinition.getActualOrientation() == ChartDefinition.Orientation.VERTICAL) { plotOrientation = PlotOrientation.VERTICAL; } JFreeChart chart = createChart(chartDefinition, dataset, plotOrientation); chart.setAntiAlias(antiAlias); // impostiamo il bordo invisibile // eventualmente e' il css a fornirne uno chart.setBorderVisible(borderVisible); // impostiamo il titolo TextTitle title = chart.getTitle(); title.setFont(titleFont); title.setMargin(10.0, 0.0, 0.0, 0.0); // ottieni il Plot CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); String urlExpression = chartDefinition.getUrlExpression(); if (!StringUtils.isBlank(urlExpression)) { CategoryURLGenerator urlGenerator = new ChartBarUrlGenerator(chartDefinition.getUrlExpression()); renderer.setBaseItemURLGenerator(urlGenerator); } else { renderer.setBaseItemURLGenerator(null); } renderer.setBaseOutlinePaint(Color.BLACK); // /////////////// if (renderer instanceof BarRenderer) { BarRenderer barRenderer = (BarRenderer) renderer; barRenderer.setDrawBarOutline(true); barRenderer.setShadowVisible(false); barRenderer.setBarPainter(new StandardBarPainter()); // hongliangpan add // ? barRenderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator()); // bar??? barRenderer.setMinimumBarLength(0.02); // barRenderer.setMaximumBarWidth(0.06); } if (renderer instanceof StackedBarRenderer3D || renderer instanceof StackedBarRenderer) { BarRenderer barRenderer = (BarRenderer) renderer; barRenderer.setDrawBarOutline(true); barRenderer.setShadowVisible(false); barRenderer.setBarPainter(new StandardBarPainter()); // hongliangpan add // ? setSeriesItemLabelGenerator barRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); // bar??? barRenderer.setMinimumBarLength(0.02); // barRenderer.setMaximumBarWidth(0.06); // ????? ItemLabelPosition itemLabelPositionFallback = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT, TextAnchor.HALF_ASCENT_LEFT, -1.57D); // ??labelposition barRenderer.setPositiveItemLabelPositionFallback(itemLabelPositionFallback); barRenderer.setNegativeItemLabelPositionFallback(itemLabelPositionFallback); barRenderer.setItemLabelsVisible(true); barRenderer.setItemMargin(10); } // /////////////// // il plot ha sfondo e bordo trasparente // (quindi si vede il colore del chart) plot.setBackgroundPaint(transparentColor); plot.setOutlinePaint(transparentColor); // Modifico il toolTip // plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} ({2})")); // imposta il messaggio se non ci sono dati plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available")); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.GRAY); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); // Category axis CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setAxisLinePaint(Color.BLACK); categoryAxis.setLabelFont(axisFont); categoryAxis.setAxisLineVisible(true); // impostiamo la rotazione dell'etichetta if (plot.getOrientation() == PlotOrientation.VERTICAL) { CategoryLabelPosition pos = new CategoryLabelPosition(RectangleAnchor.TOP_LEFT, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 4.0, CategoryLabelWidthType.CATEGORY, 100); CategoryLabelPositions positions = new CategoryLabelPositions(pos, pos, pos, pos); categoryAxis.setCategoryLabelPositions(positions); categoryAxis.setMaximumCategoryLabelWidthRatio(6.0f); height = 333; } else { categoryAxis.setMaximumCategoryLabelWidthRatio(0.4f); // recuperiamo 8 pixel a sinistra plot.setInsets(new RectangleInsets(4.0, 0.0, 4.0, 8.0)); height = 74; // contiamo gli elementi nel dataset height += 23 * dataset.getColumnCount(); height += 57; } Axis rangeAxis = plot.getRangeAxis(); rangeAxis.setAxisLinePaint(Color.BLACK); rangeAxis.setLabelFont(axisFont); DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier()); plot.setDrawingSupplier(supplier); // impostiamo il titolo della legenda String legendString = chartDefinition.getLegend(); Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0)); subtitle.setMargin(0, 0, 5, 0); chart.addSubtitle(subtitle); // impostiamo la legenda LegendTitle legend = chart.getLegend(); legend.setBorder(0, 0, 0, 0); legend.setItemFont(legendItemFont); int legendMargin = 10; legend.setMargin(0.0, legendMargin, legendMargin, legendMargin); legend.setBackgroundPaint(transparentColor); // impostiamo un gradiente orizzontale Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, height, Color.WHITE); chart.setBackgroundPaint(chartBgPaint); return chart; }