List of usage examples for org.jfree.chart.axis NumberAxis createIntegerTickUnits
public static TickUnitSource createIntegerTickUnits()
From source file:ejemplo.Ejemplo.java
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 );//from w w w . j ava2s. c o m // 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.wustl.cab2b.client.ui.visualization.charts.BarChart.java
protected JFreeChart createChart(Dataset dataset) { CategoryDataset categoryDataSet = (CategoryDataset) dataset; JFreeChart jFreeChart = ChartFactory.createBarChart("Bar Chart", null, "Value", categoryDataSet, PlotOrientation.VERTICAL, true, true, false); jFreeChart.setBackgroundPaint(Color.white); CategoryPlot categoryPlot = (CategoryPlot) jFreeChart.getPlot(); categoryPlot.setBackgroundPaint(Color.white); categoryPlot.setDomainGridlinePaint(Color.white); categoryPlot.setRangeGridlinePaint(Color.white); NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis(); numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer barRenderer = (BarRenderer) categoryPlot.getRenderer(); barRenderer.setDrawBarOutline(false); barRenderer.setMinimumBarLength(0.7D); barRenderer.setMaximumBarWidth(0.7D); barRenderer.setItemMargin(0.1D);/*from w ww. ja v a 2 s . c o m*/ CategoryAxis categoryaxis = categoryPlot.getDomainAxis(); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); return jFreeChart; }
From source file:jmbench.plots.OperationsVersusSizePlot.java
public void setAxisYTicks(double units, boolean isInteger) { NumberAxis axis = (NumberAxis) plot.getRangeAxis(); if (isInteger) axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); axis.setTickUnit(new NumberTickUnit(units)); }
From source file:XYPlotter.java
/** * Creates a chart and a plotpanel and add it to the mainwindow. *//*from ww w .java2 s . c o m*/ private void createChart() { getContentPane().removeAll(); xyDataset = createDataset(""); // create the chart... chart = ChartFactory.createXYLineChart("", // chart title "Line Chart Demo 6" "x", // x axis label "f(x)", // y axis label xyDataset, // data PlotOrientation.VERTICAL, true, // 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... plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); renderer.setSeriesShapesVisible(0, false); // a thin line will be painted for series1 renderer.setSeriesLinesVisible(1, false); // points will be painted for series2 plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. chartPanel = new ChartPanel(chart); getContentPane().add(chartPanel); }
From source file:org.posterita.core.BarChart.java
public JFreeChart createChart() throws OperationException { if (dataset == null) { throw new OperationException("Cannot create Bar chart: cause -> dataset empty!"); }/*from w ww. j a v a 2 s .c o m*/ switch (type) { case BARCHART_FLAT: chart = ChartFactory.createBarChart(title, xLabel, yLabel, dataset, orientation, showLegend, showTooltip, true); break; case BARCHART_3D: chart = ChartFactory.createBarChart3D(title, xLabel, yLabel, dataset, orientation, showLegend, showTooltip, true); break; default: throw new OperationException( "Invalid barchart type! Can only be BarChart.BARCHART_FLAT or BarChart.BARCHART_3D"); } //setting subtitle if (subtitle != null) { TextTitle title = new TextTitle(subtitle); chart.addSubtitle(title); } CategoryPlot plot = chart.getCategoryPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); //setting tickUnits if (integerTickUnits) axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer barRender = (BarRenderer) plot.getRenderer(); barRender.setMaximumBarWidth(maximumBarWidth); //displaying labels if (showLabels) { CategoryItemRenderer itemRender = plot.getRenderer(); itemRender.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); itemRender.setItemLabelsVisible(true); } return chart; }
From source file:org.jfree.experimental.chart.swt.demo.SWTBarChartDemo1.java
/** * Creates a sample chart.// w w w .jav a 2 s . co m * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("SWTBarChartDemo1", // 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... // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // the SWTGraphics2D class doesn't handle GradientPaint well, so // replace the gradient painter from the default theme with a // standard painter... renderer.setBarPainter(new StandardBarPainter()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:com.thingsfx.swing.jfreechart.JFreeChartPanel2.java
void initComponents() { // create the chart... JFreeChart chart = ChartFactory.createBarChart("JFreeChart is Definitely cool!", // chart title "Category", // domain axis label "Value", // range axis label createDataset(), // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );/*from w ww. ja v a 2s.c o m*/ // 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... CategoryPlot plot = (CategoryPlot) chart.getPlot(); // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. add(new ChartPanel(chart)); }
From source file:org.jfree.chart.demo.AreaChartDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createAreaChart("Area Chart", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); TextTitle texttitle = new TextTitle( "An area chart demonstration. We use this subtitle as an example of what happens when you get a really long title or subtitle."); texttitle.setFont(new Font("SansSerif", 0, 12)); texttitle.setPosition(RectangleEdge.TOP); texttitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.050000000000000003D, 0.050000000000000003D, 0.050000000000000003D, 0.050000000000000003D)); texttitle.setVerticalAlignment(VerticalAlignment.BOTTOM); jfreechart.addSubtitle(texttitle);/*from www .ja v a 2s .c om*/ CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setForegroundAlpha(0.5F); categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setDomainGridlinesVisible(true); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setRangeGridlinesVisible(true); categoryplot.setRangeGridlinePaint(Color.white); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); categoryaxis.setLowerMargin(0.0D); categoryaxis.setUpperMargin(0.0D); categoryaxis.addCategoryLabelToolTip("Type 1", "The first type."); categoryaxis.addCategoryLabelToolTip("Type 2", "The second type."); categoryaxis.addCategoryLabelToolTip("Type 3", "The third type."); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setLabelAngle(0.0D); return jfreechart; }
From source file:org.nbheaven.sqe.codedefects.history.controlcenter.panels.SQEHistoryPanel.java
/** Creates new form SQEHistoryPanel */ public SQEHistoryPanel() { historyChart = org.jfree.chart.ChartFactory.createStackedXYAreaChart(null, "Snapshot", "CodeDefects", perProjectDataSet, PlotOrientation.VERTICAL, false, true, false); historyChart.setBackgroundPaint(Color.WHITE); historyChart.getXYPlot().setRangeGridlinePaint(Color.BLACK); historyChart.getXYPlot().setDomainGridlinePaint(Color.BLACK); historyChart.getXYPlot().setBackgroundPaint(Color.WHITE); XYPlot plot = historyChart.getXYPlot(); plot.setForegroundAlpha(0.7f);//w w w.ja va2 s. c o m // plot.getRenderer(); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LogarithmicAxis rangeAxis = new LogarithmicAxis("CodeDefects"); rangeAxis.setStrictValuesFlag(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setRangeAxis(rangeAxis); StackedXYAreaRenderer2 categoryItemRenderer = new StackedXYAreaRenderer2(); //3D(); categoryItemRenderer.setSeriesPaint(0, Color.RED); categoryItemRenderer.setSeriesPaint(1, Color.ORANGE); categoryItemRenderer.setSeriesPaint(2, Color.YELLOW); plot.setRenderer(categoryItemRenderer); ChartPanel historyChartPanel = new ChartPanel(historyChart); historyChartPanel.setBorder(null); historyChartPanel.setPreferredSize(new Dimension(150, 200)); historyChartPanel.setBackground(Color.WHITE); initComponents(); historyView.setLayout(new BorderLayout()); historyView.add(historyChartPanel, BorderLayout.CENTER); JPanel selectorPanel = new JPanel(); selectorPanel.setOpaque(false); GroupLayout layout = new GroupLayout(selectorPanel); selectorPanel.setLayout(layout); // Turn on automatically adding gaps between components layout.setAutocreateGaps(true); // Turn on automatically creating gaps between components that touch // the edge of the container and the container. layout.setAutocreateContainerGaps(true); ParallelGroup horizontalParallelGroup = layout.createParallelGroup(GroupLayout.LEADING); SequentialGroup verticalSequentialGroup = layout.createSequentialGroup(); layout.setHorizontalGroup(layout.createSequentialGroup().add(horizontalParallelGroup)); layout.setVerticalGroup(verticalSequentialGroup); clearHistoryButton = new JButton(); clearHistoryButton.setEnabled(false); clearHistoryButton.setIcon(ImageUtilities .image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/codedefects/history/resources/trash.png"))); clearHistoryButton.setOpaque(false); clearHistoryButton.setFocusPainted(false); clearHistoryButton.setToolTipText( NbBundle.getBundle("org/nbheaven/sqe/codedefects/history/controlcenter/panels/Bundle") .getString("HINT_clear_button")); horizontalParallelGroup.add(clearHistoryButton); verticalSequentialGroup.add(clearHistoryButton); clearHistoryButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (null != activeHistory) { activeHistory.clear(); } } }); Component createVerticalStrut = Box.createVerticalStrut(10); horizontalParallelGroup.add(createVerticalStrut); verticalSequentialGroup.add(createVerticalStrut); for (final QualityProvider provider : SQEUtilities.getProviders()) { final JToggleButton providerButton = new JToggleButton(); providerButton.setIcon(provider.getIcon()); providerButton.setOpaque(false); providerButton.setFocusPainted(false); horizontalParallelGroup.add(providerButton); verticalSequentialGroup.add(providerButton); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { if (providerButton.isSelected()) { addSelectedProvider(provider); } else { removeSelectedProvider(provider); } updateView(); } }; providerButton.addActionListener(listener); addSelectedProvider(provider); providerButton.setSelected(true); } historyView.add(selectorPanel, BorderLayout.EAST); }
From source file:loadmaprenderer.ResultDisplayChart.java
private JFreeChart makeChart(XYDataset dataset, String chartTitle, String dataTitle) { JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, "Year", dataTitle, dataset, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = chart.getXYPlot();/*from w w w . ja va 2 s . co m*/ plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLUE); plot.setRangeGridlinePaint(Color.BLUE); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRange(true); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); Double range = dataLine.getMaxY() - dataLine.getMinY(); if (Math.abs(range) < 0.1) range = dataLine.getMaxY(); rangeAxis.setRange(dataLine.getMinY() - range * 0.1, dataLine.getMaxY() + range * 0.1); return chart; }