List of usage examples for java.awt BasicStroke BasicStroke
public BasicStroke(float width, int cap, int join, float miterlimit)
From source file:com.orsonpdf.demo.PDFPieChartDemo1.java
/** * Creates a chart.// w w w. j a va2 s. c o m * * @param dataset the dataset. * * @return A chart. */ private static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", dataset, false, false, false); chart.setBackgroundPaint( new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY)); // customise the title position and font TextTitle t = chart.getTitle(); t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setPaint(new Color(240, 240, 240)); t.setFont(new Font("Arial", Font.BOLD, 26)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.04); plot.setOutlineVisible(false); plot.setShadowPaint(null); plot.setLabelShadowPaint(null); // use gradients and white borders for the section colours plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE)); plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED)); plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN)); plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW)); plot.setBaseSectionOutlinePaint(Color.WHITE); plot.setSectionOutlinesVisible(true); BasicStroke bs = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 1.0f); plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 20)); plot.setLabelLinkPaint(Color.WHITE); plot.setLabelLinkStroke(new BasicStroke(2.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.WHITE); plot.setLabelBackgroundPaint(null); // add a subtitle giving the data source TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", new Font("Courier New", Font.PLAIN, 12)); source.setPaint(Color.WHITE); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); return chart; }
From source file:fr.ign.cogit.simplu3d.rjmcmc.generic.visitor.StatsVisitor.java
/** * Creates a sample chart.// w ww . jav a 2 s . c om * * @param dataset * the dataset. * @return A sample chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart result = ChartFactory.createXYLineChart("volution de l'nergie", "Itration", "nergie", dataset, PlotOrientation.VERTICAL, true, true, true); result.setBorderPaint(Color.white); result.setBackgroundPaint(Color.white); final XYPlot plot = result.getXYPlot(); Font font = new Font("Verdana", Font.PLAIN, 32); Font font2 = new Font("Verdana", Font.PLAIN, 28); // axe x ValueAxis axis = plot.getDomainAxis(); axis.setLabelFont(font); axis.setTickLabelFont(font2); axis.setAutoRange(true); // axis.setFixedAutoRange(60000.0); // 60 seconds axis = plot.getRangeAxis(); // axe y ValueAxis axis2 = plot.getRangeAxis(); axis2.setLabelFont(font); axis2.setTickLabelFont(font2); axis2.setAutoRange(true); // axis.setFixedAutoRange(60000.0); // 60 seconds axis2 = plot.getRangeAxis(); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setBackgroundPaint(Color.white); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, new Color(255, 0, 0)); renderer.setSeriesStroke(0, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f)); renderer.setLegendTextFont(0, font2); renderer.setSeriesPaint(1, new Color(2, 157, 116)); renderer.setSeriesStroke(1, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f)); renderer.setLegendTextFont(1, font2); renderer.setSeriesPaint(2, new Color(112, 147, 219)); renderer.setSeriesStroke(2, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f)); renderer.setLegendTextFont(2, font2); renderer.setSeriesPaint(3, new Color(140, 23, 23)); renderer.setSeriesStroke(3, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 6.0f }, 0.0f)); renderer.setLegendTextFont(3, font2); // axis.setRange(0.0, 200.0); return result; }
From source file:peakml.util.jfreechart.FastErrorBarPlot.java
@Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {/*w w w . j ava 2s. c o m*/ // add the plot area to the info (used amongst other by the axis for zooming) if (info != null) info.setPlotArea(area); // add the insets (if any) RectangleInsets insets = getInsets(); insets.trim(area); // draw the axis and add the dataArea to the info (used amongst other by the axis for zooming) AxisSpace space = new AxisSpace(); space = xaxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space); space = yaxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space); Rectangle2D dataArea = space.shrink(area, null); if (info != null) info.setDataArea(dataArea); // flood fill the whole area with the background color drawBackground(g2, dataArea); // draw the axis xaxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info); yaxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info); // sanity check if (dataseries.size() == 0) return; // clip the draw area Shape originalclip = g2.getClip(); g2.clip(dataArea); // create the strokes BasicStroke stroke_solid = new BasicStroke(1.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.f); BasicStroke stroke_dashed = new BasicStroke(1.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.f, new float[] { 2, 4 }, 0); g2.setStroke(stroke_solid); // count the number of labels int categoryCount = 0; if (showall) { for (Data data : dataseries) categoryCount += data.yvalues.length; } else categoryCount = dataseries.size(); // draw all the values int pos = 0; boolean dashed = false; double prevx = -1, prevy = -1; for (Data data : dataseries) { if (data.yvalues.length == 0) { dashed = true; pos++; continue; } double mean[] = showall ? data.yvalues : new double[] { data.getMeanY() }; double min[] = showall ? data.yvalues : new double[] { data.getMinY() }; double max[] = showall ? data.yvalues : new double[] { data.getMaxY() }; for (int i = 0; i < mean.length; ++i) { double ypos, xpos = xaxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, pos++, categoryCount, dataArea, RectangleEdge.BOTTOM); // draw the mean value g2.setColor(Color.RED); ypos = yaxis.valueToJava2D(mean[i], dataArea, RectangleEdge.LEFT); g2.drawLine((int) xpos - 2, (int) ypos, (int) xpos + 2, (int) ypos); // conect the dots if (prevx != -1 && prevy != -1) { g2.setColor(Color.BLACK); if (dashed) g2.setStroke(stroke_dashed); g2.drawLine((int) prevx, (int) prevy, (int) xpos, (int) ypos); if (dashed) { dashed = false; g2.setStroke(stroke_solid); } } prevy = ypos; prevx = xpos; // draw the outer values g2.setColor(Color.LIGHT_GRAY); double ypos_min = yaxis.valueToJava2D(min[i], dataArea, RectangleEdge.LEFT); g2.drawLine((int) xpos - 2, (int) ypos_min, (int) xpos + 2, (int) ypos_min); double ypos_max = yaxis.valueToJava2D(max[i], dataArea, RectangleEdge.LEFT); g2.drawLine((int) xpos - 2, (int) ypos_max, (int) xpos + 2, (int) ypos_max); g2.drawLine((int) xpos, (int) ypos_min, (int) xpos, (int) ypos_max); } } // reset g2.setClip(originalclip); }