List of usage examples for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero
public void setAutoRangeIncludesZero(boolean flag)
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createTimeSeriesChart(XYDataset dataset) { DateAxis timeAxis = new DateAxis(xAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02);/*from w w w . j a v a2 s .c o m*/ NumberAxis valueAxis = new NumberAxis(yAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); JFreeChart chart = new JFreeChart("TimeSeries Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); 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); plot.setRangeCrosshairVisible(true); // renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy")); return chart; }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createTimeSeriesChart2(XYDataset dataset) { DateAxis timeAxis = new DateAxis(xAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02);/*ww w .j a va 2 s .com*/ NumberAxis valueAxis = new NumberAxis(yAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); JFreeChart chart = new JFreeChart("TimeSeries Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); 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); plot.setRangeCrosshairVisible(true); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy")); return chart; }
From source file:de.cebitec.readXplorer.plotting.CreatePlots.java
private synchronized static JFreeChart createCombinedChart(XYSeriesCollection normal, XYSeriesCollection posInf, XYSeriesCollection negInf, String xName, String yName, XYToolTipGenerator toolTip) { final NumberAxis domainAxis = new NumberAxis(xName); // create subplot 1... final XYDataset data1 = normal; final XYItemRenderer renderer1 = new XYShapeRenderer(); renderer1.setBaseToolTipGenerator(toolTip); final NumberAxis rangeAxis1 = new NumberAxis(yName); final XYPlot subplot1 = new XYPlot(data1, domainAxis, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // create subplot 2... final XYDataset data2 = negInf; final XYItemRenderer renderer2 = new XYShapeRenderer(); renderer2.setBaseToolTipGenerator(toolTip); final NumberAxis rangeAxis2 = new NumberAxis() { @Override//www .j a v a2 s . c o m public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) { List myTicks = new ArrayList(); myTicks.add(new NumberTick(0, "-Inf", TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0)); return myTicks; } }; rangeAxis2.setAutoRangeIncludesZero(false); final XYPlot subplot2 = new XYPlot(data2, domainAxis, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // create subplot 3... final XYDataset data3 = posInf; final XYItemRenderer renderer3 = new XYShapeRenderer(); renderer3.setBaseToolTipGenerator(toolTip); final NumberAxis rangeAxis3 = new NumberAxis() { @Override public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) { List myTicks = new ArrayList(); myTicks.add(new NumberTick(0, "Inf", TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0)); return myTicks; } }; rangeAxis3.setAutoRangeIncludesZero(false); final XYPlot subplot3 = new XYPlot(data3, domainAxis, rangeAxis3, renderer3); subplot2.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // parent plot... final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domainAxis); plot.setGap(0); // add the subplots... plot.add(subplot3, 1); plot.add(subplot1, 10); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); // return a new chart containing the overlaid plot... return new JFreeChart(plot); }
From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart1.java
public static JFreeChart createChart2(ArrayList<DataItems> _nor_model, ArrayList<DataItems> _abnor_model, DataItems nor, DataItems abnor, Map<String, ArrayList<LinePos>> mapAB, String chartname, String protocol1, String protocol2) { XYDataset xydataset = createNormalDataset(nor, protocol1); JFreeChart jfreechart = ChartFactory.createXYLineChart(chartname, "", "", xydataset); jfreechart.getLegend().setVisible(false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 6D, 6D); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); // ??/*www.ja va2s .c o m*/ xylineandshaperenderer.setSeriesLinesVisible(0, true); xylineandshaperenderer.setBaseShapesVisible(false); xylineandshaperenderer.setSeriesShape(0, double1); xylineandshaperenderer.setSeriesPaint(0, Color.blue); xylineandshaperenderer.setSeriesFillPaint(0, Color.blue); xylineandshaperenderer.setSeriesOutlinePaint(0, Color.blue); xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(0.5F)); // ? // xylineandshaperenderer.setBaseItemLabelGenerator(new // StandardXYItemLabelGenerator()); // xylineandshaperenderer.setBaseItemLabelsVisible(true); int datasetcount0 = xyplot.getDatasetCount(); XYDataset xydataset1 = createNormalDataset(abnor, protocol2); // xydataset1. XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(); int datasetcount = xyplot.getDatasetCount(); xyplot.setDataset(datasetcount, xydataset1); xyplot.setRenderer(datasetcount, xylineandshaperenderer1); // ??? xylineandshaperenderer1.setBaseShapesVisible(false); // ?? xylineandshaperenderer1.setSeriesLinesVisible(0, true); xylineandshaperenderer1.setSeriesShape(0, double1); // xylineandshaperenderer1.setSeriesPaint(0, Color.green); xylineandshaperenderer1.setSeriesFillPaint(0, Color.green); xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.green); xylineandshaperenderer1.setUseFillPaint(true); xylineandshaperenderer1.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xylineandshaperenderer1.setSeriesStroke(0, new BasicStroke(0.5F)); // //? /* * for (int i = 0; i < _nor_model.size(); i++) { XYDataset xydataset2 = * createmodeDataset(_nor_model.get(i), "_nor_model" + i); * XYLineAndShapeRenderer xylineandshaperenderer2 = new * XYLineAndShapeRenderer(); xyplot.setDataset(i + 2, xydataset2); * xyplot.setRenderer(2 + i, xylineandshaperenderer2); // ??? * xylineandshaperenderer2.setBaseShapesVisible(false); // ?? * xylineandshaperenderer2.setSeriesLinesVisible(0, true); * xylineandshaperenderer2.setSeriesShape(0, double1); // * xylineandshaperenderer2.setSeriesPaint(0, Color.red); * xylineandshaperenderer2.setSeriesFillPaint(0, Color.red); * xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.red); * xylineandshaperenderer2.setUseFillPaint(true); * xylineandshaperenderer2 .setBaseItemLabelGenerator(new * StandardXYItemLabelGenerator()); * xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(2.5F)); * * } for (int i = 0; i < _abnor_model.size(); i++) { XYDataset * xydataset3 = createmodeDataset(_abnor_model.get(i), "_abnor_model" + * i); XYLineAndShapeRenderer xylineandshaperenderer3 = new * XYLineAndShapeRenderer(); xyplot.setDataset(i + 2 + * _nor_model.size(), xydataset3); xyplot.setRenderer(i + 2 + * _nor_model.size(), xylineandshaperenderer3); // ??? * xylineandshaperenderer3.setBaseShapesVisible(false); // ?? * xylineandshaperenderer3.setSeriesLinesVisible(0, true); * xylineandshaperenderer3.setSeriesShape(0, double1); // * xylineandshaperenderer3.setSeriesPaint(0, Color.red); * xylineandshaperenderer3.setSeriesFillPaint(0, Color.red); * xylineandshaperenderer3.setSeriesOutlinePaint(0, Color.red); * xylineandshaperenderer3.setUseFillPaint(true); * xylineandshaperenderer3 .setBaseItemLabelGenerator(new * StandardXYItemLabelGenerator()); * xylineandshaperenderer3.setSeriesStroke(0, new BasicStroke(2.5F)); * * } */ // ?? // // ///////////////////////////////// // ? XYDataset xydataset4 = createLineDataset(nor, abnor, mapAB, xyplot); // ??y=1 ValueMarker valuemarker = new ValueMarker(1); // valuemarker.setLabelOffsetType(LengthAdjustmentType.EXPAND); valuemarker.setPaint(Color.black); // ? valuemarker.setStroke(new BasicStroke(1.0F)); // // valuemarker.setLabel(""); //? valuemarker.setLabelFont(new Font("SansSerif", 0, 11)); // ? valuemarker.setLabelPaint(Color.red); valuemarker.setLabelAnchor(RectangleAnchor.TOP_LEFT); valuemarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); xyplot.addRangeMarker(valuemarker); // // //jfreechart.getLegend().setVisible(true); return jfreechart; }
From source file:osh.comdriver.simulation.cruisecontrol.ScheduleDrawer.java
/** * Creates a chart./*w ww . j a va2s . c om*/ * * @param dataset1 a dataset. * @return A chart. */ private static JFreeChart createChart(XYDataset dataset1, //power XYDataset dataset2, //costs XYDataset dataset3, long time) { JFreeChart chart = ChartFactory.createTimeSeriesChart("schedule", // title "time", // x-axis label "power", // y-axis label dataset1, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis axis1 = new NumberAxis("power"); NumberAxis axis2 = new NumberAxis("costs"); axis1.setAutoRangeIncludesZero(true); axis1.setUpperBound(5000); axis1.setLowerBound(-5000); axis2.setAutoRangeIncludesZero(true); axis2.setUpperBound(50); axis2.setLowerBound(0); plot.setRangeAxis(0, axis1); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); plot.setDataset(2, dataset3); plot.mapDatasetToRangeAxis(2, 0); 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); plot.setRangeCrosshairVisible(true); //TODO: SHADOWS OFF final StandardXYItemRenderer r1 = new StandardXYItemRenderer(); final StandardXYItemRenderer r2 = new StandardXYItemRenderer(); final StandardXYItemRenderer r3 = new StandardXYItemRenderer(); final StandardXYItemRenderer r4 = new StandardXYItemRenderer(); plot.setRenderer(0, r1); plot.setRenderer(1, r2); plot.setRenderer(2, r3); plot.setRenderer(3, r4); int numberOfSeries = 0; numberOfSeries += dataset1.getSeriesCount(); numberOfSeries += dataset2.getSeriesCount(); numberOfSeries += dataset3.getSeriesCount(); Color[] color = new Color[numberOfSeries]; for (int i = 0; i < numberOfSeries / 2; i++) { color[i] = Color.getHSBColor(i * 1.0f / (numberOfSeries / 2), 1.0f, 1.0f); } int i = 0; for (int j = 0; j < dataset1.getSeriesCount() / 2; j++) { float[] rgbcolor = Color.RGBtoHSB(color[i].getRed(), color[i].getGreen(), color[i].getBlue(), null); plot.getRendererForDataset(dataset1).setSeriesPaint(2 * j, Color.getHSBColor(rgbcolor[0], 1.0f, 1.0f)); plot.getRendererForDataset(dataset1).setSeriesPaint(2 * j + 1, Color.getHSBColor(rgbcolor[0], 1.0f, 0.6f)); i++; } for (int j = 0; j < dataset2.getSeriesCount() / 2; j++) { float[] rgbcolor = Color.RGBtoHSB(color[i].getRed(), color[i].getGreen(), color[i].getBlue(), null); plot.getRendererForDataset(dataset2).setSeriesPaint(2 * j, Color.getHSBColor(rgbcolor[0], 1.0f, 1.0f)); plot.getRendererForDataset(dataset2).setSeriesPaint(2 * j + 1, Color.getHSBColor(rgbcolor[0], 1.0f, 0.6f)); i++; } for (int j = 0; j < dataset3.getSeriesCount() / 2; j++) { float[] rgbcolor = Color.RGBtoHSB(color[i].getRed(), color[i].getGreen(), color[i].getBlue(), null); plot.getRendererForDataset(dataset3).setSeriesPaint(2 * j, Color.getHSBColor(rgbcolor[0], 1.0f, 1.0f)); plot.getRendererForDataset(dataset3).setSeriesPaint(2 * j + 1, Color.getHSBColor(rgbcolor[0], 1.0f, 0.6f)); i++; } // NOW line double upperBound = plot.getRangeAxis(1).getUpperBound(); double lowerBound = plot.getRangeAxis(1).getLowerBound(); XYSeries nowLine = new XYSeries("now"); nowLine.add(time * 1000, lowerBound); nowLine.add(time * 1000, upperBound); XYSeriesCollection nowColl = new XYSeriesCollection(); //power axis nowColl.addSeries(nowLine); XYDataset nowSet = nowColl; plot.setDataset(3, nowSet); plot.mapDatasetToRangeAxis(3, 1); plot.getRendererForDataset(nowSet).setSeriesPaint(0, Color.DARK_GRAY); plot.getRendererForDataset(nowSet).setSeriesStroke(0, (Stroke) new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 6.0f }, 0.0f)); plot.setDomainAxis(new DateAxis()); plot.getDomainAxis().setAutoRange(false); long begin = (time / 86400) * 86400 * 1000; //beginning of day long end = begin + 86400 * 2 * 1000; plot.getDomainAxis().setRange(begin, end); return chart; }
From source file:jgnash.ui.commodity.SecuritiesHistoryDialog.java
private static JFreeChart createChart(final SecurityNode node) { Objects.requireNonNull(node); final List<SecurityHistoryNode> hNodes = node.getHistoryNodes(); final Date max = DateUtils.asDate(hNodes.get(hNodes.size() - 1).getLocalDate()); final Date min = DateUtils.asDate(hNodes.get(0).getLocalDate()); final DateAxis timeAxis = new DateAxis(null); timeAxis.setVisible(false);//from www .j a v a 2s . c o m timeAxis.setAutoRange(false); timeAxis.setRange(min, max); final NumberAxis valueAxis = new NumberAxis(null); valueAxis.setAutoRangeIncludesZero(false); valueAxis.setVisible(false); final XYAreaRenderer renderer = new XYAreaRenderer(); renderer.setBaseToolTipGenerator(new SecurityItemLabelGenerator(node)); renderer.setOutline(true); renderer.setSeriesPaint(0, new Color(225, 247, 223)); final XYPlot plot = new XYPlot(null, timeAxis, valueAxis, renderer); final List<List<SecurityHistoryNode>> groups = node.getHistoryNodeGroupsBySplits(); for (int i = 0; i < groups.size(); i++) { int size = groups.get(i).size(); Date[] date = new Date[size]; double[] high = new double[size]; double[] low = new double[size]; double[] open = new double[size]; double[] close = new double[size]; double[] volume = new double[size]; for (int j = 0; j < size; j++) { final SecurityHistoryNode hNode = groups.get(i).get(j); date[j] = DateUtils.asDate(hNode.getLocalDate()); high[j] = hNode.getAdjustedHigh().doubleValue(); low[j] = hNode.getAdjustedLow().doubleValue(); open[j] = hNode.getAdjustedPrice().doubleValue(); close[j] = hNode.getAdjustedPrice().doubleValue(); volume[j] = hNode.getVolume(); } final AbstractXYDataset data = new DefaultHighLowDataset(node.getDescription() + i, date, high, low, open, close, volume); plot.setDataset(i, data); } plot.setInsets(new RectangleInsets(1, 1, 1, 1)); final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(null); return chart; }
From source file:org.gumtree.vis.awt.PlotFactory.java
private static NumberAxis createYAxis(IXYZDataset dataset) { String title = ""; String yTitle = dataset.getYTitle(); if (yTitle != null) { title += yTitle;/* w ww . j a v a 2s. c om*/ } String yUnits = dataset.getYUnits(); if (yUnits != null) { title += " (" + yUnits + ")"; } if (title.trim().length() == 0) { title = null; } NumberAxis yAxis = new NumberAxis(title); yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); yAxis.setAutoRangeIncludesZero(false); return yAxis; }
From source file:org.gumtree.vis.awt.PlotFactory.java
private static NumberAxis createXAxis(IXYZDataset dataset) { String title = ""; String xTitle = dataset.getXTitle(); if (xTitle != null) { title += xTitle;//from w ww. j a v a2s . c o m } String xUnits = dataset.getXUnits(); if (xUnits != null) { title += " (" + xUnits + ")"; } if (title.trim().length() == 0) { title = null; } NumberAxis xAxis = new NumberAxis(title); xAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); xAxis.setAutoRangeIncludesZero(false); return xAxis; }
From source file:ec.util.chart.swing.JTimeSeriesRendererSupportDemo.java
private static JFreeChart createTsChart() { XYPlot plot = new XYPlot(); plot.setAxisOffset(RectangleInsets.ZERO_INSETS); DateAxis domainAxis = new DateAxis(); domainAxis.setTickLabelsVisible(false); domainAxis.setLowerMargin(0.02);/*ww w. j a v a 2s. co m*/ domainAxis.setUpperMargin(0.02); plot.setDomainAxis(domainAxis); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelsVisible(false); rangeAxis.setLowerMargin(0.02); rangeAxis.setUpperMargin(0.02); plot.setRangeAxis(rangeAxis); JFreeChart result = new JFreeChart("", null, plot, true); result.setPadding(new RectangleInsets(5, 5, 5, 5)); result.getLegend().setFrame(BlockBorder.NONE); result.getLegend().setBackgroundPaint(null); return result; }
From source file:weka.core.ChartUtils.java
/** * Create a box plot from summary data (mean, median, q1, q3, min, max, * minOutlier, maxOutlier, list of outliers) * /*from w ww . j a v a 2 s . c om*/ * @param summary summary data * @param outliers list of outlier values * @param additionalArgs additional options to the renderer * @return a box plot chart * @throws Exception if a problem occurs */ protected static JFreeChart getBoxPlotFromSummaryData(List<Double> summary, List<Double> outliers, List<String> additionalArgs) throws Exception { if (summary.size() != 8) { throw new Exception("Expected 8 values in the summary argument: mean, median, " + "q1, q3, min, max, minOutlier, maxOutlier"); } String plotTitle = "Box Plog"; String userTitle = getOption(additionalArgs, "-title"); plotTitle = (userTitle != null) ? userTitle : plotTitle; String xLabel = getOption(additionalArgs, "-x-label"); xLabel = xLabel == null ? "" : xLabel; String yLabel = getOption(additionalArgs, "-y-label"); yLabel = yLabel == null ? "" : yLabel; DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); Double mean = summary.get(0); Double median = summary.get(1); Double q1 = summary.get(2); Double q3 = summary.get(3); Double min = summary.get(4); Double max = summary.get(5); Double minOutlier = summary.get(6); Double maxOutlier = summary.get(7); if (mean.isNaN() || median.isNaN() || min.isNaN() || max.isNaN() || q1.isNaN() || q3.isNaN()) { throw new Exception("NaN in summary data - can't generate box plot"); } BoxAndWhiskerItem item = new BoxAndWhiskerItem(mean, median, q1, q3, min, max, minOutlier, maxOutlier, outliers); dataset.add(item, "", ""); CategoryAxis xAxis = new CategoryAxis(); NumberAxis yAxis = new NumberAxis(); yAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setMaximumBarWidth(0.15); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(plotTitle, new Font("SansSerif", Font.BOLD, 12), plot, false); return chart; }