title, "X", "Y", createSampleData(), PlotOrientation.VERTICAL, true, true, false); XYPlot xyPlot = (XYPlot) jfreechart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); XYItemRenderer renderer = xyPlot.getRenderer(); renderer.setSeriesPaint(0, Color.blue); NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis(); domain.setRange(0.00, 1.00); domain.setTickUnit(new NumberTickUnit(0.1)); domain.setVerticalTickLabels(true); NumberAxis range = (NumberAxis) xyPlot.getRangeAxis(); range.setRange(0.0, 1.0); range.setTickUnit(new NumberTickUnit(0.1));
@Override public void writeGraphFiles(BenchmarkReport benchmarkReport) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Score calculation speed per second"); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setOrientation(PlotOrientation.VERTICAL); int seriesIndex = 0; for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) { plot.setDataset(seriesIndex, new XYSeriesCollection(series)); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); plot.setRenderer(seriesIndex, renderer); seriesIndex++; JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " score calculation speed statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "ScoreCalculationSpeedStatistic");
private XYPlot createPlot(BenchmarkReport benchmarkReport) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Best solution mutation count"); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); yAxis.setAutoRangeIncludesZero(true); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setOrientation(PlotOrientation.VERTICAL); return plot; }
private XYPlot createScalabilityPlot(List<XYSeries> seriesList, String xAxisLabel, NumberFormat xAxisNumberFormat, String yAxisLabel, NumberFormat yAxisNumberFormat) { NumberAxis xAxis; if (useLogarithmicProblemScale(seriesList)) { LogarithmicAxis logarithmicAxis = new LogarithmicAxis(xAxisLabel + " (logarithmic)"); logarithmicAxis.setAllowNegativesFlag(true); xAxis = logarithmicAxis; } else { xAxis = new NumberAxis(xAxisLabel); } xAxis.setNumberFormatOverride(xAxisNumberFormat); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setNumberFormatOverride(yAxisNumberFormat); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); int seriesIndex = 0; for (XYSeries series : seriesList) { XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series); plot.setDataset(seriesIndex, seriesCollection); XYItemRenderer renderer = createScalabilityPlotRenderer(yAxisNumberFormat); plot.setRenderer(seriesIndex, renderer); seriesIndex++; } plot.setOrientation(PlotOrientation.VERTICAL); return plot; }
PlotOrientation.VERTICAL, true, true, false); Shape cross = ShapeUtilities.createDiagonalCross(3, 1); XYPlot xyPlot = (XYPlot) jfreechart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); XYItemRenderer renderer = xyPlot.getRenderer(); renderer.setSeriesShape(0, cross); renderer.setSeriesPaint(0, Color.red); return new ChartPanel(jfreechart);
@Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { Rectangle2D box = chartPanel.getScreenDataArea(); float sx = (float) plot.getDomainAxis().valueToJava2D(x, box, plot.getDomainAxisEdge()); float maxXLim = (float) box.getWidth() - g2.getFontMetrics().stringWidth(text); if (sx > maxXLim) { sx = maxXLim; } if (sx < box.getMinX()) { sx = (float) box.getMinX(); } float sy = (float) plot.getRangeAxis().valueToJava2D(y, chartPanel.getScreenDataArea(), plot.getRangeAxisEdge()); g2.setTransform(new AffineTransform()); g2.setColor(color); g2.setFont(font); g2.drawString(text, sx, sy); }
RectangleInsets insets = getInsets(); insets.trim(area); AxisSpace space = calculateAxisSpace(g2, area); Rectangle2D dataArea = space.shrink(area, null); this.axisOffset.trim(dataArea); dataArea = integerise(dataArea); if (dataArea.isEmpty()) { return; createAndAddEntity((Rectangle2D) dataArea.clone(), info, null, null); if (info != null) { info.setDataArea(dataArea); drawBackground(g2, dataArea); Map axisStateMap = drawAxes(g2, area, dataArea, info); PlotOrientation orient = getOrientation(); crosshairState.setAnchorY(Double.NaN); if (anchor != null) { ValueAxis domainAxis = getDomainAxis(); if (domainAxis != null) { double x; if (orient == PlotOrientation.VERTICAL) { x = domainAxis.java2DToValue(anchor.getX(), dataArea, getDomainAxisEdge());
/** * Utility method for drawing a vertical line on the data area of the plot. * * @param g2 the graphics device. * @param dataArea the data area. * @param value the coordinate, where to draw the line. * @param stroke the stroke to use. * @param paint the paint to use. */ protected void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { ValueAxis axis = getDomainAxis(); if (getOrientation() == PlotOrientation.HORIZONTAL) { axis = getRangeAxis(); } if (axis.getRange().contains(value)) { double xx = axis.valueToJava2D(value, dataArea, RectangleEdge.BOTTOM); Line2D line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY()); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } }
/** * Utility method for drawing a horizontal line across the data area of the * plot. * * @param g2 the graphics device. * @param dataArea the data area. * @param value the coordinate, where to draw the line. * @param stroke the stroke to use. * @param paint the paint to use. */ protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { ValueAxis axis = getRangeAxis(); if (getOrientation() == PlotOrientation.HORIZONTAL) { axis = getDomainAxis(); } if (axis.getRange().contains(value)) { double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } }
private Shape createShape() { XYPlot plot = chartPanel.getChart().getXYPlot(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); double vx1 = areaType == AreaType.Y_RANGE ? dataArea.getX() : point1.x; double vy1 = areaType == AreaType.X_RANGE ? dataArea.getY() : point1.y; double vx2 = areaType == AreaType.Y_RANGE ? dataArea.getX() + dataArea.getWidth() : point2.x; double vy2 = areaType == AreaType.X_RANGE ? dataArea.getY() + dataArea.getHeight() : point2.y; double x1 = plot.getDomainAxis().java2DToValue(vx1, dataArea, domainEdge); double x2 = plot.getDomainAxis().java2DToValue(vx2, dataArea, domainEdge); double y1 = plot.getRangeAxis().java2DToValue(vy1, dataArea, rangeEdge); double y2 = plot.getRangeAxis().java2DToValue(vy2, dataArea, rangeEdge); double dx = abs(x2 - x1); double dy = abs(y2 - y1); final Shape shape; if (areaType == AreaType.ELLIPSE) { shape = new Ellipse2D.Double(x1 - dx, y1 - dy, 2.0 * dx, 2.0 * dy); } else if (areaType == AreaType.RECTANGLE) { shape = new Rectangle2D.Double(x1 - dx, y1 - dy, 2.0 * dx, 2.0 * dy); } else if (areaType == AreaType.X_RANGE || areaType == AreaType.Y_RANGE) { shape = new Rectangle2D.Double(min(x1, x2), min(y1, y2), dx, dy); } else { throw new IllegalStateException("areaType = " + areaType); } return shape; }
RectangleInsets insets = getInsets(); insets.trim(area); AxisSpace space = calculateAxisSpace(g2, area); Rectangle2D dataArea = space.shrink(area, null); this.axisOffset.trim(dataArea); createAndAddEntity((Rectangle2D) dataArea.clone(), info, null, null); if (info != null) { info.setDataArea(dataArea); drawBackground(g2, dataArea); Map axisStateMap = drawAxes(g2, area, dataArea, info); PlotOrientation orient = getOrientation(); crosshairState.setAnchorY(Double.NaN); if (anchor != null) { ValueAxis domainAxis = getDomainAxis(); if (domainAxis != null) { double x; if (orient == PlotOrientation.VERTICAL) { x = domainAxis.java2DToValue(anchor.getX(), dataArea, getDomainAxisEdge()); x = domainAxis.java2DToValue(anchor.getY(), dataArea, getDomainAxisEdge()); ValueAxis rangeAxis = getRangeAxis(); if (rangeAxis != null) {
ValueAxis xAxis = getDomainAxis(); if (xAxis == null) { // we can't draw quadrants without a valid x-axis return; double x = xAxis.getRange().constrain(this.quadrantOrigin.getX()); double xx = xAxis.valueToJava2D(x, area, getDomainAxisEdge()); ValueAxis yAxis = getRangeAxis(); if (yAxis == null) { // we can't draw quadrants without a valid y-axis return; double y = yAxis.getRange().constrain(this.quadrantOrigin.getY()); double yy = yAxis.valueToJava2D(y, area, getRangeAxisEdge()); double xxmin = xAxis.valueToJava2D(xmin, area, getDomainAxisEdge()); double xxmax = xAxis.valueToJava2D(xmax, area, getDomainAxisEdge()); double yymin = yAxis.valueToJava2D(ymin, area, getRangeAxisEdge()); double yymax = yAxis.valueToJava2D(ymax, area, getRangeAxisEdge()); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getBackgroundAlpha())); for (int i = 0; i < 4; i++) { if (this.quadrantPaint[i] != null && r[i] != null) { g2.setPaint(this.quadrantPaint[i]);
Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); g2.clip(dataArea); JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); RectangleEdge xAxisEdge = plot.getDomainAxisEdge(); Iterator iterator = this.xCrosshairs.iterator(); while (iterator.hasNext()) { if (ch.isVisible()) { double x = ch.getValue(); double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge); if (plot.getOrientation() == PlotOrientation.VERTICAL) { drawVerticalCrosshair(g2, dataArea, xx, ch); ValueAxis yAxis = plot.getRangeAxis(); RectangleEdge yAxisEdge = plot.getRangeAxisEdge(); iterator = this.yCrosshairs.iterator(); while (iterator.hasNext()) { if (ch.isVisible()) { double y = ch.getValue(); double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge); if (plot.getOrientation() == PlotOrientation.VERTICAL) { drawHorizontalCrosshair(g2, dataArea, yy, ch); g2.setClip(savedClip);
this.chart_ = ChartFactory.createXYLineChart( title, "Count Volumes [veh/h]", // x axis label renderer.setSeriesPaint(0, Color.black); renderer.setSeriesToolTipGenerator(0, tt_gen); renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0)); plot.addAnnotation(annotation0); XYTextAnnotation annotation1=new XYTextAnnotation("count",13000.0, 10000.0); annotation1.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation1); XYTextAnnotation annotation2=new XYTextAnnotation("0.5 count",11000.0, 3500.0); annotation2.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation2); plot.setDomainAxis(axis_x); plot.setRangeAxis(axis_y); plot.setRenderer(0, renderer); plot.setRenderer(1, renderer2); plot.setDataset(1, dataset_outliers); plot.setRenderer(2, renderer3); plot.setDataset(2, dataset1); plot.getRangeAxis().setRange(1.0, 19000.0); plot.getDomainAxis().setRange(1.0, 19000.0);
@Override public void write(OutputStream aStream) throws IOException { JFreeChart chart = ChartFactory.createXYLineChart(null, "Recall", "Precision", dataset, PlotOrientation.VERTICAL, false, false, false); chart.getXYPlot().setRenderer(new XYSplineRenderer()); chart.getXYPlot().getRangeAxis().setRange(0.0, 1.0); chart.getXYPlot().getDomainAxis().setRange(0.0, 1.0); ChartUtil.writeChartAsSVG(aStream, chart, 400, 400); } }
public static JFreeChart createXYChart(String title, XYDataset data, String xLabel, String yLabel, int pointRadius, int lineThickness, ColorTheme theme) { JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, data, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); Shape icon = new Ellipse2D.Double(-pointRadius, -pointRadius, pointRadius * 2, pointRadius * 2); plot.setRenderer(renderer); Color[] colors = generateJetSpectrum(data.getSeriesCount()); for (int i = 0; i < data.getSeriesCount(); i++) { plot.getRenderer().setSeriesStroke(i, new BasicStroke(lineThickness)); plot.getRenderer().setSeriesShape(i, icon); ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesVisible(i, true); ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesFilled(i, true); plot.getRenderer().setSeriesPaint(i, colors[i]); legend.setItemFont(newLegendFont); ValueAxis domainAxis = ((XYPlot) chart.getPlot()).getDomainAxis(); Font domainAxisLabelFont = domainAxis.getLabelFont(); float domainAxisLabelFontSize = domainAxisLabelFont.getSize(); domainAxis.setLabelFont(domainAxisLabelFont.deriveFont(domainAxisLabelFontSize * 0.6f)); ValueAxis rangeAxis = ((XYPlot) chart.getPlot()).getRangeAxis(); Font rangeAxisLabelFont = rangeAxis.getLabelFont(); float rangeAxisLabelFontSize = rangeAxisLabelFont.getSize();
final boolean overlayRemoved = removeOverlay(); XYPlot plot = chartPanel.getChart().getXYPlot(); if (dataArea.contains(point)) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); double mx = plot.getDomainAxis().java2DToValue(point.x, dataArea, domainEdge); double my = plot.getRangeAxis().java2DToValue(point.y, dataArea, rangeEdge); int datasetCount = chartPanel.getChart().getXYPlot().getDatasetCount(); double minDist = Double.POSITIVE_INFINITY; for (int datasetIndex = 0; datasetIndex < datasetCount; datasetIndex++) { XYDataset xyDataset = chartPanel.getChart().getXYPlot().getDataset(datasetIndex); int seriesCount = xyDataset.getSeriesCount(); for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) { int itemCount = xyDataset.getItemCount(seriesIndex); for (int itemIndex = 0; itemIndex < itemCount; itemIndex++) { double x = xyDataset.getXValue(seriesIndex, itemIndex); double y = xyDataset.getYValue(seriesIndex, itemIndex); double dist = (x - mx) * (x - mx) + (y - my) * (y - my);
chart = ChartFactory.createXYAreaChart("", labelX, labelY, ds, PlotOrientation.VERTICAL, showLegend, false, false); ((XYAreaRenderer) chart.getXYPlot().getRenderer()).setOutline(true); chart = ChartFactory.createStackedXYAreaChart("", labelX, labelY, ds, PlotOrientation.VERTICAL, showLegend, false, false); chart = ChartFactory.createXYLineChart("", labelX, labelY, ds, PlotOrientation.VERTICAL, showLegend, false, false); chart.getXYPlot().setRenderer(renderer); chart.setAntiAlias(true); chart.setBackgroundPaint(new Color(backgroundColor)); for (int i = 0; i < seriesMaxCount; i++) { if (seriesColor[i] >= 0) { chart.getXYPlot().getRenderer().setSeriesPaint(i, new Color(seriesColor[i])); chart.getXYPlot().getRenderer().setSeriesOutlinePaint(i, new Color(seriesOutlineColor[i])); chart.getXYPlot().setDomainGridlinePaint(new Color(gridColor)); chart.getXYPlot().setRangeGridlinePaint(new Color(gridColor)); chart.getXYPlot().setDomainAxis(0, new DateAxis()); chart.getXYPlot().setDomainAxis(1, new DateAxis()); chart.getXYPlot().setInsets(new RectangleInsets(-15, 0, 0, 10));
try plot = getChart().getXYPlot(); final String xColumnName = plot.getDomainAxis().getLabel(); final int nPoints = plot.getDataset( 0 ).getItemCount( 0 ); for ( int k = 0; k < nPoints; k++ ) final double xVal = plot.getDataset( 0 ).getXValue( 0, k ); table.addValue( xColumnName, xVal ); final int nSets = plot.getDatasetCount(); for ( int i = 0; i < nSets; i++ ) final XYDataset dataset = plot.getDataset( i ); if ( dataset instanceof XYEdgeSeriesCollection ) continue; final int nSeries = dataset.getSeriesCount(); for ( int j = 0; j < nSeries; j++ ) final Comparable seriesKey = dataset.getSeriesKey( j ); final String yColumnName = seriesKey.toString() + "(" + plot.getRangeAxis().getLabel() + ")"; final double yVal = dataset.getYValue( j, k ); table.addValue( yColumnName, yVal ); table.show( getChart().getTitle().getText() );
private void updatePoint(ChartMouseEvent event) { if (xyDataset == null || xyDataset.getSeriesCount() == 0 || (seriesIndex < 0 || seriesIndex >= xyDataset.getSeriesCount())) { if (removeOverlay()) { XYPlot plot = chartPanel.getChart().getXYPlot(); PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); double xData = plot.getDomainAxis().java2DToValue(xView, dataArea, domainEdge); int itemCount = xyDataset.getItemCount(seriesIndex); for (int i = 0; i < itemCount - 1; i++) { double x1 = xyDataset.getXValue(seriesIndex, i); double y2 = xyDataset.getYValue(seriesIndex, i + 1); double yData = y1 + (xData - x1) * (y2 - y1) / (x2 - x1); double yView = plot.getRangeAxis().valueToJava2D(yData, dataArea, rangeEdge); Point2D.Double viewPoint = new Point2D.Double(xView, yView); Point2D.Double dataPoint = new Point2D.Double(xData, yData);