List of usage examples for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero
public void setAutoRangeIncludesZero(boolean flag)
From source file:org.geoserver.monitor.web.ActivityChartBasePanel.java
JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset) { ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02);//from w w w .java 2 s. co m NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); plot.setRenderer(renderer); JFreeChart chart = new JFreeChart(plot); //TextTitle t = new TextTitle(title); //t.setTextAlignment(HorizontalAlignment.LEFT); //chart.setTitle(t); chart.setBackgroundPaint(Color.WHITE); chart.setAntiAlias(true); chart.clearSubtitles(); return chart; }
From source file:chart.JChart.java
/** * Creates a sample chart.//from w w w. ja v a 2 s. c o m * * @param dataset the dataset. * * @return A sample chart. */ private JFreeChart createChart(final XYDataset dataset, List<NSubsequence> anomalies) { final JFreeChart chart = ChartFactory.createXYLineChart("Test", "Time", "Value", dataset, PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(Color.WHITE); // final StandardLegend sl = (StandardLegend) chart.getLegend(); // sl.setDisplaySeriesShapes(true); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); // plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); // final XYItemRenderer renderer = plot.getRenderer(); MyRender renderer = new MyRender(dataset, anomalies); plot.setRenderer(renderer); renderer.setSeriesShapesVisible(0, false); chart.setBackgroundPaint(Color.white); // DateAxis axis = (DateAxis) plot.getDomainAxis(); // axis.setDateFormatOverride(new SimpleDateFormat("S")); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setAutoRangeIncludesZero(false); return chart; }
From source file:org.jfree.chart.demo.SegmentedHighLowChartDemo.java
/** * A demonstration application showing a high-low-open-close chart using a * segmented or non-segmented axis.// w ww . j a v a 2 s . c om * * @param title the frame title. * @param useSegmentedAxis use a segmented axis for this demo? * @param timelineType Type of timeline to use: 1=Monday through Friday, 2=Intraday */ public SegmentedHighLowChartDemo(final String title, final boolean useSegmentedAxis, final int timelineType) { super(title); System.out.println("\nMaking SegmentedHighLowChartDemo(" + title + ")"); // create a Calendar object with today's date at midnight final Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); // create a timeline for the demo SegmentedTimeline timeline = null; switch (timelineType) { case 1: timeline = SegmentedTimeline.newMondayThroughFridayTimeline(); break; case 2: timeline = SegmentedTimeline.newFifteenMinuteTimeline(); final Calendar cal2 = (Calendar) cal.clone(); cal2.add(Calendar.YEAR, 1); // add 1 year of baseTimeline's excluded segments (Saturdays and Sundays) as // exceptions of the intraday timeline timeline.addBaseTimelineExclusions(cal.getTime().getTime(), cal2.getTime().getTime()); break; default: System.out.println("Invalid timelineType."); System.exit(1); } // create a data set that has data for trading days (Monday through Friday). final DefaultHighLowDataset dataset = DemoDatasetFactory.createSegmentedHighLowDataset(timeline, cal.getTime()); final JFreeChart chart; if (useSegmentedAxis) { chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, timeline, true); } else { chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, true); } final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis(); axis.setAutoRange(true); final TickUnits units = new TickUnits(); units.add(new DateTickUnit(DateTickUnit.DAY, 1, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM"))); units.add(new DateTickUnit(DateTickUnit.DAY, 2, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM"))); units.add(new DateTickUnit(DateTickUnit.DAY, 7, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM"))); units.add(new DateTickUnit(DateTickUnit.DAY, 15, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM"))); units.add(new DateTickUnit(DateTickUnit.DAY, 30, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM"))); axis.setStandardTickUnits(units); final NumberAxis vaxis = (NumberAxis) chart.getXYPlot().getRangeAxis(); vaxis.setAutoRangeIncludesZero(false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:org.ow2.clif.jenkins.chart.FixedSliceSizeDistributionChart.java
@Override protected JFreeChart createChart() { JFreeChart chart = ChartFactory.createHistogram(getBasicTitle(), Messages.FixedSliceSizeDistributionChart_ResponseTime(), Messages.FixedSliceSizeDistributionChart_NumberOfCalls(), data, PlotOrientation.VERTICAL, true, true, false);//from ww w .j av a2 s . c o m if (data.getSeriesCount() != 0 && data.getItemCount(0) > 0) { double rangeStart = data.getStartX(0, 0).doubleValue(); double rangeEnd = data.getEndX(0, data.getItemCount(0) - 1).doubleValue(); NumberAxis domainAxis = new HistogramAxis(data, 0); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setVerticalTickLabels(true); domainAxis.setTickLabelsVisible(true); domainAxis.setTickMarksVisible(true); domainAxis.setRange(rangeStart, rangeEnd); chart.getXYPlot().setDomainAxis(domainAxis); NumberAxis rangeAxis = (NumberAxis) chart.getXYPlot().getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(true); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } chart.getXYPlot().setRangeGridlinesVisible(true); chart.getXYPlot().setDomainGridlinesVisible(false); return chart; }
From source file:org.jreserve.gui.calculations.factor.editor.AccidentFactorPlot.java
private Component createPlotComponent() { boolean legend = true; boolean tooltips = false; boolean urls = false; chart = ChartFactory.createLineChart(null, null, null, dataSet, PlotOrientation.VERTICAL, legend, tooltips, urls);// ww w .j a v a 2s .c o m CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.GRAY); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.WHITE); plot.setDomainGridlinePaint(Color.WHITE); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); axis.setAutoRangeStickyZero(true); renderer = plot.getRenderer(); if (renderer instanceof LineAndShapeRenderer) { LineAndShapeRenderer lasr = (LineAndShapeRenderer) renderer; lasr.setBaseShapesVisible(true); lasr.setDrawOutlines(true); lasr.setUseFillPaint(true); lasr.setBaseStroke(new BasicStroke(2)); ColorGenerator colors = new DefaultColorGenerator(); int count = dataSet.getRowCount(); int r = 3; Shape circle = new Ellipse2D.Float(-r, -r, 2 * r, 2 * r); for (int i = 0; i < count; i++) { Paint color = colors.nextColor(); lasr.setSeriesPaint(i, color); lasr.setSeriesFillPaint(i, color); lasr.setSeriesShape(i, circle); } } return new ChartPanel(chart); }
From source file:guineu.modules.filter.report.RTShift.ReportTask.java
/** * Create the chart and save it into a png file. * @param dataset/*from w w w . j av a 2s .c om*/ * @param lipidName */ private void createChart(CategoryDataset dataset, String lipidName) { try { JFreeChart chart = ChartFactory.createLineChart("RT shift", "Samples", "RT", dataset, PlotOrientation.VERTICAL, false, false, false); // Chart characteristics CategoryPlot plot = (CategoryPlot) chart.getPlot(); final NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); axis.setAutoRangeMinimumSize(1.0); LineAndShapeRenderer categoryRenderer = new LineAndShapeRenderer(); categoryRenderer.setSeriesLinesVisible(0, false); categoryRenderer.setSeriesShapesVisible(0, true); plot.setRenderer(categoryRenderer); // Save all the charts in the folder choosen by the user ChartUtilities.saveChartAsPNG(new File(this.reportFileName + "/RT Shift:" + lipidName + ".png"), chart, 1000, (500)); } catch (IOException ex) { Logger.getLogger(ReportTask.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.bt.aloha.batchtest.Chart.java
private JFreeChart createChart(XYDataset xydataset, String title, String xLabel, String yLabel) { JFreeChart jfreechart = ChartFactory.createXYLineChart(title, xLabel, yLabel, xydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); if (xydataset instanceof IntervalXYDataset) { DeviationRenderer deviationrenderer = new DeviationRenderer(true, true); deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); deviationrenderer.setSeriesFillPaint(0, new Color(255, 200, 200)); xyplot.setRenderer(deviationrenderer); }// w w w. j a v a 2s.c o m NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); numberaxis.setAutoRange(true); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return jfreechart; }
From source file:net.pickapack.chart.LinePlotFrame.java
/** * Create a line plot frame./*from www. jav a 2 s . c om*/ * * @param linePlot the line plot * @param width the width * @param height the height */ public LinePlotFrame(LinePlot linePlot, int width, int height) { super(linePlot.getTitle()); this.linePlot = linePlot; this.numSubPlots = linePlot.getSubLinePlots().size(); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time")); this.dataSets = new ArrayList<TimeSeriesCollection>(); this.dataSinks = new ArrayList<Map<SubLinePlotLine, Function<Double>>>(); for (SubLinePlot subLinePlot : linePlot.getSubLinePlots()) { TimeSeriesCollection dataSetsPerSubPlot = new TimeSeriesCollection(); this.dataSets.add(dataSetsPerSubPlot); HashMap<SubLinePlotLine, Function<Double>> dataSinksPerSubPlot = new HashMap<SubLinePlotLine, Function<Double>>(); this.dataSinks.add(dataSinksPerSubPlot); for (SubLinePlotLine subLinePlotLine : subLinePlot.getLines()) { TimeSeries timeSeries = new TimeSeries(subLinePlotLine.getTitle()); dataSetsPerSubPlot.addSeries(timeSeries); dataSinksPerSubPlot.put(subLinePlotLine, subLinePlotLine.getGetValueCallback()); } NumberAxis rangeAxis = new NumberAxis(subLinePlot.getTitleY()); rangeAxis.setAutoRangeIncludesZero(false); XYPlot subplot = new XYPlot(dataSetsPerSubPlot, null, rangeAxis, new StandardXYItemRenderer()); subplot.setBackgroundPaint(Color.lightGray); subplot.setDomainGridlinePaint(Color.white); subplot.setRangeGridlinePaint(Color.white); plot.add(subplot); } JFreeChart chart = new JFreeChart(linePlot.getTitle(), plot); chart.setBorderPaint(Color.black); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(3600000.0); JPanel content = new JPanel(new BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(width, height)); chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setContentPane(content); DataSink dataSink = new DataSink(); new Thread(dataSink).start(); }
From source file:org.jfree.chart.demo.DynamicDataDemo3.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from w w w. j a v a 2s . c om */ public DynamicDataDemo3(final String title) { super(title); final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time")); this.datasets = new TimeSeriesCollection[SUBPLOT_COUNT]; for (int i = 0; i < SUBPLOT_COUNT; i++) { this.lastValue[i] = 100.0; final TimeSeries series = new TimeSeries("Random " + i, Millisecond.class); this.datasets[i] = new TimeSeriesCollection(series); final NumberAxis rangeAxis = new NumberAxis("Y" + i); rangeAxis.setAutoRangeIncludesZero(false); final XYPlot subplot = new XYPlot(this.datasets[i], null, rangeAxis, new StandardXYItemRenderer()); subplot.setBackgroundPaint(Color.lightGray); subplot.setDomainGridlinePaint(Color.white); subplot.setRangeGridlinePaint(Color.white); plot.add(subplot); } final JFreeChart chart = new JFreeChart("Dynamic Data Demo 3", plot); // chart.getLegend().setAnchor(Legend.EAST); chart.setBorderPaint(Color.black); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); final ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(60000.0); // 60 seconds final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JPanel buttonPanel = new JPanel(new FlowLayout()); for (int i = 0; i < SUBPLOT_COUNT; i++) { final JButton button = new JButton("Series " + i); button.setActionCommand("ADD_DATA_" + i); button.addActionListener(this); buttonPanel.add(button); } final JButton buttonAll = new JButton("ALL"); buttonAll.setActionCommand("ADD_ALL"); buttonAll.addActionListener(this); buttonPanel.add(buttonAll); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 470)); chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setContentPane(content); }
From source file:guineu.modules.filter.report.areaVSheight.ReportTask.java
/** * Create the chart and save it into a png file. * @param dataset/* w w w . j a v a2s.co m*/ * @param lipidName */ private void createChart(CategoryDataset dataset, String lipidName) { try { JFreeChart chart = ChartFactory.createLineChart("Height/Area", "Samples", "Height/Area", dataset, PlotOrientation.VERTICAL, false, false, false); // Chart characteristics CategoryPlot plot = (CategoryPlot) chart.getPlot(); final NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); LineAndShapeRenderer categoryRenderer = new LineAndShapeRenderer(); categoryRenderer.setSeriesLinesVisible(0, false); categoryRenderer.setSeriesShapesVisible(0, true); plot.setRenderer(categoryRenderer); // Save all the charts in the folder choosen by the user ChartUtilities.saveChartAsPNG(new File(this.reportFileName + "/HeightvsArea:" + lipidName + ".png"), chart, 1000, 500); } catch (IOException ex) { Logger.getLogger(ReportTask.class.getName()).log(Level.SEVERE, null, ex); } }