List of usage examples for java.awt.geom GeneralPath closePath
public final synchronized void closePath()
From source file:org.operamasks.faces.render.graph.XYCurveAndShapeRenderer.java
/** * Draws the item (first pass). This method draws the lines * connecting the items. Instead of drawing separate lines, * a GeneralPath is constructed and drawn at the end of * the series painting./*from w w w .ja v a 2s .c o m*/ * * @param g2 the graphics device. * @param state the renderer state. * @param plot the plot (can be used to obtain standard color information * etc). * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataArea the area within which the data is being drawn. */ protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { if (item != 0) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); PlotOrientation orientation = plot.getOrientation(); int itemCount = dataset.getItemCount(series); double[][] points = new double[itemCount][2]; int count = 0; for (int i = 0; i < itemCount; i++) { double x = dataset.getXValue(series, i); double y = dataset.getYValue(series, i); double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); if (!Double.isNaN(transX) && !Double.isNaN(transY)) { points[count][0] = transX; points[count][1] = transY; count++; } } if (count < 2) { return; } // sort points according to x axis Arrays.sort(points, new Comparator<double[]>() { public int compare(double[] a, double[] b) { return a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0; } }); // draw curve CubicSplineFunction2D f = new CubicSplineFunction2D(points, count); GeneralPath path = new GeneralPath(); double startX = points[0][0]; double startY = points[0][1]; double endX = points[count - 1][0]; double endY = points[count - 1][1]; double yz = rangeAxis.valueToJava2D(0.0, dataArea, yAxisLocation); if (orientation == PlotOrientation.HORIZONTAL) { if (drawArea) { path.moveTo((float) yz, (float) startX); path.lineTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); path.lineTo((float) yz, (float) endX); path.closePath(); } else { path.moveTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); } } else { if (drawArea) { path.moveTo((float) startX, (float) yz); path.lineTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); path.lineTo((float) endX, (float) yz); path.closePath(); } else { path.moveTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); } } Paint paint = getItemPaint(series, item); Stroke stroke = getItemStroke(series, item); if (drawArea) { g2.setPaint(paint); g2.fill(path); // create paint for outline if (paint instanceof Color) { paint = ((Color) paint).darker(); } else if (paint instanceof GradientPaint) { paint = ((GradientPaint) paint).getColor1().darker(); } } g2.setPaint(paint); g2.setStroke(stroke); g2.draw(path); }
From source file:org.openmeetings.app.data.record.BatikMethods.java
public void drawArrow(SVGGraphics2D g2d, GeomPoint start, GeomPoint end, float thickness, float alpha, Color linecoler, Color fillColor) { if (start.equals(end)) return;// w w w . jav a 2 s. c om // (double edgeControlPosition, double edgeControlSize, // double headLength, double headWidth, double shaftControlPosition, // double shaftControlSize, float shaftPosition, double shaftThickness) ArrowStyle arrowStyle = new ArrowStyle(0.5, 0.5, thickness * 5, thickness * 5, 0.5, 0.5, 0, thickness); GeomPoint fullVect = end.subtract(start); double halfWidth = (arrowStyle.headWidth != -1) ? arrowStyle.headWidth / 2 : arrowStyle.headLength / 2; //Figure out the line start/end points GeomPoint startNorm = new GeomPoint(); startNorm.setLocation(fullVect.getY(), -fullVect.getX()); startNorm.normalize(arrowStyle.shaftThickness / 2); GeomPoint start1 = start.add(startNorm); GeomPoint start2 = start.subtract(startNorm); GeomPoint end1 = end.add(startNorm); GeomPoint end2 = end.subtract(startNorm); //log.debug("startNorm: "+startNorm.toString()); //log.debug("start1: "+start1.toString()); //log.debug("start2: "+start2.toString()); //log.debug("end1: "+end1.toString()); //log.debug("end2: "+end2.toString()); //figure out where the arrow head starts GeomPoint headPnt = fullVect.clone(); //log.debug("headPnt 1: "+headPnt.toString()); //log.debug("headPnt.length 1: "+headPnt.length()); //log.debug("arrowStyle.headLength 1: "+arrowStyle.headLength); headPnt.normalize(headPnt.length() - arrowStyle.headLength); //log.debug("headPnt 2: "+headPnt.toString()); headPnt = headPnt.add(start); //log.debug("headPnt 3: "+headPnt.toString()); //calculate the arrowhead corners GeomPoint headPntNorm = startNorm.clone(); //log.debug("headPntNorm ^^: "+headPntNorm.toString()); //log.debug("halfWidth ^^: "+halfWidth); headPntNorm.normalize(halfWidth); //log.debug("headPntNorm: "+headPntNorm.toString()); GeomPoint edge1 = headPnt.add(headPntNorm); GeomPoint edge2 = headPnt.subtract(headPntNorm); //log.debug("edge1: "+edge1.toString()); //log.debug("edge2: "+edge2.toString()); //Figure out where the arrow connects the the shaft, then calc the intersections GeomPoint shaftCenter = GeomPoint.interpolate(end, headPnt, arrowStyle.shaftPosition); //log.debug("end"+end.toString()); //log.debug("headPnt: "+headPnt.toString()); //log.debug("arrowStyle.shaftPosition: "+arrowStyle.shaftPosition); //log.debug("shaftCenter: "+shaftCenter); //log.debug("edge1: "+edge1); //shaftCenter.setLocation(185.857864376269, 185.857864376269); GeomPoint inter1 = GeomPoint.getLineIntersection(start1, end1, shaftCenter, edge1); GeomPoint inter2 = GeomPoint.getLineIntersection(start2, end2, shaftCenter, edge2); //log.debug("inter1: "+inter1.toString()); //log.debug("inter2: "+inter2.toString()); //Figure out the control points GeomPoint edgeCenter = GeomPoint.interpolate(end, headPnt, (float) arrowStyle.edgeControlPosition); GeomPoint edgeNorm = startNorm.clone(); edgeNorm.normalize(halfWidth * arrowStyle.edgeControlSize); //log.debug("halfWidth*arrowStyle.edgeControlSize: "+(halfWidth*arrowStyle.edgeControlSize)); //log.debug("edgeNorm: "+edgeNorm.toString()); GeomPoint edgeCntrl1 = edgeCenter.add(edgeNorm); GeomPoint edgeCntrl2 = edgeCenter.subtract(edgeNorm); //log.debug("edgeCntrl1: "+edgeCntrl1.toString()); //log.debug("edgeCntrl2: "+edgeCntrl2.toString()); g2d.setPaint(new Color(255, 0, 0)); // graphics.moveTo(start1.x,start1.y); // graphics.lineTo(inter1.x,inter1.y); // graphics.lineTo(edge1.x,edge1.y); // graphics.curveTo(edgeCntrl1.x,edgeCntrl1.y,end.x,end.y); // graphics.curveTo(edgeCntrl2.x,edgeCntrl2.y,edge2.x,edge2.y); // graphics.lineTo(inter2.x,inter2.y); // graphics.lineTo(start2.x,start2.y); // graphics.lineTo(start1.x,start1.y); // log.debug("moveTo"+start1.x+","+start1.y); // log.debug("lineTo"+inter1.x+","+inter1.y); // log.debug("lineTo"+edge1.x+","+edge1.y); // log.debug("quadTo"+edgeCntrl1.x+","+edgeCntrl1.y+","+end.x+","+end.y); // log.debug("quadTo"+edgeCntrl2.x+","+edgeCntrl2.y+","+edge2.x+","+edge2.y); // log.debug("lineTo"+inter2.x+","+inter2.y); // log.debug("lineTo"+start2.x+","+start2.y); // log.debug("lineTo"+start1.x+","+start1.y); GeneralPath graphics = new GeneralPath(); graphics.moveTo(start1.x, start1.y); graphics.lineTo(inter1.x, inter1.y); graphics.lineTo(edge1.x, edge1.y); graphics.quadTo(edgeCntrl1.x, edgeCntrl1.y, end.x, end.y); graphics.quadTo(edgeCntrl2.x, edgeCntrl2.y, edge2.x, edge2.y); graphics.lineTo(inter2.x, inter2.y); graphics.lineTo(start2.x, start2.y); graphics.lineTo(start1.x, start1.y); graphics.closePath(); int[] rules = new int[8]; //all possible Compositing Rules: rules[0] = AlphaComposite.SRC_OVER; rules[1] = AlphaComposite.DST_OVER; rules[2] = AlphaComposite.CLEAR; rules[3] = AlphaComposite.SRC; rules[4] = AlphaComposite.SRC_IN; rules[5] = AlphaComposite.DST_IN; rules[6] = AlphaComposite.SRC_OUT; rules[7] = AlphaComposite.DST_OUT; g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha)); g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); if (linecoler != null) { g2d.setPaint(linecoler); g2d.draw(graphics); } if (fillColor != null) { g2d.setPaint(fillColor); g2d.fill(graphics); } }
From source file:org.jfree.chart.demo.CylinderRenderer.java
public void drawItem(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate, Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis, CategoryDataset categorydataset, int i, int j, int k) { Number number = categorydataset.getValue(i, j); if (number == null) return;//from w ww .ja va2s.com double d = number.doubleValue(); java.awt.geom.Rectangle2D.Double double1 = new java.awt.geom.Rectangle2D.Double(rectangle2d.getX(), rectangle2d.getY() + getYOffset(), rectangle2d.getWidth() - getXOffset(), rectangle2d.getHeight() - getYOffset()); PlotOrientation plotorientation = categoryplot.getOrientation(); double d1 = calculateBarW0(categoryplot, plotorientation, double1, categoryaxis, categoryitemrendererstate, i, j); double ad[] = calculateBarL0L1(d); if (ad == null) return; RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge(); float f = (float) valueaxis.valueToJava2D(ad[0], double1, rectangleedge); float f1 = (float) valueaxis.valueToJava2D(ad[1], double1, rectangleedge); float f2 = Math.min(f, f1); float f3 = Math.abs(f1 - f); GeneralPath generalpath = new GeneralPath(); java.awt.geom.Ellipse2D.Double double2 = null; if (plotorientation == PlotOrientation.HORIZONTAL) { generalpath.moveTo((float) ((double) f2 + getXOffset() / 2D), (float) d1); generalpath.lineTo((float) ((double) (f2 + f3) + getXOffset() / 2D), (float) d1); java.awt.geom.Arc2D.Double double3 = new java.awt.geom.Arc2D.Double(f2 + f3, d1, getXOffset(), categoryitemrendererstate.getBarWidth(), 90D, 180D, 0); generalpath.append(double3, true); generalpath.lineTo((float) ((double) f2 + getXOffset() / 2D), (float) (d1 + categoryitemrendererstate.getBarWidth())); double3 = new java.awt.geom.Arc2D.Double(f2, d1, getXOffset(), categoryitemrendererstate.getBarWidth(), 270D, -180D, 0); generalpath.append(double3, true); generalpath.closePath(); double2 = new java.awt.geom.Ellipse2D.Double(f2 + f3, d1, getXOffset(), categoryitemrendererstate.getBarWidth()); } else { generalpath.moveTo((float) d1, (float) ((double) f2 - getYOffset() / 2D)); generalpath.lineTo((float) d1, (float) ((double) (f2 + f3) - getYOffset() / 2D)); java.awt.geom.Arc2D.Double double4 = new java.awt.geom.Arc2D.Double(d1, (double) (f2 + f3) - getYOffset(), categoryitemrendererstate.getBarWidth(), getYOffset(), 180D, 180D, 0); generalpath.append(double4, true); generalpath.lineTo((float) (d1 + categoryitemrendererstate.getBarWidth()), (float) ((double) f2 - getYOffset() / 2D)); double4 = new java.awt.geom.Arc2D.Double(d1, (double) f2 - getYOffset(), categoryitemrendererstate.getBarWidth(), getYOffset(), 0.0D, -180D, 0); generalpath.append(double4, true); generalpath.closePath(); double2 = new java.awt.geom.Ellipse2D.Double(d1, (double) f2 - getYOffset(), categoryitemrendererstate.getBarWidth(), getYOffset()); } Object obj = getItemPaint(i, j); if (getGradientPaintTransformer() != null && (obj instanceof GradientPaint)) { GradientPaint gradientpaint = (GradientPaint) obj; obj = getGradientPaintTransformer().transform(gradientpaint, generalpath); } graphics2d.setPaint(((java.awt.Paint) (obj))); graphics2d.fill(generalpath); if (obj instanceof GradientPaint) { graphics2d.setPaint(((GradientPaint) obj).getColor2()); } if (double2 != null) { graphics2d.fill(double2); } if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) { graphics2d.setStroke(getItemOutlineStroke(i, j)); graphics2d.setPaint(getItemOutlinePaint(i, j)); graphics2d.draw(generalpath); if (double2 != null) graphics2d.draw(double2); } CategoryItemLabelGenerator categoryitemlabelgenerator = getItemLabelGenerator(i, j); if (categoryitemlabelgenerator != null && isItemLabelVisible(i, j)) drawItemLabel(graphics2d, categorydataset, i, j, categoryplot, categoryitemlabelgenerator, generalpath.getBounds2D(), d < 0.0D); if (categoryitemrendererstate.getInfo() != null) { EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection(); if (entitycollection != null) { String s = null; CategoryToolTipGenerator categorytooltipgenerator = getToolTipGenerator(i, j); if (categorytooltipgenerator != null) s = categorytooltipgenerator.generateToolTip(categorydataset, i, j); String s1 = null; if (getItemURLGenerator(i, j) != null) s1 = getItemURLGenerator(i, j).generateURL(categorydataset, i, j); CategoryItemEntity categoryitementity = new CategoryItemEntity(generalpath.getBounds2D(), s, s1, categorydataset, categorydataset.getRowKey(i), categorydataset.getColumnKey(j)); entitycollection.add(categoryitementity); } } }
From source file:de.tor.tribes.ui.views.DSWorkbenchDoItYourselfAttackPlaner.java
@Override public void resetView() { AttackManager.getSingleton().addManagerListener(this); //setup renderer and general view // ((DoItYourselfAttackTableModel) jAttackTable.getModel()).clear(); HighlightPredicate.ColumnHighlightPredicate colu = new HighlightPredicate.ColumnHighlightPredicate(0, 1, 2, 3, 6);//from w w w . j a va 2 s. c om jAttackTable.setRowHeight(24); jAttackTable.getTableHeader().setDefaultRenderer(new DefaultTableHeaderRenderer()); jAttackTable.setHighlighters(new CompoundHighlighter(colu, HighlighterFactory.createAlternateStriping(Constants.DS_ROW_A, Constants.DS_ROW_B))); jAttackTable.setColumnControlVisible(true); jAttackTable.setDefaultEditor(UnitHolder.class, new UnitCellEditor()); jAttackTable.setDefaultEditor(Village.class, new VillageCellEditor()); jAttackTable.setDefaultRenderer(UnitHolder.class, new UnitCellRenderer()); jAttackTable.setDefaultRenderer(Integer.class, new NoteIconCellRenderer(NoteIconCellRenderer.ICON_TYPE.NOTE)); jAttackTable.setDefaultRenderer(Date.class, new ColoredDateCellRenderer()); jAttackTable.setDefaultRenderer(Long.class, new ColoredCoutdownCellRenderer()); jAttackTable.setDefaultEditor(Date.class, new DateSpinEditor()); jAttackTable.setDefaultEditor(Integer.class, new NoteIconCellEditor(NoteIconCellEditor.ICON_TYPE.NOTE)); BufferedImage back = ImageUtils.createCompatibleBufferedImage(5, 5, BufferedImage.BITMASK); Graphics2D g = back.createGraphics(); GeneralPath p = new GeneralPath(); p.moveTo(0, 0); p.lineTo(5, 0); p.lineTo(5, 5); p.closePath(); g.setColor(Color.GREEN.darker()); g.fill(p); g.dispose(); jAttackTable.addHighlighter(new PainterHighlighter(HighlightPredicate.EDITABLE, new ImagePainter(back, HorizontalAlignment.RIGHT, VerticalAlignment.TOP))); DefaultComboBoxModel model = new DefaultComboBoxModel(); DefaultComboBoxModel model2 = new DefaultComboBoxModel(); for (UnitHolder unit : DataHolder.getSingleton().getUnits()) { model.addElement(unit); model2.addElement(unit); } jUnitBox.setModel(model); jUnitComboBox.setModel(model2); jUnitBox.setSelectedItem(DataHolder.getSingleton().getUnitByPlainName("ram")); jUnitComboBox.setSelectedItem(DataHolder.getSingleton().getUnitByPlainName("ram")); jUnitBox.setRenderer(new UnitListCellRenderer()); jAttackTypeComboBox.setRenderer(new StandardAttackListCellRenderer()); DefaultComboBoxModel typeModel = new DefaultComboBoxModel(); for (ManageableType t : StandardAttackManager.getSingleton().getAllElements()) { StandardAttack a = (StandardAttack) t; typeModel.addElement(a); } jAttackTypeComboBox.setModel(typeModel); jUnitComboBox.setRenderer(new UnitListCellRenderer()); jSourceVillage.setValue(new Point(500, 500)); jTargetVillage.setValue(new Point(500, 500)); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jSourceVillage.updateUI(); jTargetVillage.updateUI(); } }); }
From source file:CustomStrokes.java
public Shape createStrokedShape(Shape shape) { GeneralPath newshape = new GeneralPath(); // Start with an empty shape // Iterate through the specified shape, perturb its coordinates, and // use them to build up the new shape. float[] coords = new float[6]; for (PathIterator i = shape.getPathIterator(null); !i.isDone(); i.next()) { int type = i.currentSegment(coords); switch (type) { case PathIterator.SEG_MOVETO: perturb(coords, 2);/* w w w . ja v a 2s. c o m*/ newshape.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_LINETO: perturb(coords, 2); newshape.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_QUADTO: perturb(coords, 4); newshape.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case PathIterator.SEG_CUBICTO: perturb(coords, 6); newshape.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case PathIterator.SEG_CLOSE: newshape.closePath(); break; } } // Finally, stroke the perturbed shape and return the result return stroke.createStrokedShape(newshape); }
From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.StackedAreaRenderer.java
/** * Draw a single data item.//from w w w .ja v a 2s . c o m * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the data plot area. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the data. * @param row the row index (zero-based). * @param column the column index (zero-based). * @param pass the pass index. */ public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final CategoryDataset dataset, final int row, final int column, final int pass) { if (!isSeriesVisible(row)) { return; } if ((pass == 1) && !isItemLabelVisible(row, column)) { return; } // setup for collecting optional entity info... Shape entityArea = null; final EntityCollection entities = state.getEntityCollection(); double y1 = 0.0; Number n = dataset.getValue(row, column); if (n != null) { y1 = n.doubleValue(); if (this.renderAsPercentages) { final double total = DataUtilities.calculateColumnTotal(dataset, column); y1 = y1 / total; } } final double[] stack1 = getStackValues(dataset, row, column); // leave the y values (y1, y0) untranslated as it is going to be be // stacked up later by previous series values, after this it will be // translated. double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); // get the previous point and the next point so we can calculate a // "hot spot" for the area (used by the chart entity)... double y0 = 0.0; n = dataset.getValue(row, Math.max(column - 1, 0)); if (n != null) { y0 = n.doubleValue(); if (this.renderAsPercentages) { final double total = DataUtilities.calculateColumnTotal(dataset, Math.max(column - 1, 0)); y0 = y0 / total; } } final double[] stack0 = getStackValues(dataset, row, Math.max(column - 1, 0)); // FIXME: calculate xx0 double xx0 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); final int itemCount = dataset.getColumnCount(); double y2 = 0.0; n = dataset.getValue(row, Math.min(column + 1, itemCount - 1)); if (n != null) { y2 = n.doubleValue(); if (this.renderAsPercentages) { final double total = DataUtilities.calculateColumnTotal(dataset, Math.min(column + 1, itemCount - 1)); y2 = y2 / total; } } final double[] stack2 = getStackValues(dataset, row, Math.min(column + 1, itemCount - 1)); double xx2 = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); // This gets rid of the white lines between most category values // Doug Moran - Hitachi Vantara xx0 = Math.round(xx0); xx1 = Math.round(xx1); xx2 = Math.round(xx2); // FIXME: calculate xxLeft and xxRight final double xxLeft = xx0; final double xxRight = xx2; final double[] stackLeft = averageStackValues(stack0, stack1); final double[] stackRight = averageStackValues(stack1, stack2); final double[] adjStackLeft = adjustedStackValues(stack0, stack1); final double[] adjStackRight = adjustedStackValues(stack1, stack2); final float transY1; final RectangleEdge edge1 = plot.getRangeAxisEdge(); final GeneralPath left = new GeneralPath(); final GeneralPath right = new GeneralPath(); if (y1 >= 0.0) { // handle positive value transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[1], dataArea, edge1); final float transStack1 = (float) rangeAxis.valueToJava2D(stack1[1], dataArea, edge1); final float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[1], dataArea, edge1); // LEFT POLYGON if (y0 >= 0.0) { final double yleft = (y0 + y1) / 2.0 + stackLeft[1]; final float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1); left.moveTo((float) xx1, transY1); left.lineTo((float) xx1, transStack1); left.lineTo((float) xxLeft, transStackLeft); left.lineTo((float) xxLeft, transYLeft); left.closePath(); } else { left.moveTo((float) xx1, transStack1); left.lineTo((float) xx1, transY1); left.lineTo((float) xxLeft, transStackLeft); left.closePath(); } final float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[1], dataArea, edge1); // RIGHT POLYGON if (y2 >= 0.0) { final double yright = (y1 + y2) / 2.0 + stackRight[1]; final float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1); right.moveTo((float) xx1, transStack1); right.lineTo((float) xx1, transY1); right.lineTo((float) xxRight, transYRight); right.lineTo((float) xxRight, transStackRight); right.closePath(); } else { right.moveTo((float) xx1, transStack1); right.lineTo((float) xx1, transY1); right.lineTo((float) xxRight, transStackRight); right.closePath(); } } else { // handle negative value transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[0], dataArea, edge1); final float transStack1 = (float) rangeAxis.valueToJava2D(stack1[0], dataArea, edge1); final float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[0], dataArea, edge1); // LEFT POLYGON if (y0 >= 0.0) { left.moveTo((float) xx1, transStack1); left.lineTo((float) xx1, transY1); left.lineTo((float) xxLeft, transStackLeft); left.clone(); } else { final double yleft = (y0 + y1) / 2.0 + stackLeft[0]; final float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1); left.moveTo((float) xx1, transY1); left.lineTo((float) xx1, transStack1); left.lineTo((float) xxLeft, transStackLeft); left.lineTo((float) xxLeft, transYLeft); left.closePath(); } final float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[0], dataArea, edge1); // RIGHT POLYGON if (y2 >= 0.0) { right.moveTo((float) xx1, transStack1); right.lineTo((float) xx1, transY1); right.lineTo((float) xxRight, transStackRight); right.closePath(); } else { final double yright = (y1 + y2) / 2.0 + stackRight[0]; final float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1); right.moveTo((float) xx1, transStack1); right.lineTo((float) xx1, transY1); right.lineTo((float) xxRight, transYRight); right.lineTo((float) xxRight, transStackRight); right.closePath(); } } if (pass == 0) { final Paint itemPaint = getItemPaint(row, column); g2.setPaint(itemPaint); g2.fill(left); g2.fill(right); // add an entity for the item... if (entities != null) { final GeneralPath gp = new GeneralPath(left); gp.append(right, false); entityArea = gp; addItemEntity(entities, dataset, row, column, entityArea); } } else if (pass == 1) { drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, transY1, y1 < 0.0); } }
From source file:de.saring.util.gui.jfreechart.StackedRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device.// w w w. j av a2 s. c om * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color information * etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState information about crosshairs on a plot. * @param pass the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } TableXYDataset tdataset = (TableXYDataset) dataset; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1)) { y1 = 0.0; } double[] stack1 = getStackValues(tdataset, series, item); // get the previous point and the next point so we can calculate a // "hot spot" for the area (used by the chart entity)... double x0 = dataset.getXValue(series, Math.max(item - 1, 0)); double y0 = dataset.getYValue(series, Math.max(item - 1, 0)); if (Double.isNaN(y0)) { y0 = 0.0; } double[] stack0 = getStackValues(tdataset, series, Math.max(item - 1, 0)); int itemCount = dataset.getItemCount(series); double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1)); double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1)); if (Double.isNaN(y2)) { y2 = 0.0; } double[] stack2 = getStackValues(tdataset, series, Math.min(item + 1, itemCount - 1)); double xleft = (x0 + x1) / 2.0; double xright = (x1 + x2) / 2.0; double[] stackLeft = averageStackValues(stack0, stack1); double[] stackRight = averageStackValues(stack1, stack2); double[] adjStackLeft = adjustedStackValues(stack0, stack1); double[] adjStackRight = adjustedStackValues(stack1, stack2); RectangleEdge edge0 = plot.getDomainAxisEdge(); float transX1 = (float) domainAxis.valueToJava2D(x1, dataArea, edge0); float transXLeft = (float) domainAxis.valueToJava2D(xleft, dataArea, edge0); float transXRight = (float) domainAxis.valueToJava2D(xright, dataArea, edge0); if (this.roundXCoordinates) { transX1 = Math.round(transX1); transXLeft = Math.round(transXLeft); transXRight = Math.round(transXRight); } float transY1; RectangleEdge edge1 = plot.getRangeAxisEdge(); GeneralPath left = new GeneralPath(); GeneralPath right = new GeneralPath(); if (y1 >= 0.0) { // handle positive value transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[1], dataArea, edge1); float transStack1 = (float) rangeAxis.valueToJava2D(stack1[1], dataArea, edge1); float transStackLeft = (float) rangeAxis.valueToJava2D(stackLeft[1], dataArea, edge1); // other than StackedXYAreaRenderer2! // LEFT POLYGON if (y0 >= 0.0) { double yleft = (y0 + y1) / 2.0 + stackLeft[1]; float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1); left.moveTo(transX1, transY1); left.lineTo(transX1, transStack1); left.lineTo(transXLeft, transStackLeft); left.lineTo(transXLeft, transYLeft); left.closePath(); } else { left.moveTo(transX1, transStack1); left.lineTo(transX1, transY1); left.lineTo(transXLeft, transStackLeft); left.closePath(); } float transStackRight = (float) rangeAxis.valueToJava2D(stackRight[1], dataArea, edge1); // other than StackedXYAreaRenderer2! // RIGHT POLYGON if (y2 >= 0.0) { double yright = (y1 + y2) / 2.0 + stackRight[1]; float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1); right.moveTo(transX1, transStack1); right.lineTo(transX1, transY1); right.lineTo(transXRight, transYRight); right.lineTo(transXRight, transStackRight); right.closePath(); } else { right.moveTo(transX1, transStack1); right.lineTo(transX1, transY1); right.lineTo(transXRight, transStackRight); right.closePath(); } } else { // handle negative value transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[0], dataArea, edge1); float transStack1 = (float) rangeAxis.valueToJava2D(stack1[0], dataArea, edge1); float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[0], dataArea, edge1); // LEFT POLYGON if (y0 >= 0.0) { left.moveTo(transX1, transStack1); left.lineTo(transX1, transY1); left.lineTo(transXLeft, transStackLeft); left.clone(); } else { double yleft = (y0 + y1) / 2.0 + stackLeft[0]; float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1); left.moveTo(transX1, transY1); left.lineTo(transX1, transStack1); left.lineTo(transXLeft, transStackLeft); left.lineTo(transXLeft, transYLeft); left.closePath(); } float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[0], dataArea, edge1); // RIGHT POLYGON if (y2 >= 0.0) { right.moveTo(transX1, transStack1); right.lineTo(transX1, transY1); right.lineTo(transXRight, transStackRight); right.closePath(); } else { double yright = (y1 + y2) / 2.0 + stackRight[0]; float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1); right.moveTo(transX1, transStack1); right.lineTo(transX1, transY1); right.lineTo(transXRight, transYRight); right.lineTo(transXRight, transStackRight); right.closePath(); } } // Get series Paint and Stroke Paint itemPaint = getItemPaint(series, item); if (pass == 0) { g2.setPaint(itemPaint); g2.fill(left); g2.fill(right); } else if (pass == 1) { if (item == 0 || (y1 == 0.0 && y0 == 0.0)) { return; } // get the data point... if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } if (Double.isNaN(y0) || Double.isNaN(x0)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0 + stack0[1], dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } state.workingLine.setLine(transX0, transY0, transX1, transY1); if (state.workingLine.intersects(dataArea)) { g2.setStroke(getItemStroke(series, item)); g2.setPaint(super.lookupSeriesPaint(series)); g2.draw(state.workingLine); } return; } // add an entity for the item... if (entities != null) { GeneralPath gp = new GeneralPath(left); gp.append(right, false); entityArea = gp; addEntity(entities, entityArea, dataset, series, item, transX1, transY1); } }
From source file:net.sf.fspdfs.chartthemes.spring.EyeCandySixtiesChartTheme.java
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return;// w ww . j ava2s. c om } double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); double barL0 = Math.min(transL0, transL1); double barLength = Math.abs(transL1 - transL0); // draw the bar... Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } Paint itemPaint = getItemPaint(row, column); if (itemPaint instanceof GradientPaint) { itemPaint = getGradientPaintTransformer().transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); g2.fill(bar); double x0 = bar.getMinX(); double x1 = x0 + getXOffset(); double x2 = bar.getMaxX(); double x3 = x2 + getXOffset(); double y0 = bar.getMinY() - getYOffset(); double y1 = bar.getMinY(); double y2 = bar.getMaxY() - getYOffset(); double y3 = bar.getMaxY(); GeneralPath bar3dRight = null; GeneralPath bar3dTop = null; if (barLength > 0.0) { bar3dRight = new GeneralPath(); bar3dRight.moveTo((float) x2, (float) y3); bar3dRight.lineTo((float) x2, (float) y1); bar3dRight.lineTo((float) x3, (float) y0); bar3dRight.lineTo((float) x3, (float) y2); bar3dRight.closePath(); if (itemPaint instanceof Color) { g2.setPaint(((Color) itemPaint).darker()); } else if (itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; g2.setPaint(new StandardGradientPaintTransformer().transform(new GradientPaint(gp.getPoint1(), gp.getColor1().darker(), gp.getPoint2(), gp.getColor2().darker(), gp.isCyclic()), bar3dRight)); } g2.fill(bar3dRight); } bar3dTop = new GeneralPath(); bar3dTop.moveTo((float) x0, (float) y1); bar3dTop.lineTo((float) x1, (float) y0); bar3dTop.lineTo((float) x3, (float) y0); bar3dTop.lineTo((float) x2, (float) y1); bar3dTop.closePath(); g2.fill(bar3dTop); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (bar3dRight != null) { g2.draw(bar3dRight); } if (bar3dTop != null) { g2.draw(bar3dTop); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { GeneralPath barOutline = new GeneralPath(); barOutline.moveTo((float) x0, (float) y3); barOutline.lineTo((float) x0, (float) y1); barOutline.lineTo((float) x1, (float) y0); barOutline.lineTo((float) x3, (float) y0); barOutline.lineTo((float) x3, (float) y2); barOutline.lineTo((float) x2, (float) y3); barOutline.closePath(); addItemEntity(entities, dataset, row, column, barOutline); } }
From source file:net.sf.jasperreports.chartthemes.spring.EyeCandySixtiesChartTheme.java
@Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return;// ww w .j a v a 2 s .c om } double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); double barL0 = Math.min(transL0, transL1); double barLength = Math.abs(transL1 - transL0); // draw the bar... Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } Paint itemPaint = getItemPaint(row, column); if (itemPaint instanceof GradientPaint) { itemPaint = getGradientPaintTransformer().transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); g2.fill(bar); double x0 = bar.getMinX(); double x1 = x0 + getXOffset(); double x2 = bar.getMaxX(); double x3 = x2 + getXOffset(); double y0 = bar.getMinY() - getYOffset(); double y1 = bar.getMinY(); double y2 = bar.getMaxY() - getYOffset(); double y3 = bar.getMaxY(); GeneralPath bar3dRight = null; GeneralPath bar3dTop = null; if (barLength > 0.0) { bar3dRight = new GeneralPath(); bar3dRight.moveTo((float) x2, (float) y3); bar3dRight.lineTo((float) x2, (float) y1); bar3dRight.lineTo((float) x3, (float) y0); bar3dRight.lineTo((float) x3, (float) y2); bar3dRight.closePath(); if (itemPaint instanceof Color) { g2.setPaint(((Color) itemPaint).darker()); } else if (itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; g2.setPaint(new StandardGradientPaintTransformer().transform(new GradientPaint(gp.getPoint1(), gp.getColor1().darker(), gp.getPoint2(), gp.getColor2().darker(), gp.isCyclic()), bar3dRight)); } g2.fill(bar3dRight); } bar3dTop = new GeneralPath(); bar3dTop.moveTo((float) x0, (float) y1); bar3dTop.lineTo((float) x1, (float) y0); bar3dTop.lineTo((float) x3, (float) y0); bar3dTop.lineTo((float) x2, (float) y1); bar3dTop.closePath(); g2.fill(bar3dTop); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (bar3dRight != null) { g2.draw(bar3dRight); } if (bar3dTop != null) { g2.draw(bar3dTop); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { GeneralPath barOutline = new GeneralPath(); barOutline.moveTo((float) x0, (float) y3); barOutline.lineTo((float) x0, (float) y1); barOutline.lineTo((float) x1, (float) y0); barOutline.lineTo((float) x3, (float) y0); barOutline.lineTo((float) x3, (float) y2); barOutline.lineTo((float) x2, (float) y3); barOutline.closePath(); addItemEntity(entities, dataset, row, column, barOutline); } }
From source file:ro.nextreports.engine.chart.JFreeChartExporter.java
private JFreeChart createLineChart() throws QueryException { XYSeriesCollection dataset = new XYSeriesCollection(); String chartTitle = replaceParameters(chart.getTitle().getTitle()); chartTitle = StringUtil.getI18nString(chartTitle, I18nUtil.getLanguageByName(chart, language)); Object[] charts = new Object[chart.getYColumns().size()]; List<String> legends = chart.getYColumnsLegends(); boolean hasLegend = false; for (int i = 0; i < charts.length; i++) { String legend = ""; try {/* w ww . j a v a 2 s. c o m*/ legend = replaceParameters(legends.get(i)); legend = StringUtil.getI18nString(legend, I18nUtil.getLanguageByName(chart, language)); } catch (IndexOutOfBoundsException ex) { // no legend set } if ((legend != null) && !"".equals(legend.trim())) { hasLegend = true; } XYSeries lineChart = new XYSeries(legend); charts[i] = lineChart; dataset.addSeries(lineChart); } String xLegend = StringUtil.getI18nString(replaceParameters(chart.getXLegend().getTitle()), I18nUtil.getLanguageByName(chart, language)); String yLegend = StringUtil.getI18nString(replaceParameters(chart.getYLegend().getTitle()), I18nUtil.getLanguageByName(chart, language)); JFreeChart jfreechart = ChartFactory.createXYLineChart(chartTitle, // Title replaceParameters(xLegend), // x-axis Label replaceParameters(yLegend), // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); // hide legend if necessary if (!hasLegend) { jfreechart.removeLegend(); } // hide border jfreechart.setBorderVisible(false); // title setTitle(jfreechart); // charts colors & values boolean showValues = (chart.getShowYValuesOnChart() == null) ? false : chart.getShowYValuesOnChart(); DecimalFormat decimalFormat; DecimalFormat percentageFormat; if (chart.getYTooltipPattern() == null) { decimalFormat = new DecimalFormat("#"); percentageFormat = new DecimalFormat("0.00%"); } else { decimalFormat = new DecimalFormat(chart.getYTooltipPattern()); percentageFormat = decimalFormat; } XYPlot plot = (XYPlot) jfreechart.getPlot(); for (int i = 0; i < charts.length; i++) { plot.getRenderer().setSeriesPaint(i, chart.getForegrounds().get(i)); if (showValues) { plot.getRenderer().setSeriesItemLabelsVisible(i, true); plot.getRenderer().setSeriesItemLabelGenerator(i, new StandardXYItemLabelGenerator("{2}", decimalFormat, percentageFormat)); } } if (showValues) { // increase a little bit the range axis to view all item label values over points plot.getRangeAxis().setUpperMargin(0.2); } // grid axis visibility & colors if ((chart.getXShowGrid() != null) && !chart.getXShowGrid()) { plot.setDomainGridlinesVisible(false); } else { if (chart.getXGridColor() != null) { plot.setDomainGridlinePaint(chart.getXGridColor()); } else { plot.setDomainGridlinePaint(Color.BLACK); } } if ((chart.getYShowGrid() != null) && !chart.getYShowGrid()) { plot.setRangeGridlinesVisible(false); } else { if (chart.getYGridColor() != null) { plot.setRangeGridlinePaint(chart.getYGridColor()); } else { plot.setRangeGridlinePaint(Color.BLACK); } } // chart background plot.setBackgroundPaint(chart.getBackground()); // labels color plot.getDomainAxis().setTickLabelPaint(chart.getXColor()); plot.getRangeAxis().setTickLabelPaint(chart.getYColor()); //legend color plot.getDomainAxis().setLabelPaint(chart.getXLegend().getColor()); plot.getRangeAxis().setLabelPaint(chart.getYLegend().getColor()); // legend font plot.getDomainAxis().setLabelFont(chart.getXLegend().getFont()); plot.getRangeAxis().setLabelFont(chart.getYLegend().getFont()); // hide labels if ((chart.getXShowLabel() != null) && !chart.getXShowLabel()) { plot.getDomainAxis().setTickLabelsVisible(false); plot.getDomainAxis().setTickMarksVisible(false); } if ((chart.getYShowLabel() != null) && !chart.getYShowLabel()) { plot.getRangeAxis().setTickLabelsVisible(false); plot.getRangeAxis().setTickMarksVisible(false); } // label orientation if (chart.getXorientation() == Chart.VERTICAL) { plot.getDomainAxis().setVerticalTickLabels(true); } // labels fonts plot.getDomainAxis().setTickLabelFont(chart.getXLabelFont()); plot.getRangeAxis().setTickLabelFont(chart.getYLabelFont()); // point style Shape pointShape = null; byte style = chart.getType().getStyle(); switch (style) { case ChartType.STYLE_LINE_DOT_SOLID: case ChartType.STYLE_LINE_DOT_HOLLOW: pointShape = new Ellipse2D.Float(-3.0f, -3.0f, 6.0f, 6.0f); break; case ChartType.STYLE_LINE_DOT_ANCHOR: // triangle GeneralPath s5 = new GeneralPath(); s5.moveTo(0.0f, -3.0f); s5.lineTo(3.0f, 3.0f); s5.lineTo(-3.0f, 3.0f); s5.closePath(); pointShape = s5; break; case ChartType.STYLE_LINE_DOT_BOW: GeneralPath s4 = new GeneralPath(); s4.moveTo(-3.0f, -3.0f); s4.lineTo(3.0f, -3.0f); s4.lineTo(-3.0f, 3.0f); s4.lineTo(3.0f, 3.0f); s4.closePath(); pointShape = s4; break; case ChartType.STYLE_LINE_DOT_STAR: pointShape = new Star(-3.0f, 0f).getShape(); break; default: // no shape break; } if (pointShape != null) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setUseFillPaint(true); for (int i = 0; i < charts.length; i++) { renderer.setSeriesShapesVisible(i, true); if (style != ChartType.STYLE_LINE_DOT_SOLID) { renderer.setSeriesFillPaint(i, chart.getBackground()); } else { renderer.setSeriesFillPaint(i, chart.getForegrounds().get(i)); } renderer.setSeriesShape(i, pointShape); } } final HashMap<String, String> formatValues = createChart(plot.getRangeAxis(), charts); // in x axis does not contain number values , values are strings representing one unit if (!integerXValue) { ((NumberAxis) plot.getDomainAxis()).setTickUnit(new NumberTickUnit(1)); ((NumberAxis) plot.getDomainAxis()).setNumberFormatOverride(new DecimalFormat() { @Override public StringBuffer format(double number, StringBuffer result, FieldPosition fieldPosition) { String s = formatValues.get(String.valueOf(Math.round(number))); if (s == null) { s = ""; } return result.append(s); } }); } return jfreechart; }