List of usage examples for org.jfree.chart.plot XYPlot XYPlot
public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer)
From source file:org.optaplanner.benchmark.impl.statistic.calculatecount.CalculateCountProblemStatistic.java
@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("Calculate count 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.isSuccess()) { CalculateCountSingleStatistic singleStatistic = (CalculateCountSingleStatistic) singleBenchmarkResult .getSingleStatistic(problemStatisticType); for (CalculateCountStatisticPoint point : singleStatistic.getPointList()) { long timeMillisSpent = point.getTimeMillisSpent(); long calculateCountPerSecond = point.getCalculateCountPerSecond(); series.add(timeMillisSpent, calculateCountPerSecond); }/*from w w w. j a v a2 s .c om*/ } plot.setDataset(seriesIndex, new XYSeriesCollection(series)); if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) { // Make the favorite more obvious renderer.setSeriesStroke(0, new BasicStroke(2.0f)); } plot.setRenderer(seriesIndex, renderer); seriesIndex++; } JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " calculate count statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "CalculateCountStatistic"); }
From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.adap3decompositionV1_5.SimpleScatterPlot.java
public SimpleScatterPlot(double[] xValues, double[] yValues, double[] colors, String xLabel, String yLabel) { super(null, true); setBackground(Color.white);//ww w .j a v a 2 s . c o m setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); xAxis = new NumberAxis(xLabel); xAxis.setAutoRangeIncludesZero(false); xAxis.setUpperMargin(0); xAxis.setLowerMargin(0); yAxis = new NumberAxis(yLabel); yAxis.setAutoRangeIncludesZero(false); yAxis.setUpperMargin(0); yAxis.setLowerMargin(0); xyDataset = new DefaultXYZDataset(); int length = Math.min(xValues.length, yValues.length); double[][] data = new double[3][length]; System.arraycopy(xValues, 0, data[0], 0, length); System.arraycopy(yValues, 0, data[1], 0, length); System.arraycopy(colors, 0, data[2], 0, length); xyDataset.addSeries(SERIES_ID, data); XYDotRenderer renderer = new XYDotRenderer() { @Override public Paint getItemPaint(int row, int col) { double c = xyDataset.getZ(row, col).doubleValue(); return Color.getHSBColor((float) c, 1.0f, 1.0f); } }; renderer.setDotHeight(3); renderer.setDotWidth(3); plot = new XYPlot(xyDataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 12), plot, false); chart.setBackgroundPaint(Color.white); super.setChart(chart); }
From source file:sernet.gs.ui.rcp.main.bsi.views.chart.RealisierungLineChart.java
private JFreeChart createProgressChart(Object dataset) { final double plotGap = 10.0; final int axisUpperBoundPadding = 50; final int labelFontSize = 10; XYDataset data1 = (XYDataset) dataset; XYItemRenderer renderer1 = new StandardXYItemRenderer(); NumberAxis rangeAxis1 = new NumberAxis(Messages.RealisierungLineChart_1); XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis(Messages.RealisierungLineChart_2)); plot.setGap(plotGap);//from w w w.j a v a2s.c om plot.add(subplot1, 1); plot.setOrientation(PlotOrientation.VERTICAL); CountMassnahmen command = new CountMassnahmen(); try { command = ServiceFactory.lookupCommandService().executeCommand(command); } catch (CommandException e) { ExceptionUtil.log(e, Messages.RealisierungLineChart_3); } int totalNum = command.getTotalCount(); NumberAxis axis = (NumberAxis) subplot1.getRangeAxis(); axis.setUpperBound(totalNum + axisUpperBoundPadding); ValueMarker bst = new ValueMarker(totalNum); bst.setPaint(Color.GREEN); bst.setLabel(Messages.RealisierungLineChart_4); bst.setLabelAnchor(RectangleAnchor.LEFT); bst.setLabelFont(new Font("SansSerif", Font.ITALIC + Font.BOLD, labelFontSize)); //$NON-NLS-1$ bst.setLabelTextAnchor(TextAnchor.CENTER_LEFT); subplot1.addRangeMarker(bst, Layer.BACKGROUND); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart(Messages.RealisierungLineChart_6, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.white); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.SymbolAxisDemo1.java
protected JFreeChart createChart(XYDataset dataset) { SymbolAxis domainAxis = new SymbolAxis("Domain", new String[] { "A", "B", "C", "D" }); SymbolAxis rangeAxis = new SymbolAxis("Range", new String[] { "V", "X", "Y", "Z" }); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); if (!legendPanelOn) renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(chartTitle, plot); setXSummary(dataset);//from w ww.ja va 2s . c om if (legendPanelOn) chart.removeLegend(); return chart; }
From source file:com.itemanalysis.jmetrik.graph.itemmap.ItemMapPanel.java
public void setGraph() { HistogramChartDataset personDataset = null; HistogramChartDataset itemData = null; try {/*ww w .j a va 2 s.co m*/ //get titles String chartTitle = command.getFreeOption("title").getString(); String chartSubtitle = command.getFreeOption("subtitle").getString(); PlotOrientation itemMapOrientation = PlotOrientation.HORIZONTAL; //create common x-axis NumberAxis domainAxis = new NumberAxis(); domainAxis.setLabel("Logits"); //create histogram personDataset = new HistogramChartDataset(); ValueAxis rangeAxis = new NumberAxis("Person Density"); if (itemMapOrientation == PlotOrientation.HORIZONTAL) rangeAxis.setInverted(true); XYBarRenderer renderer = new XYBarRenderer(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setURLGenerator(new StandardXYURLGenerator()); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); XYPlot personPlot = new XYPlot(personDataset, null, rangeAxis, renderer); personPlot.setOrientation(PlotOrientation.HORIZONTAL); //create scatterplot of item difficulty itemData = new HistogramChartDataset(); NumberAxis itemRangeAxis = new NumberAxis("Item Frequency"); if (itemMapOrientation == PlotOrientation.VERTICAL) { itemRangeAxis.setInverted(true); } XYBarRenderer itemRenderer = new XYBarRenderer(); itemRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); itemRenderer.setURLGenerator(new StandardXYURLGenerator()); itemRenderer.setDrawBarOutline(true); itemRenderer.setShadowVisible(false); XYPlot itemPlot = new XYPlot(itemData, null, itemRangeAxis, itemRenderer); itemPlot.setOrientation(PlotOrientation.HORIZONTAL); //combine the two charts CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis); cplot.add(personPlot, 3); cplot.add(itemPlot, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); cplot.setOrientation(itemMapOrientation); // //next four lines are temp setting for book // //these four lines will create a histogram with white bars so it appears as just the bar outline // renderer.setBarPainter(new StandardXYBarPainter()); // renderer.setSeriesPaint(0, Color.white); // itemRenderer.setBarPainter(new StandardXYBarPainter()); // itemRenderer.setSeriesPaint(0, Color.white); chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, cplot, false); chart.setBackgroundPaint(Color.white); if (chartSubtitle != null && !"".equals(chartSubtitle)) { chart.addSubtitle(new TextTitle(chartSubtitle)); } ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(this, panel.getPopupMenu()); panel.setPreferredSize(new Dimension(width, height)); // //temp setting for book // this.addLocalEPSMenuItem(this, panel.getPopupMenu(), chart);//remove this line for public release versions chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); this.setBackground(Color.WHITE); this.add(panel); } catch (IllegalArgumentException ex) { logger.fatal(ex.getMessage(), ex); this.firePropertyChange("error", "", "Error - Check log for details."); } }
From source file:org.optaplanner.benchmark.impl.statistic.bestsolutionmutation.BestSolutionMutationProblemStatistic.java
@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("Best solution mutation count"); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); yAxis.setAutoRangeIncludesZero(true); 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.isSuccess()) { BestSolutionMutationSingleStatistic singleStatistic = (BestSolutionMutationSingleStatistic) singleBenchmarkResult .getSingleStatistic(problemStatisticType); for (BestSolutionMutationStatisticPoint point : singleStatistic.getPointList()) { long timeMillisSpent = point.getTimeMillisSpent(); long mutationCount = point.getMutationCount(); series.add(timeMillisSpent, mutationCount); }/* ww w.j a v a2s. c o m*/ } plot.setDataset(seriesIndex, new XYSeriesCollection(series)); if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) { // Make the favorite more obvious renderer.setSeriesStroke(0, new BasicStroke(2.0f)); } plot.setRenderer(seriesIndex, renderer); seriesIndex++; } JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " best solution mutation statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "BestSolutionMutationStatistic"); }
From source file:ChartUsingJava.CombinedXYPlotDemo1.java
/** * Creates an overlaid chart./*from w ww.java 2 s.c om*/ * * @return The chart. */ private static JFreeChart createCombinedChart() { // create plot ... IntervalXYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); renderer1.setSeriesStroke(0, new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesPaint(0, Color.blue); DateAxis domainAxis = new DateAxis("Year"); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.02); ValueAxis rangeAxis = new NumberAxis("$billion"); XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); // add a second dataset and renderer... IntervalXYDataset data2 = createDataset2(); XYBarRenderer renderer2 = new XYBarRenderer() { public Paint getItemPaint(int series, int item) { XYDataset dataset = getPlot().getDataset(); if (dataset.getYValue(series, item) >= 0.0) { return Color.red; } else { return Color.green; } } }; renderer2.setSeriesPaint(0, Color.red); renderer2.setDrawBarOutline(false); renderer2.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"), renderer2); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); CombinedXYPlot cplot = new CombinedXYPlot(domainAxis, rangeAxis); cplot.add(plot1, 3); cplot.add(plot2, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart("CombinedXYPlotDemo1", JFreeChart.DEFAULT_TITLE_FONT, cplot, false); chart.setBackgroundPaint(Color.white); LegendTitle legend = new LegendTitle(cplot); chart.addSubtitle(legend); return chart; }
From source file:br.prof.salesfilho.oci.image.GraphicBuilder.java
public void createCombinedChart(Map<String, double[]> mapSeries, String legendTitle) { XYSeriesCollection xds;/* w w w. jav a 2s. c o m*/ final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis(legendTitle)); plot.setGap(10.0); for (Map.Entry<String, double[]> entrySet : mapSeries.entrySet()) { String serieName = entrySet.getKey(); double[] values = entrySet.getValue(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); final XYSeries series = new XYSeries(serieName); for (int i = 0; i < values.length; i++) { series.add(i, Precision.round(values[i], 2)); renderer.setSeriesVisible(i, true, true); renderer.setSeriesShapesVisible(i, true); } xds = new XYSeriesCollection(); xds.addSeries(series); final NumberAxis rangeAxis = new NumberAxis(serieName); final XYPlot subplot = new XYPlot(xds, null, rangeAxis, renderer); subplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); plot.add(subplot); } this.chart = new JFreeChart(this.title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chartPanel.setChart(chart); }
From source file:playground.yu.utils.charts.TimeScatterChart.java
private JFreeChart createChart(String title, String timeAxisLabel, String valueAxisLabel, final TimeTableXYDataset dataset) { ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02);/*from w ww . j a v a 2 s . c o m*/ NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; boolean tooltips = false; if (tooltips) { toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); } XYURLGenerator urlGenerator = null; boolean urls = false; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); boolean legend = true; JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; // return ChartFactory.createTimeSeriesChart(title, timeAxisLabel, // valueAxisLabel, dataset, true, // legend? // false, // tooltips? // false // URLs? // ); }
From source file:playground.yu.utils.charts.TimeLineChart.java
private JFreeChart createChart(String title, String timeAxisLabel, String valueAxisLabel, final TimeTableXYDataset dataset) { ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02);/*from ww w . j a v a 2s . c o m*/ NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; boolean tooltips = false; if (tooltips) { toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); } XYURLGenerator urlGenerator = null; boolean urls = false; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true/* line */, false/* shape */); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); boolean legend = true; JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }