List of usage examples for org.jfree.chart.plot XYPlot setRangeAxis
public void setRangeAxis(ValueAxis axis)
From source file:org.nbheaven.sqe.codedefects.history.controlcenter.panels.SQEHistoryPanel.java
/** Creates new form SQEHistoryPanel */ public SQEHistoryPanel() { historyChart = org.jfree.chart.ChartFactory.createStackedXYAreaChart(null, "Snapshot", "CodeDefects", perProjectDataSet, PlotOrientation.VERTICAL, false, true, false); historyChart.setBackgroundPaint(Color.WHITE); historyChart.getXYPlot().setRangeGridlinePaint(Color.BLACK); historyChart.getXYPlot().setDomainGridlinePaint(Color.BLACK); historyChart.getXYPlot().setBackgroundPaint(Color.WHITE); XYPlot plot = historyChart.getXYPlot(); plot.setForegroundAlpha(0.7f);//from w ww. j ava 2s .com // plot.getRenderer(); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LogarithmicAxis rangeAxis = new LogarithmicAxis("CodeDefects"); rangeAxis.setStrictValuesFlag(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setRangeAxis(rangeAxis); StackedXYAreaRenderer2 categoryItemRenderer = new StackedXYAreaRenderer2(); //3D(); categoryItemRenderer.setSeriesPaint(0, Color.RED); categoryItemRenderer.setSeriesPaint(1, Color.ORANGE); categoryItemRenderer.setSeriesPaint(2, Color.YELLOW); plot.setRenderer(categoryItemRenderer); ChartPanel historyChartPanel = new ChartPanel(historyChart); historyChartPanel.setBorder(null); historyChartPanel.setPreferredSize(new Dimension(150, 200)); historyChartPanel.setBackground(Color.WHITE); initComponents(); historyView.setLayout(new BorderLayout()); historyView.add(historyChartPanel, BorderLayout.CENTER); JPanel selectorPanel = new JPanel(); selectorPanel.setOpaque(false); GroupLayout layout = new GroupLayout(selectorPanel); selectorPanel.setLayout(layout); // Turn on automatically adding gaps between components layout.setAutocreateGaps(true); // Turn on automatically creating gaps between components that touch // the edge of the container and the container. layout.setAutocreateContainerGaps(true); ParallelGroup horizontalParallelGroup = layout.createParallelGroup(GroupLayout.LEADING); SequentialGroup verticalSequentialGroup = layout.createSequentialGroup(); layout.setHorizontalGroup(layout.createSequentialGroup().add(horizontalParallelGroup)); layout.setVerticalGroup(verticalSequentialGroup); clearHistoryButton = new JButton(); clearHistoryButton.setEnabled(false); clearHistoryButton.setIcon(ImageUtilities .image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/codedefects/history/resources/trash.png"))); clearHistoryButton.setOpaque(false); clearHistoryButton.setFocusPainted(false); clearHistoryButton.setToolTipText( NbBundle.getBundle("org/nbheaven/sqe/codedefects/history/controlcenter/panels/Bundle") .getString("HINT_clear_button")); horizontalParallelGroup.add(clearHistoryButton); verticalSequentialGroup.add(clearHistoryButton); clearHistoryButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (null != activeHistory) { activeHistory.clear(); } } }); Component createVerticalStrut = Box.createVerticalStrut(10); horizontalParallelGroup.add(createVerticalStrut); verticalSequentialGroup.add(createVerticalStrut); for (final QualityProvider provider : SQEUtilities.getProviders()) { final JToggleButton providerButton = new JToggleButton(); providerButton.setIcon(provider.getIcon()); providerButton.setOpaque(false); providerButton.setFocusPainted(false); horizontalParallelGroup.add(providerButton); verticalSequentialGroup.add(providerButton); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { if (providerButton.isSelected()) { addSelectedProvider(provider); } else { removeSelectedProvider(provider); } updateView(); } }; providerButton.addActionListener(listener); addSelectedProvider(provider); providerButton.setSelected(true); } historyView.add(selectorPanel, BorderLayout.EAST); }
From source file:com.marvelution.jira.plugins.hudson.charts.BuildResultsRatioChartGenerator.java
/** * {@inheritDoc}/*from ww w . j a v a2 s. c o m*/ */ @Override public ChartHelper generateChart() { final Map<Integer, Build> buildMap = new HashMap<Integer, Build>(); final CategoryTableXYDataset dataSet = new CategoryTableXYDataset(); for (Build build : builds) { buildMap.put(Integer.valueOf(build.getBuildNumber()), build); dataSet.add(Double.valueOf(build.getBuildNumber()), Double.valueOf(build.getDuration()), getI18n().getText("hudson.charts.duration")); } final JFreeChart chart = ChartFactory.createXYBarChart("", "", false, getI18n().getText("hudson.charts.duration"), dataSet, PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(Color.WHITE); chart.setBorderVisible(false); final BuildResultRenderer renderer = new BuildResultRenderer(server, buildMap); renderer.setBaseItemLabelFont(ChartDefaults.defaultFont); renderer.setBaseItemLabelsVisible(false); renderer.setMargin(0.0D); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER)); renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); renderer.setBaseToolTipGenerator(renderer); renderer.setURLGenerator(renderer); final XYPlot xyPlot = chart.getXYPlot(); xyPlot.setAxisOffset(new RectangleInsets(1.0D, 1.0D, 1.0D, 1.0D)); xyPlot.setRenderer(renderer); final NumberAxis domainAxis = new NumberAxis(); domainAxis.setLowerBound(Collections.min(buildMap.keySet())); domainAxis.setUpperBound(Collections.max(buildMap.keySet())); final TickUnitSource ticks = NumberAxis.createIntegerTickUnits(); domainAxis.setStandardTickUnits(ticks); xyPlot.setDomainAxis(domainAxis); final DateAxis rangeAxis = new DateAxis(); final DurationFormat durationFormat = new DurationFormat(); rangeAxis.setDateFormatOverride(durationFormat); rangeAxis.setLabel(getI18n().getText("hudson.charts.duration")); xyPlot.setRangeAxis(rangeAxis); ChartUtil.setupPlot(xyPlot); return new ChartHelper(chart); }
From source file:org.jfree.chart.demo.CompassFormatDemo.java
/** * Creates a sample chart./*from w ww . j a v a 2 s .co m*/ * * @return a sample chart. */ private JFreeChart createChart() { final XYDataset direction = createDirectionDataset(600); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time", "Date", "Direction", direction, true, true, false); final XYPlot plot = chart.getXYPlot(); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setUpperMargin(0.0); // configure the range axis to display directions... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false); final TickUnits units = new TickUnits(); units.add(new NumberTickUnit(180.0, new CompassFormat())); units.add(new NumberTickUnit(90.0, new CompassFormat())); units.add(new NumberTickUnit(45.0, new CompassFormat())); units.add(new NumberTickUnit(22.5, new CompassFormat())); rangeAxis.setStandardTickUnits(units); // add the wind force with a secondary dataset/renderer/axis plot.setRangeAxis(rangeAxis); final XYItemRenderer renderer2 = new XYAreaRenderer(); final ValueAxis axis2 = new NumberAxis("Force"); axis2.setRange(0.0, 12.0); renderer2.setSeriesPaint(0, new Color(0, 0, 255, 128)); plot.setDataset(1, createForceDataset(600)); plot.setRenderer(1, renderer2); plot.setRangeAxis(1, axis2); plot.mapDatasetToRangeAxis(1, 1); return chart; }
From source file:edu.fullerton.viewerplugin.XYPlotter.java
private ChartPanel getPanel(double[][] data) throws WebUtilException { ChartPanel ret = null;/* w w w . j a v a 2 s . c om*/ try { XYSeries xys; XYSeriesCollection mtds = new XYSeriesCollection(); String mylegend = legend == null || legend.isEmpty() ? "series 1" : legend; xys = new XYSeries(legend); int len = data.length; double minx = Double.MAX_VALUE; double maxx = Double.MIN_VALUE; double miny = Double.MAX_VALUE; double maxy = Double.MIN_VALUE; boolean gotZeroX = false; boolean gotZeroY = false; for (int i = 0; i < len; i++) { double x = data[i][0]; double y = data[i][1]; if (x == 0) { gotZeroX = true; } else { minx = Math.min(minx, x); maxx = Math.max(maxx, x); } if (y == 0) { gotZeroY = true; } else { miny = Math.min(miny, y); maxy = Math.max(maxy, y); } } // this kludge lets us plot a 0 on a log axis double fakeZeroX = 0.; double fakeZeroY = 0.; if (gotZeroX) { if (logXaxis) { fakeZeroX = minx / 10; } else { minx = Math.min(0, minx); maxx = Math.max(0, maxx); } } if (gotZeroY) { if (logYaxis) { fakeZeroY = miny / 10; } else { miny = Math.min(0, miny); maxy = Math.max(0, maxy); } } for (int i = 0; i < len; i++) { double x = data[i][0]; double y = data[i][1]; x = x == 0 ? fakeZeroX : x; y = y == 0 ? fakeZeroY : y; xys.add(x, y); } mtds.addSeries(xys); DefaultXYDataset ds = new DefaultXYDataset(); int exp; if (maxy == 0. && miny == 0.) { miny = -1.; exp = 0; logYaxis = false; } else { maxy = maxy > miny ? maxy : miny * 10; exp = PluginSupport.scaleRange(mtds, miny, maxy); if (!logYaxis && exp > 0) { yLabel += " x 1e-" + Integer.toString(exp); } } JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, ds, PlotOrientation.VERTICAL, true, false, false); org.jfree.chart.plot.XYPlot plot = (org.jfree.chart.plot.XYPlot) chart.getPlot(); if (logYaxis) { LogAxis rangeAxis = new LogAxis(yLabel); double smallest = miny * Math.pow(10, exp); rangeAxis.setSmallestValue(smallest); rangeAxis.setMinorTickCount(9); LogAxisNumberFormat lanf = new LogAxisNumberFormat(); lanf.setExp(exp); rangeAxis.setNumberFormatOverride(lanf); rangeAxis.setRange(smallest, maxy * Math.pow(10, exp)); plot.setRangeAxis(rangeAxis); } if (logXaxis) { LogAxis domainAxis = new LogAxis(xLabel); domainAxis.setMinorTickCount(9); domainAxis.setSmallestValue(minx); domainAxis.setNumberFormatOverride(new LogAxisNumberFormat()); plot.setDomainAxis(domainAxis); } ValueAxis domainAxis = plot.getDomainAxis(); if (fmin != null && fmin > 0) { domainAxis.setLowerBound(fmin); } if (fmax != null && fmax > 0) { domainAxis.setUpperBound(fmax); } plot.setDomainAxis(domainAxis); plot.setDataset(0, mtds); // Set the line thickness XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer(); BasicStroke str = new BasicStroke(lineThickness); int n = plot.getSeriesCount(); for (int i = 0; i < n; i++) { r.setSeriesStroke(i, str); } if (legend == null || legend.isEmpty()) { chart.removeLegend(); } ret = new ChartPanel(chart); } catch (Exception ex) { throw new WebUtilException("Creating spectrum plot" + ex.getLocalizedMessage()); } return ret; }
From source file:org.jfree.chart.demo.XYTickLabelDemo.java
/** * Creates the demo chart.// w w w .j av a 2 s. com * * @return The chart. */ private JFreeChart createChart() { // create some sample data final XYSeries series1 = new XYSeries("Something"); series1.add(0.0, 30.0); series1.add(1.0, 10.0); series1.add(2.0, 40.0); series1.add(3.0, 30.0); series1.add(4.0, 50.0); series1.add(5.0, 50.0); series1.add(6.0, 70.0); series1.add(7.0, 70.0); series1.add(8.0, 80.0); final XYSeriesCollection dataset1 = new XYSeriesCollection(); dataset1.addSeries(series1); final XYSeries series2 = new XYSeries("Something else"); series2.add(0.0, 5.0); series2.add(1.0, 4.0); series2.add(2.0, 1.0); series2.add(3.0, 5.0); series2.add(4.0, 0.0); final XYSeriesCollection dataset2 = new XYSeriesCollection(); dataset2.addSeries(series2); // create the chart final JFreeChart result = ChartFactory.createXYLineChart("Tick Label Demo", "Domain Axis 1", "Range Axis 1", dataset1, PlotOrientation.VERTICAL, false, true, false); result.setBackgroundPaint(Color.white); final XYPlot plot = result.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setPaint(Color.black); // DOMAIN AXIS 2 final NumberAxis xAxis2 = new NumberAxis("Domain Axis 2"); xAxis2.setAutoRangeIncludesZero(false); plot.setDomainAxis(1, xAxis2); // RANGE AXIS 2 final DateAxis yAxis1 = new DateAxis("Range Axis 1"); plot.setRangeAxis(yAxis1); final DateAxis yAxis2 = new DateAxis("Range Axis 2"); plot.setRangeAxis(1, yAxis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, dataset2); plot.mapDatasetToDomainAxis(1, 1); plot.mapDatasetToRangeAxis(1, 1); return result; }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a stacked XY area plot. The chart object returned by this * method uses an {@link XYPlot} instance as the plot, with a * {@link NumberAxis} for the domain axis, a {@link NumberAxis} as the * range axis, and a {@link StackedXYAreaRenderer2} as the renderer. * /* w w w . j a va2s .c o m*/ * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A stacked XY area chart. */ public static JFreeChart createStackedXYAreaChart(String title, String xAxisLabel, String yAxisLabel, TableXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(toolTipGenerator, urlGenerator); renderer.setOutline(true); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); plot.setRangeAxis(yAxis); // forces recalculation of the axis range JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:gui.DendrogramChart.java
ChartPanel getChartPanel(Dendrogram d, boolean log) { JFreeChart chart = ChartFactory.createXYLineChart(null, "Similarity", "No. of Groups", null, PlotOrientation.VERTICAL, true, true, false); setChartData(chart, log);/*from w w w .jav a2 s .c om*/ RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); chart.setRenderingHints(rh); chart.removeLegend(); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(new Color(255, 255, 220)); plot.setDomainGridlinePaint(new Color(128, 128, 128)); plot.setRangeGridlinePaint(new Color(128, 128, 128)); if (log == false) { NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0); rangeAxis.setNumberFormatOverride(new DecimalFormat("0")); rangeAxis.setLabelFont(Prefs.labelFont); } else { // LogarithmicAxis logXAxis = new LogarithmicAxis("Similarity"); // logXAxis.setAllowNegativesFlag(true); LogarithmicAxis logYAxis = new LogarithmicAxis("No. Of Groups"); logYAxis.setAllowNegativesFlag(false); // plot.setDomainAxis(logXAxis); plot.setRangeAxis(logYAxis); } ChartPanel chartPanel = new ChartPanel(chart); // chartPanel.setPopupMenu(null); return chartPanel; }
From source file:org.projectforge.statistics.TimesheetDisciplineChartBuilder.java
private JFreeChart create(final TimeSeries series1, final TimeSeries series2, final Shape shape, final Stroke stroke, final boolean showAxisValues, final String valueAxisUnitKey) { final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series1);// ww w. j av a2s . com dataset.addSeries(series2); final JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL, true, true, false); final XYDifferenceRenderer renderer = new XYDifferenceRenderer(new Color(238, 176, 176), new Color(135, 206, 112), true); renderer.setSeriesPaint(0, new Color(222, 23, 33)); renderer.setSeriesPaint(1, new Color(64, 169, 59)); if (shape != null) { renderer.setSeriesShape(0, shape); renderer.setSeriesShape(1, shape); } else { final Shape none = new Rectangle(); renderer.setSeriesShape(0, none); renderer.setSeriesShape(1, none); } renderer.setSeriesStroke(0, stroke); renderer.setSeriesStroke(1, stroke); renderer.setSeriesVisibleInLegend(0, false); renderer.setSeriesVisibleInLegend(1, false); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); final DateAxis xAxis = new DateAxis(); xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); xAxis.setVisible(showAxisValues); plot.setDomainAxis(xAxis); final NumberAxis yAxis; if (showAxisValues == true) { yAxis = new NumberAxis(PFUserContext.getLocalizedString(valueAxisUnitKey)); } else { yAxis = new NumberAxis(); } yAxis.setVisible(showAxisValues); plot.setRangeAxis(yAxis); plot.setOutlineVisible(false); return chart; }
From source file:net.sf.maltcms.chromaui.foldChangeViewer.tasks.FoldChangeViewLoaderWorker.java
private void configurePlot(XYPlot plot, RTUnit rtAxisUnit) { NumberAxis domainAxis = null;/*from w w w . j a va 2 s . c om*/ if (plot.getDomainAxis() == null) { domainAxis = new NumberAxis("log2 fold change"); plot.setDomainAxis(domainAxis); } else { domainAxis = (NumberAxis) plot.getDomainAxis(); } // domainAxis.setNumberFormatOverride(new RTNumberFormatter(rtAxisUnit)); // domainAxis.setLabel("RT[" + rtAxisUnit.name().toLowerCase() + "]"); plot.setRangeZeroBaselineVisible(true); plot.setDomainZeroBaselineVisible(true); domainAxis.setAutoRange(true); domainAxis.setAutoRangeIncludesZero(false); NumberAxis rangeAxis = null; if (plot.getRangeAxis() == null) { rangeAxis = new NumberAxis("-log10 p-value"); plot.setRangeAxis(rangeAxis); } else { rangeAxis = (NumberAxis) plot.getRangeAxis(); } rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(true); Logger.getLogger(getClass().getName()).info("Adding chart"); plot.setBackgroundPaint(Color.WHITE); ChartCustomizer.setSeriesColors(plot, 0.8f); }
From source file:net.sourceforge.processdash.ui.web.psp.TimeLogPhaseWaterfallChart.java
private JFreeChart createChart(IntervalXYDataset dataset, ProcessUtil process, List<String> phases, GapSkipTracker gaps) {/*from ww w. ja va 2s .com*/ JFreeChart result = ChartFactory.createXYBarChart(null, null, true, null, dataset, PlotOrientation.VERTICAL, false, true, false); XYPlot xyplot = (XYPlot) result.getPlot(); DateAxis dateAxis = new DateAxis(null); dateAxis.setTickMarksVisible(false); dateAxis.setTickLabelsVisible(false); dateAxis.setLowerMargin(0.01); dateAxis.setUpperMargin(0.01); setupGaps(gaps, dateAxis, xyplot); xyplot.setDomainAxis(dateAxis); String[] phaseNameList = new String[phases.size()]; for (int i = 0; i < phaseNameList.length; i++) phaseNameList[i] = Translator.translate(phases.get(i)); SymbolAxis symbolaxis = new SymbolAxis(null, phaseNameList); symbolaxis.setGridBandsVisible(false); xyplot.setRangeAxis(symbolaxis); final XYBarRenderer renderer = (XYBarRenderer) xyplot.getRenderer(); renderer.setUseYInterval(true); renderer.setDrawBarOutline(true); renderer.setBaseOutlinePaint(Color.black); new PhaseChartColorer(process, phases) { public void setItemColor(Object key, int pos, Color c) { renderer.setSeriesPaint(pos, c); } }.run(); int exceptionSeries = dataset.getSeriesCount() - 1; renderer.setSeriesPaint(exceptionSeries, EXCEPTION_PAINT); renderer.setSeriesFillPaint(exceptionSeries, EXCEPTION_PAINT); renderer.setSeriesOutlinePaint(exceptionSeries, EXCEPTION_PAINT); renderer.setBaseToolTipGenerator(new TooltipGenerator()); xyplot.setBackgroundPaint(Color.white); xyplot.setDomainGridlinesVisible(false); xyplot.setRangeGridlinePaint(Color.lightGray); xyplot.setDrawingSupplier(DRAWING_SUPPLIER_FACTORY.newDrawingSupplier()); result.setAntiAlias(false); result.setTextAntiAlias(true); parameters.put("title", resources.getString("Title")); return result; }