List of usage examples for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero
public void setAutoRangeIncludesZero(boolean flag)
From source file:domainhealth.frontend.graphics.JFreeChartGraphImpl.java
/** * Write a PNG image representation of the Graph to the given output * stream/*from w w w . ja va 2s. c o m*/ * * @param out The output stream to write the PNG bytes to * @throws IOException Indicates a problem writing to the output stream */ public void writeGraphImage(int numServersDisplayed, OutputStream out) throws IOException { ValueAxis xAxis = new DateAxis(MonitorProperties.units(DATE_TIME)); NumberAxis yAxis = new NumberAxis(yAxisUnits); yAxis.setAutoRangeIncludesZero(true); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot xyPlotLine = new XYPlot(xySeriesCollection, xAxis, yAxis, new StandardXYItemRenderer(StandardXYItemRenderer.LINES)); JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, xyPlotLine, true); chart.setBackgroundPaint(java.awt.Color.white); // Increase size of graph height to accommodate large legends for when many servers in the domain int graphAdditionalHeight = GRAPH_INCREMENT_HEIGHT * ((int) (numServersDisplayed / GRAPH_INCREMENT_SERVER_RATIO)); BufferedImage graphImage = chart.createBufferedImage(GRAPH_WIDTH, INITIAL_GRAPH_HEIGHT + graphAdditionalHeight, new ChartRenderingInfo(new StandardEntityCollection())); addNoDataLogoIfEmpty(graphImage); ChartUtilities.writeBufferedImageAsPNG(out, graphImage); // Could try extra two PNG related params: encodeAlpha and compression }
From source file:org.encog.workbench.tabs.visualize.scatter.ScatterPlotTab.java
private JPanel createPanel(int xIndex, int yIndex, boolean legend) { XYDataset dataset = new ScatterXY(file, xIndex, yIndex); JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, dataset, PlotOrientation.VERTICAL, legend, true, false);//from w w w . ja va 2s . com XYPlot plot = (XYPlot) chart.getPlot(); XYDotRenderer renderer = new XYDotRenderer(); renderer.setDotWidth(4); renderer.setDotHeight(4); if (this.file.isRegression()) { int per = 255 / 10; int r = 0; int b = 255; for (int i = 0; i < file.getSeriesCount(); i++) { renderer.setSeriesPaint(i, new Color(r, 0, b)); r += per; b -= per; } } else { for (int i = 0; i < file.getSeriesCount(); i++) { renderer.setSeriesPaint(i, COLORS[i % COLORS.length]); } } plot.setRenderer(renderer); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); plot.getRangeAxis().setInverted(false); ChartPanel result = new ChartPanel(chart); result.setBorder(BorderFactory.createLineBorder(Color.black)); // we need one to draw the legend off of if (this.samplePlot == null) this.samplePlot = plot; //chart.removeLegend(); return result; }
From source file:org.jfree.chart.demo.MultipleAxisDemo3.java
/** * Creates the demo chart.// www . ja v a2s . c om * * @return The chart. */ private JFreeChart createChart() { final XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day", "Primary Range Axis", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.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); plot.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT); // DOMAIN AXIS 3 final NumberAxis xAxis3 = new NumberAxis("Domain Axis 3"); xAxis2.setAutoRangeIncludesZero(false); plot.setDomainAxis(2, xAxis3); plot.setDomainAxisLocation(2, AxisLocation.BOTTOM_OR_LEFT); // RANGE AXIS 2 final NumberAxis yAxis2 = new NumberAxis("Range Axis 2"); plot.setRangeAxis(1, yAxis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); final XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170); plot.setDataset(1, dataset2); plot.mapDatasetToDomainAxis(1, 1); plot.mapDatasetToRangeAxis(1, 1); return chart; }
From source file:org.jfree.chart.demo.CyclicXYPlotDemo.java
/** * A demonstration application showing an XY plot, with a cyclic axis and renderer * * @param title the frame title.// w ww . jav a2s. com */ public CyclicXYPlotDemo(final String title) { super(title); this.series = new XYSeries("Random Data"); this.series.setMaximumItemCount(50); // Only 50 items are visible at the same time. // Keep more as a mean to test this. final XYSeriesCollection data = new XYSeriesCollection(this.series); final JFreeChart chart = ChartFactory.createXYLineChart("Cyclic XY Plot Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = chart.getXYPlot(); plot.setDomainAxis(new CyclicNumberAxis(10, 0)); plot.setRenderer(new CyclicXYItemRenderer()); final NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); axis.setAutoRangeMinimumSize(1.0); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(400, 300)); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel, BorderLayout.CENTER); final JButton button1 = new JButton("Start"); button1.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { timer.start(); } }); final JButton button2 = new JButton("Stop"); button2.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { timer.stop(); } }); final JButton button3 = new JButton("Step by step"); button3.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { CyclicXYPlotDemo.this.actionPerformed(null); } }); final JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); buttonPanel.add(button3); content.add(buttonPanel, BorderLayout.SOUTH); setContentPane(content); this.timer = new Timer(200, this); }
From source file:GeMSE.Visualization.BoxAndWhiskerPlot.java
private void Plot() { BoxAndWhiskerCategoryDataset dataset = CreateDataset(); CategoryAxis xAxis = new CategoryAxis("Type"); NumberAxis yAxis = new NumberAxis("Value"); yAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false);/*from w ww . jav a 2s . c o m*/ renderer.setArtifactPaint(Color.BLACK); renderer.setBaseOutlinePaint(Color.BLACK); renderer.setSeriesOutlinePaint(0, Color.BLACK); renderer.setSeriesPaint(0, Color.BLACK); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(new Color(0, 0, 0, 0)); JFreeChart chart = new JFreeChart(null, new Font("Courier New", Font.PLAIN, 10), plot, true); chart.removeLegend(); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(450, 270)); PlotPanel.setViewportView(chartPanel); }
From source file:org.jfree.chart.demo.SecondaryDatasetDemo1.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from w w w . java 2s. c o m */ public SecondaryDatasetDemo1(String title) { super(title); TimeSeriesCollection dataset1 = createRandomDataset("Series 1"); JFreeChart chart = ChartFactory.createTimeSeriesChart("Secondary Dataset Demo 1", "Time", "Value", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); this.plot = chart.getXYPlot(); this.plot.setBackgroundPaint(Color.lightGray); this.plot.setDomainGridlinePaint(Color.white); this.plot.setRangeGridlinePaint(Color.white); this.plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); ValueAxis axis = this.plot.getDomainAxis(); axis.setAutoRange(true); NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2"); rangeAxis2.setAutoRangeIncludesZero(false); JPanel content = new JPanel(new BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); JButton button1 = new JButton("Add Dataset"); button1.setActionCommand("ADD_DATASET"); button1.addActionListener(this); JButton button2 = new JButton("Remove Dataset"); button2.setActionCommand("REMOVE_DATASET"); button2.addActionListener(this); JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:org.interpss.chart.dstab.SimpleOneStateChart.java
/** * create the chart based on the data attributes * /*from ww w .j av a 2 s . c o m*/ */ public void createChart() { final JFreeChart chart = ChartFactory.createXYLineChart(plotTitle, xLabel, yLabel, createXYDataSet(xDataAry, yDataAry, yDataLabel), PlotOrientation.VERTICAL, true, false, false); final XYPlot plot = (XYPlot) chart.getPlot(); final StandardXYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(renderer); //NumberAxis axis_x = (NumberAxis) plot.getDomainAxis(); //axis_x.setRangeAboutValue(12.0, 24.0); final NumberAxis axisLeft = (NumberAxis) plot.getRangeAxis(); axisLeft.setAutoRangeIncludesZero(false); axisLeft.setAutoRangeMinimumSize(autoRangeMinimumSize); final XYItemRenderer v_renderer = plot.getRenderer(0); v_renderer.setSeriesPaint(0, yColor); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(Chart_Width, Chart_Height)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.MultipleDatasetDemo1.java
/** * Constructs a new demonstration application. * * @param title the frame title./*from w ww . j av a 2s . c o m*/ */ public MultipleDatasetDemo1(final String title) { super(title); final TimeSeriesCollection dataset1 = createRandomDataset("Series 1"); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Dataset Demo 1", "Time", "Value", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); this.plot = chart.getXYPlot(); this.plot.setBackgroundPaint(Color.lightGray); this.plot.setDomainGridlinePaint(Color.white); this.plot.setRangeGridlinePaint(Color.white); // this.plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); final ValueAxis axis = this.plot.getDomainAxis(); axis.setAutoRange(true); final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2"); rangeAxis2.setAutoRangeIncludesZero(false); final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JButton button1 = new JButton("Add Dataset"); button1.setActionCommand("ADD_DATASET"); button1.addActionListener(this); final JButton button2 = new JButton("Remove Dataset"); button2.setActionCommand("REMOVE_DATASET"); button2.addActionListener(this); final JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:org.drools.planner.benchmark.core.statistic.bestscore.BestScoreProblemStatistic.java
protected void writeGraphStatistic() { NumberAxis xAxis = new NumberAxis("Time spend"); xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat()); NumberAxis yAxis = new NumberAxis("Score"); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); int seriesIndex = 0; for (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) { BestScoreSingleStatistic singleStatistic = (BestScoreSingleStatistic) singleBenchmark .getSingleStatistic(problemStatisticType); XYSeries series = new XYSeries(singleBenchmark.getSolverBenchmark().getName()); for (BestScoreSingleStatisticPoint point : singleStatistic.getPointList()) { long timeMillisSpend = point.getTimeMillisSpend(); Score score = point.getScore(); Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score); if (scoreGraphValue != null) { series.add(timeMillisSpend, scoreGraphValue); }/* w ww . j av a 2 s . c om*/ } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series); plot.setDataset(seriesIndex, seriesCollection); XYItemRenderer renderer; // No direct lines between 2 points renderer = new XYStepRenderer(); if (singleStatistic.getPointList().size() <= 1) { // Workaround for https://sourceforge.net/tracker/?func=detail&aid=3387330&group_id=15494&atid=115494 renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES); } plot.setRenderer(seriesIndex, renderer); seriesIndex++; } plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(problemBenchmark.getName() + " best score statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); graphStatisticFile = new File(problemBenchmark.getProblemReportDirectory(), problemBenchmark.getName() + "BestScoreStatistic.png"); OutputStream out = null; try { out = new FileOutputStream(graphStatisticFile); ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e); } finally { IOUtils.closeQuietly(out); } }
From source file:org.jfree.chart.demo.SecondaryDatasetDemo2.java
/** * Constructs a new demonstration application. * * @param title the frame title./* w w w .j a v a 2 s . com*/ */ public SecondaryDatasetDemo2(final String title) { super(title); final CategoryDataset dataset1 = createRandomDataset("Series 1"); final JFreeChart chart = ChartFactory.createLineChart("Secondary Dataset Demo 2", "Category", "Value", dataset1, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); this.plot = chart.getCategoryPlot(); this.plot.setBackgroundPaint(Color.lightGray); this.plot.setDomainGridlinePaint(Color.white); this.plot.setRangeGridlinePaint(Color.white); // this.plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); final NumberAxis rangeAxis = (NumberAxis) this.plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false); final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JButton button1 = new JButton("Add Dataset"); button1.setActionCommand("ADD_DATASET"); button1.addActionListener(this); final JButton button2 = new JButton("Remove Dataset"); button2.setActionCommand("REMOVE_DATASET"); button2.addActionListener(this); final JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }