List of usage examples for org.jfree.chart.axis NumberAxis setStandardTickUnits
public void setStandardTickUnits(TickUnitSource source)
From source file:org.jgrasstools.gears.utils.images.LineChartGenerator.java
/** * Creates the chart image and dumps it to file. * /*from www . j a v a2s . c o m*/ * @param chartFile the file to which to write to. * @param autoRange flag to define if to auto define the range from the bounds. * @param withLegend flag to define the legend presence. * @param imageWidth the output image width (if -1 default is used). * @param imageHeight the output image height (if -1 default is used). * @throws IOException */ @SuppressWarnings("nls") public void dumpChart(File chartFile, boolean autoRange, boolean withLegend, int imageWidth, int imageHeight) throws IOException { JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, collection, PlotOrientation.VERTICAL, withLegend, false, false); XYPlot plot = (XYPlot) chart.getPlot(); // plot.setDomainPannable(true); // plot.setRangePannable(true); // plot.setForegroundAlpha(0.85f); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); if (autoRange) { double delta = (max - min) * 0.1; yAxis.setRange(min - delta, max + delta); yAxis.setMinorTickCount(4); yAxis.setMinorTickMarksVisible(true); } // ValueAxis xAxis = plot.getDomainAxis(); // xAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US)); // XYItemRenderer renderer = plot.getRenderer(); // renderer.setDrawBarOutline(false); // // flat bars look best... // renderer.setBarPainter(new StandardXYBarPainter()); // renderer.setShadowVisible(false); if (!chartFile.getName().endsWith(".png")) { chartFile = FileUtilities.substituteExtention(chartFile, "png"); } if (imageWidth == -1) { imageWidth = IMAGEWIDTH; } if (imageHeight == -1) { imageHeight = IMAGEHEIGHT; } BufferedImage bufferedImage = chart.createBufferedImage(imageWidth, imageHeight); ImageIO.write(bufferedImage, "png", chartFile); }
From source file:org.cerberus.refactor.LineChart.java
public BufferedImage bi(CategoryDataset categorydataset, String name, int count) { BufferedImage bi = null;/*from w w w . j a va 2 s.c o m*/ JFreeChart jfreechart = ChartFactory.createLineChart(name, "Category", "Count", categorydataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); Shape point = ShapeUtilities.createDiagonalCross(1, 1); //TODO check this - seriesColors never used // String[] seriesColors = {"#FF0000", "#D7D6F6", "#0F07F3", "#EEFFBD", "#75C53E", "#FED7BA", "#FE6F01"}; // String[] seriesColors2 = {"#D7D6F6", "#0F07F3", "#EEFFBD", "#75C53E", "#FED7BA", "#FE6F01"}; LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer(); lineandshaperenderer.setBaseShapesVisible(true); lineandshaperenderer.setBaseShapesFilled(true); for (int a = 0; a < count; a++) { lineandshaperenderer.setSeriesShapesVisible(a, true); lineandshaperenderer.setSeriesLinesVisible(a, true); lineandshaperenderer.setSeriesStroke(a, new BasicStroke(1.0F)); lineandshaperenderer.setSeriesShape(a, point); } lineandshaperenderer.setDrawOutlines(true); lineandshaperenderer.setUseFillPaint(true); lineandshaperenderer.setBaseFillPaint(Color.white); //DateAxis dateaxis = (DateAxis)xyplot.getDomainAxis(); //dateaxis.setDateFormatOverride(new SimpleDateFormat("hh:mm")); bi = jfreechart.createBufferedImage(500, 270); return bi; }
From source file:org.perfrepo.web.controller.reports.testgroup.TestGroupChartBean.java
public void drawChart(OutputStream out, Object data) throws IOException { if (data instanceof ChartData) { ChartData chartData = (ChartData) data; JFreeChart chart = ChartFactory.createBarChart(chartData.getTitle(), "Test", "%", processDataSet(chartData), PlotOrientation.HORIZONTAL, false, true, false); chart.addSubtitle(new TextTitle("Comparison", new Font("Dialog", Font.ITALIC, 10))); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); CustomRenderer renderer = new CustomRenderer(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{2}%", NumberFormat.getInstance())); renderer.setBaseItemLabelsVisible(true); renderer.setDrawBarOutline(false); renderer.setMaximumBarWidth(1d / (chartData.getTests().length + 4.0)); plot.setRenderer(renderer);//from ww w . j a v a 2s . c o m CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setCategoryMargin(0.1); categoryAxis.setUpperMargin(0.1); categoryAxis.setLowerMargin(0.1); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.10); BufferedImage buffImg = chart.createBufferedImage(640, chartData.getTests().length * 100 + 100); ImageIO.write(buffImg, "gif", out); } }
From source file:cheuk.licenseheaderchecker.resource.DataGraph.java
/** * Creates a trend graph/*w w w .j a va2s. com*/ * * @return the JFreeChart graph object */ protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createLineChart(null, // chart title null, // unused yLabel, // range axis label categoryDataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... //final LegendTitle legend = chart.getLegend(); //legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0); // rangeAxis.setAutoRange(true); final StackedAreaRenderer renderer = new StackedAreaRenderer2(); plot.setRenderer(renderer); //renderer.setBaseStroke(new BasicStroke(2.0f)); //ColorPalette.apply(renderer); plot.setRenderer(renderer); renderer.setSeriesPaint(2, RED); renderer.setSeriesPaint(1, GRAY); renderer.setSeriesPaint(0, YELLOW); // crop extra space around the graph plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); return chart; }
From source file:etssi.Graphique.java
/** * Creates a chart./* w w w.j a v a 2s . c o m*/ * * @param dataset the data for the chart. * * @return a chart. */ private JFreeChart createChart(final XYDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createXYLineChart("Graphique", // chart title "Tranche Horaire (0 avant 6h, 1 de 6h 10h, 2 de 10h 16h, 3 de 16h 20h, 4 aprs 20h ", // x axis label "Montant passagers", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // get a reference to the plot for further customisation... final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); //renderer.setSeriesLinesVisible(0, false); //renderer.setSeriesShapesVisible(1, false); //plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.javarebel.chart.generator.ChartGenerator.java
protected void configureChart(JFreeChart chart, ChartData data) { ChartConfig config = data.getConfig(); chart.setBackgroundPaint(/*from w w w .j a v a2 s . co m*/ (config == null || config.getBackground() == null) ? Color.WHITE : config.getBackground()); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); PlotConfig plotConfig = new DefaultPlotConfig(); if (config != null && config.getPlotConfig() != null) plotConfig = config.getPlotConfig(); configurePlot(plot, plotConfig); final CategoryItemRenderer renderer = plot.getRenderer(); ItemLabelConfig labelConfig = new DefaultItemLabelConfig(); if (config != null && config.getLabelConfig() != null) labelConfig = config.getLabelConfig(); configureBaseItemLabel(renderer, labelConfig); renderer.setBaseSeriesVisibleInLegend(data.isLegendVisible()); if (config != null && config.getForeground() != null) renderer.setSeriesPaint(0, config.getForeground()); else renderer.setSeriesPaint(0, data.getSeriesColor()); DefaultAxisConfig axisConfig = new DefaultAxisConfig(); if (config != null && config.getAxisConfig() != null) axisConfig = config.getAxisConfig(); configureAxis(plot.getDomainAxis(), axisConfig); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); }
From source file:MWC.GUI.JFreeChart.CourseFormatter.java
public final void format(final XYPlot thePlot) { final NumberAxis theAxis = (NumberAxis) thePlot.getRangeAxis(); theAxis.setRange(0, 360);// w w w .j a v a 2 s.c om // create some tick units suitable for degrees theAxis.setStandardTickUnits(getDegreeTickUnits()); theAxis.setAutoTickUnitSelection(true); }
From source file:org.jenkinsci.plugins.autozoil.graph.AutozoilGraph.java
/** * Creates a Autozoil trend graph// w ww .ja v a 2 s . c om * * @return the JFreeChart graph object */ protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createLineChart(null, // chart title null, // unused yLabel, // range axis label categoryDataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... final LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0); rangeAxis.setAutoRange(true); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(2.0f)); ColorPalette.apply(renderer); // crop extra space around the graph plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); return chart; }
From source file:com.intel.stl.ui.configuration.view.VLStallCountByVLBarChartPanel.java
@Override public void initComponents() { dataset = new XYSeriesCollection(); JFreeChart chart = ComponentFactory.createXYBarChart(K0342_PORT_VL_TITLE.getValue(), K0347_PORT_VL_STALL_COUNT.getValue(), dataset, (XYItemLabelGenerator) null); XYPlot plot = chart.getXYPlot();// w w w. java 2 s. c om plot.setDomainPannable(true); plot.setRangePannable(true); final String vlLabel = "<html>" + K0342_PORT_VL_TITLE.getValue() + ": "; final String mtuLabel = "<br>" + K0347_PORT_VL_STALL_COUNT.getValue() + ": "; XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setBarAlignmentFactor(0); renderer.setMargin(0.2); renderer.setSeriesToolTipGenerator(0, new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int arg1, int arg2) { int vlNum = (int) dataset.getXValue(arg1, arg2); int mtuCount = (int) dataset.getYValue(arg1, arg2); return vlLabel + vlNum + mtuLabel + mtuCount + "</html>"; } }); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); chartPanel = new ChartPanel(chart); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(PREFERRED_CHART_SIZE); propsPanel.add(chartPanel); }
From source file:com.intel.stl.ui.configuration.view.HoQLifeBarChartPanel.java
@Override public void initComponents() { dataset = new XYSeriesCollection(); JFreeChart chart = ComponentFactory.createXYBarChart(K0342_PORT_VL_TITLE.getValue(), K1069_HOQLIFE.getValue(), dataset, (XYItemLabelGenerator) null); XYPlot plot = chart.getXYPlot();//from w w w .j a va 2s . c o m plot.setDomainPannable(true); plot.setRangePannable(true); final String vlLabel = "<html>" + K0342_PORT_VL_TITLE.getValue() + ": "; final String hoqLabel = "<br>" + K1069_HOQLIFE.getValue() + ": "; XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setBarAlignmentFactor(0); renderer.setMargin(0.2); renderer.setSeriesToolTipGenerator(0, new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int arg1, int arg2) { int vlNum = (int) dataset.getXValue(arg1, arg2); int hoqCount = (int) dataset.getYValue(arg1, arg2); return vlLabel + vlNum + hoqLabel + hoqCount + "</html>"; } }); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); chartPanel = new ChartPanel(chart); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(PREFERRED_CHART_SIZE); propsPanel.add(chartPanel); }