@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()) { XYSeries series = new XYSeries(singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix()); XYItemRenderer renderer = new XYLineAndShapeRenderer(); if (singleBenchmarkResult.hasAllSuccess()) { ScoreCalculationSpeedSubSingleStatistic subSingleStatistic = (ScoreCalculationSpeedSubSingleStatistic) long timeMillisSpent = point.getTimeMillisSpent(); long scoreCalculationSpeed = point.getScoreCalculationSpeed(); series.add(timeMillisSpent, scoreCalculationSpeed); plot.setDataset(seriesIndex, new XYSeriesCollection(series)); seriesIndex++; JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " score calculation speed statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "ScoreCalculationSpeedStatistic");
JFreeChart chart = ChartFactory.createTimeSeriesChart( "Legal & General Unit Trust Prices", // title "Date", // x-axis label ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true);
setChart(ChartFactory.createXYLineChart(title, xLabel, yLabel, (XYDataset) dataset, PlotOrientation.VERTICAL, true, true, false)); XYPlot plot = getChart().getXYPlot(); plot.setDomainAxis(axis); } catch (Exception e) { NumberAxis axis = new NumberAxis(); plot.setDomainAxis(axis); NumberAxis axis = new NumberAxis(); plot.setDomainAxis(axis); getChart().setTitle((String) null); getChart().setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); renderer.setDrawSeriesLineAsPath(true); for (int i = 0; i < getMatrix().getColumnCount(); i++) { renderer.setSeriesStroke(i, new BasicStroke(3)); plot.setRenderer(i, renderer);
protected JFreeChart renderPreChart(Map<String, OXFFeatureCollection> entireCollMap, String[] observedProperties, ArrayList<TimeSeriesCollection> timeSeries, Calendar begin, Calendar end) { JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title "Date", // x-axis label observedProperties[0], // y-axis label ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); XYDataset additionalDataset = timeSeries.get(i); plot.setDataset(i, additionalDataset); plot.setRangeAxis(i, new NumberAxis(observedProperties[i]));
public static ChartPanel createGraph(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, double minRange, double maxRange, boolean showLegend) final JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getRangeAxis().setRange(minRange, maxRange);
XYSeries dataset = new XYSeries("Series"); for (int i = 0; i < tsData.length; i++) { dataset.add(i, (float) tsData[i]); XYSeriesCollection chartXYSeriesCollection = new XYSeriesCollection(dataset); XYSeries dot = new XYSeries("Dot"); dot.add((float) redDot, 0.0f); chartXYSeriesCollection.addSeries(dot); XYLineAndShapeRenderer xyRenderer = new XYLineAndShapeRenderer(true, false); xyRenderer.setBaseStroke(new BasicStroke(3)); xyRenderer.setSeriesPaint(0, new Color(0, 0, 0)); xyRenderer.setSeriesLinesVisible(0, true); xyRenderer.setSeriesShapesVisible(0, false); xyRenderer.setSeriesPaint(1, Color.RED); xyRenderer.setSeriesLinesVisible(1, false); xyRenderer.setSeriesShapesVisible(1, true); NumberAxis timeAxis = new NumberAxis(); timeAxis.setLabel("Time"); XYPlot timeseriesPlot = new XYPlot(chartXYSeriesCollection, timeAxis, valueAxis, xyRenderer); JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, timeseriesPlot, false);
private static final String title = "Scatter Shape Demo"; private static final Random rand = new Random(); private final XYSeries series = new XYSeries("Data"); title, "X", "Y", createSampleData(), PlotOrientation.VERTICAL, true, true, false); XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); xyPlot.setRenderer(new XYLineAndShapeRenderer(false, true) { axis.setRange(-3.0, 3.0); axis.setTickUnit(new NumberTickUnit(0.5)); axis.setVerticalTickLabels(vertical); XYSeriesCollection xySeriesCollection = new XYSeriesCollection(); for (int i = 0; i < N * N; i++) { series.add(rand.nextGaussian(), rand.nextGaussian()); xySeriesCollection.addSeries(series); return xySeriesCollection;
final XYLineAndShapeRenderer pointRenderer = new XYLineAndShapeRenderer(); final JFreeChart chart = ChartFactory.createXYLineChart( title, xAxisLabel, yAxisLabel, pointDataset, PlotOrientation.VERTICAL, true, true, false ); chart.getTitle().setFont( FONT ); chart.getLegend().setItemFont( SMALL_FONT ); final XYPlot plot = chart.getXYPlot(); plot.setRenderer( 0, pointRenderer ); plot.getRangeAxis().setLabelFont( FONT ); plot.getRangeAxis().setTickLabelFont( SMALL_FONT ); plot.getDomainAxis().setLabelFont( FONT ); plot.getDomainAxis().setTickLabelFont( SMALL_FONT ); pointRenderer.setUseOutlinePaint( true ); final int nseries = pointDataset.getSeriesCount(); for ( int i = 0; i < nseries; i++ ) pointRenderer.setSeriesOutlinePaint( i, Color.black ); pointRenderer.setSeriesLinesVisible( i, false ); pointRenderer.setSeriesShape( i, DEFAULT_SHAPE, false ); pointRenderer.setSeriesPaint( i, paints.getPaint( ( double ) i / nseries ), false );
XYSeriesCollection dataset2 = createXYDatasetGauss(horizontal); NumberAxis xAxis = new NumberAxis(getValueString()); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT); final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setBaseSeriesVisibleInLegend(false); for (int j = 0; j < dataset2.getSeriesCount(); j++) { XYSeries s = dataset2.getSeries(j); if (s.getKey().equals(groupName)) { renderer2.setSeriesPaint(j, c); renderer2.setSeriesShapesVisible(j, false); renderer2.setSeriesStroke(j, myStroke); renderer.setSeriesPaint(0, gp); renderer2.setSeriesPaint(0, c); renderer2.setSeriesShapesVisible(0, false); renderer2.setSeriesStroke(0, myStroke); chart.setTextAntiAlias(false); return chart;
renderer.setSeriesShapesVisible(0, true); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesItemLabelsVisible(0, true); renderer.setBaseItemLabelGenerator(new LabelGenerator()); renderer.setSeriesItemLabelsVisible(s + 1, true); renderer.setSeriesItemLabelsVisible(s + 2, true); renderer.setSeriesItemLabelsVisible(s + 3, true); renderer.setSeriesShapesVisible(s + 1, true); renderer.setSeriesShapesVisible(s + 2, true); renderer.setSeriesShapesVisible(s + 3, true); renderer.setSeriesLinesVisible(s + 1, true); renderer.setSeriesLinesVisible(s + 2, true); renderer.setSeriesLinesVisible(s + 3, true); renderer.setSeriesPaint(s + 1, paints[(i + 1) % paints.length]); renderer.setSeriesPaint(s + 2, paints[(i + 1) % paints.length]); renderer.setSeriesPaint(s + 3, paints[(i + 1) % paints.length]); renderer.setSeriesShape(s + 1, shapes[(i + 1) % shapes.length]); renderer.setSeriesShape(s + 2, shapes[(i + 1) % shapes.length]); renderer.setSeriesShape(s + 3, shapes[(i + 1) % shapes.length]); renderer.setSeriesStroke(s + 2, new BasicStroke(3)); renderer.setSeriesStroke(s + 3, new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[] { 5f, 5f }, 0));
private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createXYLineChart( chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); for (int i = 0; i < seriesList.size(); i++) { renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, true); plot.setRenderer(renderer); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
if (simVal>maxSimValue) maxSimValue=simVal; dataset0.addSeries(series); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setLinesVisible(false); renderer.setURLGenerator(url_gen); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesToolTipGenerator(0, tt_gen); renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0)); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setLinesVisible(false); renderer2.setSeriesPaint(0, Color.red); renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); dataset1.addSeries("f05x", new double[][] {{200.0, maxCountValue},{100.0, 0.5*maxCountValue}}); XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(); renderer3.setShapesVisible(false); renderer3.setSeriesPaint(0, Color.blue); renderer3.setSeriesPaint(1, Color.blue); renderer3.setSeriesPaint(2, Color.blue); renderer3.setBaseSeriesVisibleInLegend(false); renderer3.setSeriesItemLabelsVisible(0, true); renderer3.setSeriesItemLabelsVisible(1, false); renderer3.setSeriesItemLabelsVisible(2, false);
pop.add(++count, num.doubleValue()); dataset.addSeries(it.next()); NumberAxis xAxis = new NumberAxis(); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(getValueString()); yAxis.setAutoRangeIncludesZero(false); XYLineAndShapeRenderer renderer6 = new XYLineAndShapeRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer6); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeCrosshairVisible(true); plot.setDomainCrosshairVisible(true); renderer6.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); renderer6.setBaseSeriesVisibleInLegend(false); JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, isGrouping()); String groupName = it.next(); Color c = ChartCategories.getColor(i); for (int j = 0; j < dataset.getSeriesCount(); j++) { XYSeries s = dataset.getSeries(j); if (s.getKey().equals(groupName)) { renderer6.setSeriesPaint(j, c); renderer6.setSeriesPaint(0, ChartCategories.getColor(0));
final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0,true); renderer.setSeriesShapesVisible(0, true); final NumberAxis percentAxis = new NumberAxis(axisY); percentAxis.setInverted(false); percentAxis.setRange(0.0, 100.0); XYPlot plot = chart.getXYPlot(); plot.setDomainAxis(timeAxis); plot.setRangeAxis(percentAxis); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.gray); plot.setRangeZeroBaselinePaint(Color.gray); plot.setRenderer(renderer); chart.setBackgroundPaint(Color.white);
XYDataset dataset2 = createXYCurrentDataset(); XYLineAndShapeRenderer r1 = new XYLineAndShapeRenderer(); r1.setSeriesPaint(0, new Color(0xff, 0xff, 0x00)); r1.setSeriesPaint(1, new Color(0x00, 0xff, 0xff)); r1.setSeriesShapesVisible(0, false); r1.setSeriesShapesVisible(1, false); XYLineAndShapeRenderer r2 = new XYLineAndShapeRenderer(); r2.setSeriesPaint(0, new Color(0xff, 0x00, 0x00)); r2.setSeriesPaint(1, new Color(0x00, 0xff, 0x00)); r2.setSeriesShapesVisible(0, false); r2.setSeriesShapesVisible(1, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDataset(0, dataset1); plot.setRenderer(0, r1); plot.setDataset(1, dataset2); plot.setRenderer(1, r2); plot.setRangeAxis(1, new NumberAxis("Actual Current")); plot.mapDatasetToRangeAxis(1, 1); //2nd dataset to 2nd y-axi
XYPlot plot = new XYPlot(); plot.setDataset(0, scatterPlotDataset); plot.setRenderer(0, new XYLineAndShapeRenderer(false, true)); plot.setDomainAxis(0, new NumberAxis("Scatterplot domain")); plot.setRangeAxis(0, new NumberAxis("Scatterplot range")); plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); getFunctionDataset(0.8, 0.5, 1.2, minY, maxY); plot.setDataset(1, functionDataset); plot.setRenderer(1, new XYLineAndShapeRenderer(true, false)); Function2D p = new PolynomialFunction2D(a); XYSeries series = sampleFunctionOverY(p, minY, maxY, 100, "Function"); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); return dataset; double end, int samples, Comparable<?> seriesKey) XYSeries series = new XYSeries(seriesKey, false); double step = (end - start) / (samples - 1); for (int i = 0; i < samples; i++)
public static ChartHelper generateMultiLineChart(XYDataset dataset, String chartTitle, String yLabel, String xLabel, List domainMarkers) { boolean legend = true; boolean tooltips = true; boolean urls = true; JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, yLabel, xLabel, dataset, legend, tooltips, urls); chart.setBackgroundPaint(Color.WHITE); chart.setBorderVisible(false); XYPlot plot = chart.getXYPlot(); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); TickUnitSource units = NumberAxis.createIntegerTickUnits(); yAxis.setStandardTickUnits(units); if (domainMarkers != null && !domainMarkers.isEmpty()) { for (Iterator iterator = domainMarkers.iterator(); iterator.hasNext();) { ValueMarker valueMarker = (ValueMarker) iterator.next(); valueMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT); valueMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(valueMarker); } } XYItemRenderer plotRenderer = plot.getRenderer(); if (plotRenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plotRenderer; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } return new ChartHelper(chart); }
PlotOrientation.VERTICAL, true, false, false); final XYPlot plot = xylineChart.getXYPlot(); plot.setBackgroundPaint(new Color(240, 240, 240)); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setSeriesPaint(0, Color.BLACK); renderer.setSeriesStroke(0, new BasicStroke(4.0f)); plot.setRenderer(renderer); return xylineChart; final XYSeries seno = new XYSeries("Sin"); for (double i = 0; i <= 1440; i++) { double temp = Math.sin(i * ((2 * Math.PI) / 640) + Math.PI) + 1; seno.add(i / 60, temp); final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(seno); return dataset;
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); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); plot.setRenderer(renderer); 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]); LegendTitle legend = chart.getLegend(); Font legendFont = legend.getItemFont(); float legendFontSize = legendFont.getSize(); legend.setItemFont(newLegendFont); ValueAxis domainAxis = ((XYPlot) chart.getPlot()).getDomainAxis(); Font domainAxisLabelFont = domainAxis.getLabelFont(); float domainAxisLabelFontSize = domainAxisLabelFont.getSize();
XYSeries dataset = new XYSeries("Series"); for (int i = 0; i < tsData.length; i++) { dataset.add(i, (float) tsData[i]); chartXYSeriesCollection = new XYSeriesCollection(dataset); XYLineAndShapeRenderer xyRenderer = new XYLineAndShapeRenderer(true, false); xyRenderer.setSeriesPaint(0, new Color(0, 0, 0)); xyRenderer.setBaseStroke(new BasicStroke(3)); NumberAxis timeAxis = new NumberAxis("Time. (zoom: select with mouse; panning: Ctrl+mouse)"); NumberAxis valueAxis = new NumberAxis("Values"); valueAxis.setAutoRangeIncludesZero(false); this.timeseriesPlot = new XYPlot(chartXYSeriesCollection, timeAxis, valueAxis, xyRenderer); this.timeseriesPlot.setDomainPannable(true); this.timeseriesPlot.setRangePannable(true); this.chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, timeseriesPlot, false); this.chart.addProgressListener(this); this.chart.setNotify(true);