List of usage examples for org.jfree.chart.axis NumberAxis setStandardTickUnits
public void setStandardTickUnits(TickUnitSource source)
From source file:fitmon.Chart.java
/** * Creates a sample chart.//from w w w . ja v a 2 s. co m * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:servlet.SalesReportEventsBarChart.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w . j a va 2 s . c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List<ArrayList> data = productSession.getEventSessionNo(); final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < data.size(); i++) { dataset.addValue(Integer.valueOf(data.get(i).get(1).toString()), "Sessions", data.get(i).get(0).toString()); } final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); JFreeChart barChart = ChartFactory.createBarChart("No of Sessions", "Event", "Sessions", dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot cplot = (CategoryPlot) barChart.getPlot(); cplot.setBackgroundPaint(Color.WHITE);//change background color //set bar chart color ((BarRenderer) cplot.getRenderer()).setBarPainter(new StandardBarPainter()); BarRenderer r = (BarRenderer) barChart.getCategoryPlot().getRenderer(); r.setSeriesPaint(0, Color.GREEN); r.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getInstance())); r.setBaseItemLabelsVisible(true); CategoryAxis categoryAxis = cplot.getDomainAxis(); categoryAxis.setUpperMargin(0.15); NumberAxis rangeAxis = (NumberAxis) cplot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.15); int width = 550; /* Width of the image */ int height = 450; /* Height of the image */ response.setContentType("image/png"); OutputStream out = response.getOutputStream(); ChartUtilities.writeChartAsPNG(out, barChart, 400, 300, info); }
From source file:org.jfree.chart.demo.WaterTemperatureDemo.java
/** * A demonstration application showing an XY series containing a null value. * * @param title the frame title./*from w ww . j ava 2s .co m*/ */ public WaterTemperatureDemo(final String title) { super(title); final XYDataset dataset = createDataset(); final NumberAxis rangeAxis = new NumberAxis("Temperature"); rangeAxis.setRange(-0.55, -0.15); final NumberAxis domainAxis = new NumberAxis("Depth"); domainAxis.setInverted(true); domainAxis.setRange(0.0, 35.0); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final XYItemRenderer renderer = new StandardXYItemRenderer(); final XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); plot.setOrientation(PlotOrientation.HORIZONTAL); final JFreeChart chart = new JFreeChart("Water Temperature By Depth", plot); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:br.prof.salesfilho.oci.image.GraphicBuilder.java
public void createChart() { chart = ChartFactory.createXYLineChart(this.title, this.xLabel, this.yLabel, this.collectionDataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); List<XYSeries> listSeries = collectionDataset.getSeries(); for (int i = 0; i < listSeries.size(); i++) { renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShapesFilled(i, false); }/*from w ww. j av a 2 s .co m*/ plot.setRenderer(renderer); plot.setRangePannable(true); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); chartPanel.setChart(chart); }
From source file:org.jfree.chart.demo.ParetoChartDemo.java
/** * Creates a new demo instance./*from w w w . j a va 2 s. c o m*/ * * @param title the frame title. */ public ParetoChartDemo(final String title) { super(title); final DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("C", new Integer(4843)); data.addValue("C++", new Integer(2098)); data.addValue("C#", new Integer(26)); data.addValue("Java", new Integer(1901)); data.addValue("Perl", new Integer(2507)); data.addValue("PHP", new Integer(1689)); data.addValue("Python", new Integer(948)); data.addValue("Ruby", new Integer(100)); data.addValue("SQL", new Integer(263)); data.addValue("Unix Shell", new Integer(485)); data.sortByValues(SortOrder.DESCENDING); final KeyedValues cumulative = DataUtilities.getCumulativePercentages(data); final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Languages", data); // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Freshmeat Software Projects", // chart title "Language", // domain axis label "Projects", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.addSubtitle(new TextTitle("By Programming Language")); chart.addSubtitle(new TextTitle("As at 5 March 2003")); // set the background color for the chart... chart.setBackgroundPaint(new Color(0xBBBBDD)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); final CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative", cumulative); final NumberAxis axis2 = new NumberAxis("Percent"); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); // OPTIONAL CUSTOMISATION COMPLETED. // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(550, 270)); setContentPane(chartPanel); }
From source file:edu.cuny.cat.ui.TraderDistributionPanel.java
public TraderDistributionPanel() { registry = GameController.getInstance().getRegistry(); clock = GameController.getInstance().getClock(); dataset = new DefaultCategoryDataset(); setTitledBorder("Trader Distribution"); chart = ChartFactory.createLineChart("", "", "", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(getBackground()); final CategoryPlot categoryplot = chart.getCategoryPlot(); categoryplot.setOrientation(PlotOrientation.HORIZONTAL); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); final LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer(); UIUtils.setDefaultLineAndShapeRendererStyle(lineandshaperenderer); lineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); final NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setAutoRangeIncludesZero(false); numberaxis.setUpperMargin(0.12D);/*from w w w .j a va 2 s . c om*/ final ChartPanel chartPanel = new ChartPanel(chart); add(chartPanel, BorderLayout.CENTER); }
From source file:LineChartDemo6.java
/** * Creates a chart.//from w w w . j a v a 2 s. com * * @param dataset the data for the chart. * * @return a chart. */ private JFreeChart createChart(final XYDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart Demo 6", // chart title "X", // x axis label "Y", // 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.lightGray); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); 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:edu.ucla.stat.SOCR.chart.demo.StatisticalLineChartDemo1.java
/** * Creates a sample chart./*from w w w . j av a 2 s. c o m*/ * * @param dataset a dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation !legendPanelOn, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setUpperMargin(0.0); domainAxis.setLowerMargin(0.0); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); // customise the renderer... StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(true, false); plot.setRenderer(renderer); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:edu.ucla.stat.SOCR.chart.SuperNormalDistributionChart.java
/** * Creates a chart./*w ww .j av a 2 s .c o m*/ * * @param dataset the dataset. * * @return a chart. */ protected JFreeChart createChart(XYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title domainLabel, // x axis label rangeLabel, // y axis label dataset, // data PlotOrientation.VERTICAL, !legendPanelOn, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.jfree.chart.demo.CrosshairDemo1.java
/** * Creates a chart./*from w w w .j ava 2s . c o m*/ * * @param dataset the data for the chart. * * @return a chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createXYLineChart("Crosshair Demo 1", // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setDomainCrosshairVisible(true); plot.setDomainCrosshairLockedOnData(true); plot.setRangeCrosshairVisible(true); plot.setRangeCrosshairLockedOnData(true); final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setPlotShapes(true); renderer.setShapesFilled(true); // 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; }