List of usage examples for org.jfree.chart.block LineBorder LineBorder
public LineBorder(Paint paint, Stroke stroke, RectangleInsets insets)
From source file:net.sf.jasperreports.chartthemes.provider.LineBorderProvider.java
@Override public BlockFrame getBlockFrame() { RectangleInsets borderInsets = insets == null ? new RectangleInsets(1.0, 1.0, 1.0, 1.0) : insets; Stroke borderStroke = lineStroke == null ? new BasicStroke(1.0f) : lineStroke; Paint borderPaint = paint == null ? null : paint.getPaint(); if (borderPaint == null) { borderPaint = Color.BLACK; }/* w w w .j a v a2s . c o m*/ return new LineBorder(borderPaint, borderStroke, borderInsets); }
From source file:com.mgmtp.perfload.perfalyzer.reportpreparation.PlotCreator.java
public JFreeChart createPlot(final AxisType xAxisType, final AxisType yAxisType, final RendererType rendererType, final DisplayData displayData, final DataRange dataRange, boolean showMarkers, final NumberDataSet... dataSets) { NumberAxis xAxis = createAxis(xAxisType, resourceBundle.getString(displayData.getUnitX())); XYPlot plot;/*from w w w. j av a 2s .c om*/ if (dataSets.length == 1) { NumberAxis yAxis = createAxis(yAxisType, resourceBundle.getString(displayData.getUnitY())); plot = new XYPlot(dataSets[0], xAxis, yAxis, rendererType.createRenderer()); } else { CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(xAxis); for (int i = 0; i < dataSets.length; ++i) { NumberDataSet dataSet = dataSets[i]; // no range for y-axis! NumberAxis yAxis = createAxis(yAxisType, resourceBundle.getString(displayData.getUnitYList().get(i))); XYPlot subPlot = new XYPlot(dataSet, null, yAxis, rendererType.createRenderer()); combinedPlot.add(subPlot); formatPlot(subPlot); } plot = combinedPlot; } JFreeChart chart = new JFreeChart(plot); CHART_THEME.apply(chart); formatPlot(plot); if (showMarkers) { for (Marker marker : markers) { IntervalMarker im = new IntervalMarker(marker.getLeftMillis() / 1000L, marker.getRightMillis() / 1000L); im.setLabel(marker.getName()); im.setLabelFont(new Font("Sans Serif", Font.ITALIC | Font.BOLD, 14)); im.setLabelAnchor(RectangleAnchor.TOP); im.setLabelOffset(new RectangleInsets(8d, 0d, 0d, 0d)); im.setLabelPaint(Color.BLACK); im.setAlpha(.2f); im.setPaint(Color.WHITE); im.setOutlinePaint(Color.BLACK); im.setOutlineStroke(new BasicStroke(1.0f)); plot.addDomainMarker(im, Layer.BACKGROUND); } } LegendTitle legend = chart.getLegend(); legend.setBackgroundPaint(new Color(229, 229, 229)); legend.setFrame( new LineBorder(new Color(213, 213, 213), new BasicStroke(1.0f), legend.getFrame().getInsets())); // only for non-logarithmic axes // range must be set after plot is created, otherwise nothing is drawn if (dataRange != null && !xAxisType.equals(AxisType.LOGARITHMIC)) { xAxis.setRange(dataRange.getLowerSeconds(), dataRange.getUpperSeconds()); } return chart; }
From source file:SciTK.PlotXYZBlock.java
private void init(String x_label, String y_label, String window_title) { chart = ChartFactory.createScatterPlot("", x_label, y_label, data, PlotOrientation.VERTICAL, false, true, false);/*from w w w . j av a 2 s . co m*/ // turn off borders of the plot: XYPlot p = chart.getXYPlot(); p.getDomainAxis().setLowerMargin(0.0); p.getDomainAxis().setUpperMargin(0.0); p.getRangeAxis().setLowerMargin(0.0); p.getRangeAxis().setUpperMargin(0.0); // -------------------------------------------- // set up a lookup table // -------------------------------------------- // this is how we render the block plots: XYBlockRenderer renderer = new XYBlockRenderer(); // need to find max and min z of the data set: double min = 0; double max = 0; for (int i = 0; i < data.getSeriesCount(); i++) // iterate over data sets { for (int j = 0; j < data.getItemCount(i); j++) // iterate over points in dataset { if (data.getZValue(i, j) < min) min = data.getZValue(i, j); else if (data.getZValue(i, j) > max) max = data.getZValue(i, j); } } // create paint scale using min and max values, default color black: LookupPaintScale paintScale = new LookupPaintScale(min, max, Color.black); // set up the LUT: double step_size = (max - min) / 255.; // step size for LUT for (int i = 0; i < 256; i++) { paintScale.add(min + i * step_size, new Color(i, i, i, 255)); } renderer.setPaintScale(paintScale); // set this renderer to the plot: p.setRenderer(renderer); // -------------------------------------------- // set up a color bar // -------------------------------------------- // create an array of display labels: num_labels = 10; // default to 10 labels on color bar double display_step_size = (max - min) / ((double) num_labels); String[] scale_bar_labels = new String[num_labels + 1]; // to format numbers in scientific notation: DecimalFormat formater = new DecimalFormat("0.#E0"); // create list of labesl: for (int i = 0; i <= num_labels; i++) { scale_bar_labels[i] = formater.format(min + i * display_step_size); } // create axis: SymbolAxis scaleAxis = new SymbolAxis(null, scale_bar_labels); scaleAxis.setRange(min, max); scaleAxis.setPlot(new PiePlot()); scaleAxis.setGridBandsVisible(false); // set up the paint scale: psl = new PaintScaleLegend(paintScale, scaleAxis); psl.setBackgroundPaint(new Color(255, 255, 255, 0)); // clear background // set up frame with buffer region to allow text display psl.setFrame(new LineBorder((Paint) Color.BLACK, new BasicStroke((float) 1.0), new RectangleInsets(15, 10, 15, 10))); psl.setAxisOffset(5.0); // display on right side: psl.setPosition(RectangleEdge.RIGHT); // margin around color scale: psl.setMargin(new RectangleInsets(20, 15, 20, 15)); // add to the chart so it will be displayed by default: chart.addSubtitle(psl); // -------------------------------------------- // WINDOW-RELATED UI // -------------------------------------------- // set up the generic plot UI: super.window_title = window_title; super.initUI(); // add another menu item JMenuBar mb = super.getJMenuBar(); // get the menu bar // find menu named "Plot" JMenu menu_plot = null; for (int i = 0; i < mb.getMenuCount(); i++) { if (mb.getMenu(i).getText() == "Plot") menu_plot = mb.getMenu(i); } // Add a new checkbox for the color scale bar JCheckBoxMenuItem menu_plot_scalebar = new JCheckBoxMenuItem("Color Scale"); menu_plot_scalebar.setToolTipText("Show color scale bar?"); menu_plot_scalebar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); boolean selected = aButton.getModel().isSelected(); setScaleBar(selected); } }); // set appropirate checkbox state: menu_plot_scalebar.setState(true); if (menu_plot != null) // sanity check menu_plot.add(menu_plot_scalebar); }
From source file:org.operamasks.faces.render.graph.ChartRenderer.java
private LegendTitle createLegend(JFreeChart chart, UILegend legendcomp) { LegendTitle legend = new LegendTitle(chart.getPlot()); PositionType position = legendcomp.getPosition(); if (position == null) { legend.setPosition(RectangleEdge.BOTTOM); } else {//from w ww . ja va 2 s . com setTitlePosition(legend, position); } Double tm = legendcomp.getTopMargin(); Double lm = legendcomp.getLeftMargin(); Double bm = legendcomp.getBottomMargin(); Double rm = legendcomp.getRightMargin(); if (tm == null) tm = 1.0; if (lm == null) lm = 1.0; if (bm == null) bm = 1.0; if (rm == null) rm = 1.0; legend.setMargin(new RectangleInsets(tm, lm, bm, rm)); Paint bgcolor = legendcomp.getBackgroundColor(); if (bgcolor != null) { legend.setBackgroundPaint(bgcolor); } Float borderWidth = legendcomp.getBorderWidth(); Paint borderColor = legendcomp.getBorderColor(); if (borderWidth != null || borderColor != null) { if (borderWidth == null) borderWidth = 1.0f; if (borderColor == null) borderColor = Color.black; LineBorder border = new LineBorder(borderColor, new BasicStroke(borderWidth), new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setFrame(border); } Font itemFont = legendcomp.getItemFont(); Paint itemColor = legendcomp.getItemColor(); if (itemFont != null) legend.setItemFont(itemFont); if (itemColor != null) legend.setItemPaint(itemColor); return legend; }