List of usage examples for org.jfree.data.xy XYDataset getXValue
public double getXValue(int series, int item);
From source file:ste.travian.world.TileRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device./*from w ww . j ava 2s . c o m*/ * @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 (horizontal) axis. * @param rangeAxis the range (vertical) axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ 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) { // get the data point... double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double adjx = (this.dotWidth - 1) / 2.0; double adjy = (this.dotHeight - 1) / 2.0; if (Double.isNaN(y)) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx; double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy; g2.setPaint(getItemPaint(series, item)); if (orientation == PlotOrientation.HORIZONTAL) { g2.fillRect((int) transY, (int) transX, this.dotHeight, this.dotWidth); } else if (orientation == PlotOrientation.VERTICAL) { g2.fillRect((int) transX, (int) transY, this.dotWidth, this.dotHeight); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); // add an entity for the item, but only if it falls within the data // area... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } int xx = (int) transX; int yy = (int) transY; if (orientation == PlotOrientation.HORIZONTAL) { xx = (int) transY; yy = (int) transX; } if (entities != null && dataArea.contains(xx, yy)) { addEntity(entities, null, dataset, series, item, (int) xx, (int) yy); } }
From source file:cgpanalyser.gui.chart.XYChartPanel.java
public void setPrevCrosshairValue(JFreeChart jfreechart) { XYPlot plot = (XYPlot) jfreechart.getPlot(); XYDataset dataset = plot.getDataset(); //set crosshair to previous value if not on first already for (int i = 0; i < dataSampler.getLastToDisplay().size(); i++) { //find generation in datasampler.todisplay if ((int) plot.getDomainCrosshairValue() == dataSampler.getLastToDisplay().get(i).getGenNumber()) { if (i > 0) { plot.setDomainCrosshairValue(dataset.getXValue(0, i - 1)); plot.setRangeCrosshairValue(dataset.getYValue(0, i - 1)); }/*ww w . j av a 2 s .c om*/ break; } } }
From source file:org.mwc.cmap.grideditor.chart.RendererWithDynamicFeedback.java
/** * @see XYLineAndShapeRenderer#drawPrimaryLine *///from ww w . j a v a 2s. c o m protected void drawFeedBackPrimaryLine(final XYItemRendererState state, final Graphics2D g2, final XYPlot plot, final XYDataset dataset, final int pass, // final int series, final int item, final ValueAxis domainAxis, final ValueAxis rangeAxis, final Rectangle2D dataArea) { if (item != 0) { final double x1 = myFeedBackValue != null ? myFeedBackValue.x : dataset.getXValue(series, item); final double y1 = myFeedBackValue != null ? myFeedBackValue.y : dataset.getYValue(series, item); final double x0 = dataset.getXValue(series, item - 1); final double y0 = dataset.getYValue(series, item - 1); drawFeedbackEdge(x0, y0, x1, y1, state, g2, plot, domainAxis, rangeAxis, dataArea); } if (item < dataset.getItemCount(series) - 1) { final double x0 = myFeedBackValue != null ? myFeedBackValue.x : dataset.getXValue(series, item); final double y0 = myFeedBackValue != null ? myFeedBackValue.y : dataset.getYValue(series, item); final double x1 = dataset.getXValue(series, item + 1); final double y1 = dataset.getYValue(series, item + 1); drawFeedbackEdge(x0, y0, x1, y1, state, g2, plot, domainAxis, rangeAxis, dataArea); } }
From source file:ChartUsingJava.XYSmoothLineAndShapeRenderer.java
/** * Draws the item (first pass). This method draws the lines * connecting the items.//from ww w. j a va 2s . c om * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @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 pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). */ protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { if (item == 0) { return; } // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } double x0 = dataset.getXValue(series, item - 1); double y0 = dataset.getYValue(series, item - 1); 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, dataArea, yAxisLocation); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } Point2D.Double point0 = new Point2D.Double(); Point2D.Double point1 = new Point2D.Double(); Point2D.Double point2 = new Point2D.Double(); Point2D.Double point3 = new Point2D.Double(); if (item == 1) { point0 = null; } else { point0.x = domainAxis.valueToJava2D(dataset.getXValue(series, item - 2), dataArea, xAxisLocation); point0.y = rangeAxis.valueToJava2D(dataset.getYValue(series, item - 2), dataArea, yAxisLocation); } point1.x = transX0; point1.y = transY0; point2.x = transX1; point2.y = transY1; if ((item + 1) == dataset.getItemCount(series)) { point3 = null; } else { point3.x = domainAxis.valueToJava2D(dataset.getXValue(series, item + 1), dataArea, xAxisLocation); point3.y = rangeAxis.valueToJava2D(dataset.getYValue(series, item + 1), dataArea, yAxisLocation); } int steps = ((int) ((point2.x - point1.x) / 0.2) < 30) ? (int) ((point2.x - point1.x) / 0.2) : 30; Point2D.Double[] points = getBezierCurve(point0, point1, point2, point3, 1, steps); for (int i = 1; i < points.length; i++) { transX0 = points[i - 1].x; transY0 = points[i - 1].y; transX1 = points[i].x; transY1 = points[i].y; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } if (state.workingLine.intersects(dataArea)) { drawFirstPassShape(g2, pass, series, item, state.workingLine); } } }
From source file:net.sf.clichart.chart.AbstractChartBuilder.java
private double calculateBarWidth(XYDataset axisDataset, int lineWeight) { double minimumInterval = -1; for (int seriesIndex = 0; seriesIndex < axisDataset.getSeriesCount(); seriesIndex++) { for (int itemIndex = 1; itemIndex < axisDataset.getItemCount(seriesIndex); itemIndex++) { double interval = axisDataset.getXValue(seriesIndex, itemIndex) - axisDataset.getXValue(seriesIndex, itemIndex - 1); if (itemIndex == 1) { minimumInterval = interval; } else { minimumInterval = Math.min(minimumInterval, interval); }//from w ww .j av a2 s . c o m } } double barWeight = 0.5; if (lineWeight >= 0 && lineWeight <= 5) { barWeight = 0.2 * lineWeight; } return minimumInterval * barWeight; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.XYDotRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device. * @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 (horizontal) axis. * @param rangeAxis the range (vertical) axis. * @param dataset the dataset.//from w w w. jav a2s. c om * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot (<code>null</code> permitted). * @param pass the pass index. */ public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea, final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis, final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState, final int pass) { // get the data point... final double x = dataset.getXValue(series, item); final double y = dataset.getYValue(series, item); final double adjx = (this.dotWidth - 1) / 2.0; final double adjy = (this.dotHeight - 1) / 2.0; if (!Double.isNaN(y)) { final RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); final double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx; final double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy; g2.setPaint(getItemPaint(series, item)); final PlotOrientation orientation = plot.getOrientation(); final Shape s; if (orientation == PlotOrientation.HORIZONTAL) { //noinspection SuspiciousNameCombination s = new Rectangle2D.Double(transY, transX, this.dotHeight, this.dotWidth); } else if (orientation == PlotOrientation.VERTICAL) { s = new Rectangle2D.Double(transX, transY, this.dotWidth, this.dotHeight); } else { throw new IllegalStateException("PlotOrientation is neither Horizontal nor Vertical"); } g2.fill(s); final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); // collect entity and tool tip information... if (state.getInfo() != null) { final EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; final XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } String url = null; if (getURLGenerator() != null) { url = getURLGenerator().generateURL(dataset, series, item); } final XYItemEntity entity = new XYItemEntity(s, dataset, series, item, tip, url); entities.add(entity); } } } }
From source file:anl.verdi.plot.jfree.XYBlockRenderer.java
/** * Draws the block representing the specified item. * * @param g2 the graphics device. * @param state the state.//from w w w. ja v a 2s . c om * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index. */ 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) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = 0.0; double max = paintScale.getUpperBound(); double min = paintScale.getLowerBound(); if (dataset instanceof XYZDataset) z = ((XYZDataset) dataset).getZValue(series, item); //NOTE: so to get the max/min color instead of unknown (Qun He, UNC, 03/19/2009) if (z > max) z = max; if (z < min) z = min; Color p = (Color) this.paintScale.getPaint(z); double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight + this.yOffset, dataArea, plot.getRangeAxisEdge()); Rectangle2D block; PlotOrientation orientation = plot.getOrientation(); if (orientation.equals(PlotOrientation.HORIZONTAL)) { block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0), Math.abs(xx0 - xx1)); } else { block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0), Math.abs(yy1 - yy0)); } g2.setColor(p); g2.fill(block); if (gridLinesEnabled) { boolean aaOn = false; if (g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING) == RenderingHints.VALUE_ANTIALIAS_ON) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); aaOn = true; } g2.setPaint(gridLineColor); g2.setStroke(gridLineStroke); g2.draw(block); if (aaOn) g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } else { g2.setStroke(basicStroke); g2.draw(block); } }
From source file:nl.vu.nat.jfreechartcustom.XYBlockRenderer.java
/** * Draws the block representing the specified item. * * @param g2 the graphics device.//from w w w .j a v a2 s . c om * @param state the state. * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index. */ 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) { boolean bAddEntity = false; double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = 0.0; if (dataset instanceof XYZDataset) { z = ((XYZDataset) dataset).getZValue(series, item); } Paint p = this.paintScale.getPaint(z); double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight + this.yOffset, dataArea, plot.getRangeAxisEdge()); Rectangle2D block; PlotOrientation orientation = plot.getOrientation(); if (orientation.equals(PlotOrientation.HORIZONTAL)) { block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0), Math.abs(xx0 - xx1)); } else { // Detect if Rectangle is smaller than 2 by 2 pixels block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0), Math.abs(yy1 - yy0)); } g2.setPaint(p); g2.fill(block); g2.setStroke(new BasicStroke(1.0f)); // g2.draw(block); EntityCollection entities = state.getEntityCollection(); if (entities != null && bAddEntity) { addEntity(entities, block, dataset, series, item, 0.0, 0.0); } }
From source file:net.sf.maltcms.common.charts.api.overlay.SelectionOverlay.java
private void updateCrosshairs(final Dataset ds, final int seriesIndex, final int itemIndex) { if (ds instanceof XYDataset) { XYDataset xyds = (XYDataset) ds; double x = xyds.getXValue(seriesIndex, itemIndex); double y = xyds.getYValue(seriesIndex, itemIndex); domainCrosshair.setValue(x);//w ww .ja v a 2s .c o m rangeCrosshair.setValue(y); } else if (ds instanceof CategoryDataset) { CategoryDataset cds = (CategoryDataset) ds; double y = cds.getValue(seriesIndex, itemIndex).doubleValue(); domainCrosshair.setValue(itemIndex); rangeCrosshair.setValue(y); } }
From source file:com.intel.stl.ui.main.view.DataRateChartRangeUpdater.java
@Override public void updateChartRange(JFreeChart chart, long lower, long upper) { if (lower > upper) { return;/*from ww w . j a v a 2s . co m*/ } XYPlot xyplot = (XYPlot) chart.getPlot(); NumberAxis range = (NumberAxis) xyplot.getRangeAxis(); range.setRangeWithMargins(lower, upper); range.setLowerBound(0); // If upper is less than 1000, don't do anything to convert the y-axis // label and // convert the unit tick. TickUnitSource unitSrc = createTickUnits(upper); if (unitSrc != null) { // Change tick values only if upper is above 1000. range.setStandardTickUnits(unitSrc); xyplot.getRenderer().setBaseToolTipGenerator( new StandardXYToolTipGenerator("<html><b>{0}</b><br> Time: {1}<br> Data: {2}</html>", Util.getHHMMSS(), new DecimalFormat("#,##0.00" + " " + unitDes)) { private static final long serialVersionUID = 4825888117284967486L; @Override protected Object[] createItemArray(XYDataset dataset, int series, int item) { String nullXString = "null"; String nullYString = "null"; Object[] result = new Object[3]; result[0] = dataset.getSeriesKey(series).toString(); double x = dataset.getXValue(series, item); if (Double.isNaN(x) && dataset.getX(series, item) == null) { result[1] = nullXString; } else { DateFormat xDateFormat = this.getXDateFormat(); if (xDateFormat != null) { result[1] = xDateFormat.format(new Date((long) x)); } else { result[1] = this.getXFormat().format(x); } } double y = dataset.getYValue(series, item); if (Double.isNaN(y) && dataset.getY(series, item) == null) { result[2] = nullYString; } else { DateFormat yDateFormat = this.getYDateFormat(); if (yDateFormat != null) { result[2] = yDateFormat.format(new Date((long) y)); } else { result[2] = this.getYFormat().format(y / tickUnitSize); } } return result; } }); } else { range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } // y-axis label setChartRangeLabel(range); }