List of usage examples for org.jfree.chart.title PaintScaleLegend setMargin
public void setMargin(RectangleInsets margin)
From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.SimpleBlockChart.java
/** * Creates a chart for the specified dataset. * // w ww . j a v a2 s.c o m * @param dataset the dataset. * * @return A chart instance. */ public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1"); JFreeChart chart = null; NumberAxis xAxis = new NumberAxis(xLabel); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (xLowerBound != null && xUpperBound != null) { xAxis.setLowerBound(xLowerBound); xAxis.setUpperBound(xUpperBound); } else { xAxis.setAutoRange(true); } xAxis.setAxisLinePaint(Color.white); xAxis.setTickMarkPaint(Color.white); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { xAxis.setLabelFont(addLabelsStyle.getFont()); xAxis.setLabelPaint(addLabelsStyle.getColor()); } NumberAxis yAxis = new NumberAxis(yLabel); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (yLowerBound != null && yUpperBound != null) { yAxis.setLowerBound(yLowerBound); yAxis.setUpperBound(yUpperBound); } else yAxis.setAutoRange(true); yAxis.setAxisLinePaint(Color.white); yAxis.setTickMarkPaint(Color.white); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { yAxis.setLabelFont(addLabelsStyle.getFont()); yAxis.setLabelPaint(addLabelsStyle.getColor()); } XYBlockRenderer renderer = new XYBlockRenderer(); PaintScale paintScale = null; if (grayPaintScale) { paintScale = new GrayPaintScale(minScaleValue, maxScaleValue); } else { if (scaleLowerBound != null && scaleUpperBound != null) { paintScale = new LookupPaintScale(scaleLowerBound, scaleUpperBound, Color.gray); } else { paintScale = new LookupPaintScale(minScaleValue, maxScaleValue, Color.gray); } for (int i = 0; i < zRangeArray.length; i++) { ZRange zRange = zRangeArray[i]; ((LookupPaintScale) paintScale).add(zRange.getValue().doubleValue(), zRange.getColor()); } } renderer.setPaintScale(paintScale); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); plot.setForegroundAlpha(0.66f); chart = new JFreeChart(plot); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } chart.removeLegend(); NumberAxis scaleAxis = new NumberAxis(zLabel); scaleAxis.setAxisLinePaint(Color.white); scaleAxis.setTickMarkPaint(Color.white); scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7)); if (scaleLowerBound != null && scaleUpperBound != null) { scaleAxis.setLowerBound(scaleLowerBound); scaleAxis.setUpperBound(scaleUpperBound); } else scaleAxis.setAutoRange(true); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { scaleAxis.setLabelFont(addLabelsStyle.getFont()); scaleAxis.setLabelPaint(addLabelsStyle.getColor()); } if (blockHeight != null && blockWidth != null) { renderer.setBlockWidth(blockWidth.doubleValue()); renderer.setBlockHeight(blockHeight.doubleValue()); } PaintScaleLegend legend = new PaintScaleLegend(paintScale, scaleAxis); legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT); legend.setAxisOffset(5.0); legend.setMargin(new RectangleInsets(5, 5, 5, 5)); legend.setFrame(new BlockBorder(Color.black)); legend.setPadding(new RectangleInsets(10, 10, 10, 10)); legend.setStripWidth(10); legend.setPosition(RectangleEdge.RIGHT); legend.setBackgroundPaint(color); chart.addSubtitle(legend); // chart.setBackgroundPaint(new Color(180, 180, 250)); chart.setBackgroundPaint(color); logger.debug("OUT"); return chart; }
From source file:org.gumtree.vis.hist2d.Hist2D.java
private PaintScaleLegend createScaleLegend(PaintScale scale) { PaintScaleLegend legend = new PaintScaleLegend(scale, scaleAxis); legend.setSubdivisionCount(20);/*from w ww. j a v a 2 s.com*/ legend.setStripOutlineVisible(false); legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT); legend.setAxisOffset(5); RectangleInsets rec = new RectangleInsets(5, 0, 10, 5); legend.setMargin(rec); RectangleInsets rec2 = new RectangleInsets(4, 0, 22, 2); legend.setPadding(rec2); legend.setStripWidth(10); legend.setPosition(RectangleEdge.RIGHT); return legend; }
From source file:org.glotaran.core.datadisplayers.multispec.MultiSpecEditorTopComponent.java
private void MakeImageChart(ColorCodedImageDataset dataset) { double range = Math.abs(data.getMaxInt() - data.getMinInt()); double dataMin, dataMax; if (range == 0.0) { dataMin = data.getMinInt() - 0.1; dataMax = data.getMaxInt() + 0.1; } else {/*from w w w .java2 s.c o m*/ dataMin = data.getMinInt(); dataMax = data.getMaxInt(); } PaintScale ps = new RainbowPaintScale(dataMin, dataMax); this.chartMultiSpec = createChart(new XYSeriesCollection()); this.chartMultiSpec.setBackgroundPaint(JFreeChart.DEFAULT_BACKGROUND_PAINT); XYPlot tempPlot = (XYPlot) this.chartMultiSpec.getPlot(); this.wholeXRange = tempPlot.getDomainAxis().getRange(); this.wholeYRange = tempPlot.getRangeAxis().getRange(); //added axes labeles on the image // DecimalFormat formatter = new DecimalFormat("##0E0"); // NumberAxis xAxis = new NumberAxis("Wavelength "); // // // double[] x2values = data.getIntenceImY(); // double x2range = Math.abs(x2values[0] - x2values[x2values.length - 1]); // if (x2range<=0) { // for (int i = 0; i < x2values.length; i++) { // x2values[i]=i; // } // } // // int numberOfTicks = Math.min(data.getIntenceImY().length,MAX_NO_TICKS); // NonLinearNumberTickUnit xTickUnit = new NonLinearNumberTickUnit(x2values.length/numberOfTicks, formatter,x2values); // xAxis.setTickUnit(xTickUnit); // xAxis.setTickLabelsVisible(true); // tempPlot.setDomainAxis(xAxis); // // NumberAxis yAxis = new NumberAxis("? Wavelength"); // // formatter = new DecimalFormat("##0.#E0"); // numberOfTicks = Math.min(data.getX3().length,MAX_NO_TICKS); // NonLinearNumberTickUnit yTickUnit = new NonLinearNumberTickUnit(data.getX3().length/numberOfTicks, formatter,data.getX3(),false); // yAxis.setTickUnit(yTickUnit); // yAxis.setTickLabelsVisible(true); // tempPlot.setRangeAxis(yAxis); chartPanelMultiSpec = new HeightMapPanel(chartMultiSpec, true); chartPanelMultiSpec.setFillZoomRectangle(true); chartPanelMultiSpec.setMouseWheelEnabled(true); chartPanelMultiSpec.setZoomFillPaint(new Color(68, 68, 78, 63)); jpMultiSpecImage.removeAll(); // chpanImage.setSize(jPSpecImage.getMaximumSize()); jpMultiSpecImage.setLayout(new BorderLayout()); ImageCrosshairLabelGenerator crossLabGenVerticalCut = new ImageCrosshairLabelGenerator(data.getIntenceImY(), false); ImageCrosshairLabelGenerator crossLabGenHorisontalCut = new ImageCrosshairLabelGenerator( data.getIntenceImX(), false); ImageCrosshairLabelGenerator crossLabGenTimeSlise = new ImageCrosshairLabelGenerator(data.getX(), false); crhVerticalCut = createCroshair(Color.red, crossLabGenVerticalCut); crhHorisontalCut = createCroshair(Color.gray, crossLabGenHorisontalCut); crhTimeSlice = createCroshair(Color.red, null); CrosshairOverlay overlay = new CrosshairOverlay(); overlay.addDomainCrosshair(crhVerticalCut); overlay.addRangeCrosshair(crhHorisontalCut); chartPanelMultiSpec.addOverlay(overlay); jpMultiSpecImage.add(chartPanelMultiSpec); //TODO: auto scale the JSlider jSColum to the size of the chart //chpanImage.getChartRenderingInfo().getChartArea().getWidth(); //jSColum.setBounds(jSColum.getBounds().x, jSColum.getBounds().y,(int)chpanImage.getChartRenderingInfo().getChartArea().getBounds().width,jSColum.getHeight()); chartMultiSpec.addChangeListener((ChartChangeListener) this); subchartVerticalCutTrace = createXYPlot(PlotOrientation.HORIZONTAL, AxisLocation.BOTTOM_OR_RIGHT, data.getIntenceImX(), jpVerticalCut, false, null); subchartHorisontalTrace = createXYPlot(PlotOrientation.VERTICAL, AxisLocation.BOTTOM_OR_RIGHT, data.getIntenceImY(), jpHorisontalCut, false, null); CrosshairOverlay overlayTime = new CrosshairOverlay(); overlayTime.addDomainCrosshair(crhTimeSlice); subchartTimeTrace = createXYPlot(PlotOrientation.VERTICAL, AxisLocation.BOTTOM_OR_LEFT, data.getX(), jpTimeeTrace, false, overlayTime); NumberAxis scaleAxis = new NumberAxis(); scaleAxis.setAxisLinePaint(Color.black); scaleAxis.setTickMarkPaint(Color.black); scaleAxis.setRange(data.getMinInt(), data.getMaxInt()); scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 12)); PaintScaleLegend legend = new PaintScaleLegend(ps, scaleAxis); legend.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); legend.setMargin(new RectangleInsets(5, 5, 5, 5)); legend.setStripWidth(15); legend.setPosition(RectangleEdge.RIGHT); legend.setBackgroundPaint(chartMultiSpec.getBackgroundPaint()); chartMultiSpec.addSubtitle(legend); this.chartMultiSpec.addChangeListener((ChartChangeListener) this); jSVerticalCut.setValueIsAdjusting(true); jSVerticalCut.setMaximum(dataset.GetImageWidth() - 1); jSVerticalCut.setMinimum(0); // jSVerticalCut.setValue(0); jSVerticalCut.setValueIsAdjusting(false); jsHorisontalCut.setValueIsAdjusting(true); jsHorisontalCut.setMaximum(dataset.GetImageHeigth() - 1); jsHorisontalCut.setMinimum(0); jsHorisontalCut.setValueIsAdjusting(false); jsTimeSlice.setValueIsAdjusting(true); jsTimeSlice.setMaximum(data.getNt() - 1); jsTimeSlice.setMinimum(0); jsTimeSlice.setValueIsAdjusting(false); }