List of usage examples for org.jfree.chart.axis NumberAxis createIntegerTickUnits
public static TickUnitSource createIntegerTickUnits()
From source file:org.jfree.chart.demo.LineChartDemo5.java
/** * Creates a sample chart.//from w w w. j a va2 s. c o m * * @param dataset the dataset. * * @return a chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createLineChart("Line Chart Demo 5", // chart title "Type", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); final Shape[] shapes = new Shape[3]; int[] xpoints; int[] ypoints; // right-pointing triangle xpoints = new int[] { -3, 3, -3 }; ypoints = new int[] { -3, 0, 3 }; shapes[0] = new Polygon(xpoints, ypoints, 3); // vertical rectangle shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6); // left-pointing triangle xpoints = new int[] { -3, 3, 3 }; ypoints = new int[] { 0, -3, 3 }; shapes[2] = new Polygon(xpoints, ypoints, 3); final DrawingSupplier supplier = new DefaultDrawingSupplier(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, shapes); final CategoryPlot plot = chart.getCategoryPlot(); plot.setDrawingSupplier(supplier); chart.setBackgroundPaint(Color.yellow); // set the stroke for each series... plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f)); plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 6.0f }, 0.0f)); plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); // customise the renderer... final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); // renderer.setDrawShapes(true); renderer.setItemLabelsVisible(true); // renderer.setLabelGenerator(new StandardCategoryLabelGenerator()); // customise the range axis... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setUpperMargin(0.12); return chart; }
From source file:edu.uara.wrappers.customcharts.CustomLineChart.java
/** * Set range axis to only display integer *//*from www. ja v a 2s . c o m*/ @Override public void setTickIntegerUnit() { CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); }
From source file:com.kodemore.freechart.KmSimpleLineChart.java
private JFreeChart createChart(XYDataset dataset) { PlotOrientation orientation = PlotOrientation.VERTICAL; boolean showsTooltips = false; boolean showsUrls = false; JFreeChart chart = ChartFactory.createXYLineChart(getTitle(), getAxisTitleX(), getAxisTitleY(), dataset, orientation, getShowsLegend(), showsTooltips, showsUrls); if (hasBackgroundColor()) chart.setBackgroundPaint(getBackgroundColor()); XYPlot plot;//from w w w . j av a2s .c o m plot = chart.getXYPlot(); if (hasPlotBackgroundColor()) plot.setBackgroundPaint(getPlotBackgroundColor()); if (hasPlotGridLineColor()) { Color color = getPlotGridLineColor(); plot.setDomainGridlinePaint(color); plot.setRangeGridlinePaint(color); } XYLineAndShapeRenderer renderer; renderer = new XYLineAndShapeRenderer(); KmList<KmSimpleLineChartGroup> groups = getGroups(); int n = groups.size(); for (int i = 0; i < n; i++) { KmSimpleLineChartGroup group = groups.getAt(i); renderer.setSeriesLinesVisible(i, group.getShowsLines()); renderer.setSeriesShapesVisible(i, group.getShowsShapes()); } plot.setRenderer(renderer); if (getIntegerUnitsX()) { NumberAxis rangeAxis; rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } if (getIntegerUnitsY()) { NumberAxis rangeAxis; rangeAxis = (NumberAxis) plot.getDomainAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.DotChart.java
/** * Creates a chart./*from w w w .j av a 2 s .c om*/ * * @param dataset the data for the chart. * * @return a chart. */ protected JFreeChart createChart1(XYDataset dataset) { //System.out.println("createChart1 called"); // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title "", // x axis label domain rangeLabel, // y axis label range dataset, // data PlotOrientation.HORIZONTAL, !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.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); // renderer.setSeriesShape(0, java.awt.Shape.round); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setBaseLinesVisible(false); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); //change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); rangeAxis.setUpperMargin(0.01); rangeAxis.setLowerMargin(0.01); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); //domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); domainAxis.setAutoRangeIncludesZero(true); domainAxis.setTickLabelsVisible(false); domainAxis.setTickMarksVisible(false); domainAxis.setUpperMargin(5); domainAxis.setLowerMargin(0.01); // OPTIONAL CUSTOMISATION COMPLETED. setYSummary(dataset); try { // System.out.println("setting the common RangeAxis to null"); common_rangeAxis = null; common_rangeAxis = (NumberAxis) rangeAxis.clone(); // System.out.println("creating the common RangeAxis"); } catch (CloneNotSupportedException e) { System.out.println("CloneNotSupportedException!, exception caught"); } return chart; }
From source file:org.testeditor.dashboard.TableDurationTrend.java
/** * designs and creates graph from data sets. * /* w ww .j a v a 2s. c o m*/ * @param objektList * list of all suite GoogleSucheSuite runs <AllRunsResult> * @param parent * composite parent * @param modelService * to find part label * @param window * trimmed window * @param app * org.eclipse.e4.ide.application */ @SuppressWarnings({ "serial" }) @Inject @Optional public void createControls(@UIEventTopic("Testobjektlist") List<AllRunsResult> objektList, Composite parent, EModelService modelService, MWindow window, MApplication app) { MPart mPart = (MPart) modelService.find("org.testeditor.ui.part.2", app); String[] arr = objektList.get(0).getFilePath().getName().split("\\."); String filenameSplitted = arr[arr.length - 1]; mPart.setLabel(translationService.translate("%dashboard.table.label.duration", CONTRIBUTOR_URI) + " " + filenameSplitted); mPart.setTooltip(translationService.translate("%dashboard.table.label.duration", CONTRIBUTOR_URI) + " " + objektList.get(0).getFilePath().getName()); parent.setLayout(new FillLayout()); // create the chart... chart = ChartFactory.createBarChart3D(null, // chart // title translationService.translate("%dashboard.table.label.duration.axis.dates", CONTRIBUTOR_URI), // domain // X axis // label translationService.translate("%dashboard.table.label.duration.axis.duration", CONTRIBUTOR_URI) + " h:m:s:ms", // range // Y axis // label createDataset(objektList), // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); // y axis right plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setNumberFormatOverride(new NumberFormat() { // show duration // values in // h:m:s:ms @Override public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { // return new StringBuffer(String.format("%f", number)); return new StringBuffer(String.format(formatDuration(number))); } @Override public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { // return new StringBuffer(String.format("%f", number)); return new StringBuffer(String.format(formatDuration(number))); } @Override public Number parse(String source, ParsePosition parsePosition) { return null; } }); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1} " + translationService.translate("%dashboard.table.label.duration.axis.duration", CONTRIBUTOR_URI) + ": {2}ms", NumberFormat.getInstance())); renderer.setDrawBarOutline(false); renderer.setMaximumBarWidth(.15); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(1.57)); Color color = toAwtColor(ColorConstants.COLOR_BLUE); final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, color, 0, 0, color); renderer.setSeriesPaint(0, gp0); chartComposite = new ChartComposite(parent, SWT.EMBEDDED); chartComposite.setSize(800, 800); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); chartComposite.setLayoutData(data); chartComposite.setHorizontalAxisTrace(false); chartComposite.setVerticalAxisTrace(false); chartComposite.setChart(chart); chartComposite.pack(true); chartComposite.setVisible(true); chartComposite.forceRedraw(); parent.layout(); }
From source file:com.mxgraph.examples.swing.chart.BarChartDemo1.java
public static JFreeChart createChart1(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("", // chart title "X-value", // domain axis label "Y-value", // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation true, // include legend true, // tooltips? false // URLs? );//from w ww . jav a 2 s . c om // 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(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setCategoryMargin(0.1);// categoryAxis.setUpperMargin(0.02); categoryAxis.setLowerMargin(0.02); // ****************************************************************** // 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()); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.10); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(true); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); // 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); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); renderer.setItemLabelAnchorOffset(10D); renderer.setItemLabelFont(new Font("", Font.PLAIN, 12)); renderer.setItemLabelsVisible(true); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 180)); // OPTIONAL CUSTOMISATION COMPLETED. chart.getTitle().setFont(new Font("", Font.BOLD, 16));// // domainAxis.setLabelFont(new Font("", Font.BOLD, 14)); // domainAxis.setTickLabelFont(new Font("", Font.PLAIN, 10)); // rangeAxis.setLabelFont(new Font("", Font.BOLD, 15)); chart.getLegend().setItemFont(new Font("", Font.BOLD, 15)); /** * chart.getTitle().setFont(new Font("",Font.BOLD,20));// // domainAxis.setLabelFont(new Font("",Font.BOLD,14)); // domainAxis.setTickLabelFont(new Font("",Font.BOLD,12)); // rangeAxis.setLabelFont(new Font("",Font.BOLD,15)); chart.getLegend().setItemFont(new Font("", Font.BOLD, 15)); */ return chart; }
From source file:jmemorize.gui.swing.panels.HistoryChartPanel.java
private JFreeChart createChart() { JFreeChart chart = ChartFactory.createStackedBarChart(null, // chart title null, // domain axis label Localization.get(LC.CHART_CARDS), // range axis label new DefaultCategoryDataset(), // data PlotOrientation.VERTICAL, // the plot orientation true, // include legend true, // tooltips false // urls );//from w w w . j a v a2 s .co m CategoryPlot plot = (CategoryPlot) chart.getPlot(); TickUnitSource tickUnits = NumberAxis.createIntegerTickUnits(); plot.getRangeAxis().setStandardTickUnits(tickUnits); //CHECK use locale setupRenderer(plot); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return chart; }
From source file:com.sami.chart.util.LineChartDemo1.java
/** * Creates a sample chart./*from www . j av a 2 s . c o m*/ * * @param dataset a dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createLineChart("Line Chart Demo 1", // chart title "Type", // 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... // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // legend.setShapeScaleX(1.5); // legend.setShapeScaleY(1.5); //legend.setDisplaySeriesLines(true); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); // customise the range axis... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // customise the renderer... final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); // renderer.setDrawShapes(true); renderer.setSeriesStroke(0, new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f)); renderer.setSeriesStroke(1, new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 6.0f }, 0.0f)); renderer.setSeriesStroke(2, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.agmip.ui.afsirs.frames.GraphOutput.java
public void addEvaporationAndTranspiration() { XYSeries etSeries = new XYSeries("ET"); double[][] ET = utils.getET(); for (int i = 0; i < 10/*ET.length*/; i++) { for (int j = 0; j < 10/*ET[0].length*/; j++) { etSeries.add(i * ET[0].length + j, ET[i][j]); }//from ww w .ja v a2 s . c o m } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(etSeries); JFreeChart chart = ChartFactory.createXYLineChart("Evaporation Transpiration", "Days", "Inches", dataset/*, PlotOrientation.VERTICAL, true, true, false*/); chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.GRAY); plot.setDomainGridlinePaint(Color.WHITE); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ChartPanel panel = new ChartPanel(chart); jTabbedPane1.addTab("Evaporation Transpiration", panel); }
From source file:org.jls.toolbox.math.chart.XYBlockChart.java
/** * Permet de crer le graphique partir des paramtres spcifis. *//* w w w . jav a 2 s.c om*/ private void createChart() { // Cration des axes NumberAxis xAxis = new NumberAxis(this.xTitle); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xAxis.setLabelFont(new Font("Dialog", Font.BOLD, 14)); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); NumberAxis yAxis = new NumberAxis(this.yTitle); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setLabelFont(new Font("Dialog", Font.BOLD, 14)); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); this.renderer = new XYBlockRenderer(); PaintScale scale = new GrayPaintScale(0, 10); this.renderer.setPaintScale(scale); // Cration de la courbe this.plot = new XYPlot(this.dataset, xAxis, yAxis, this.renderer); // Cration du graphique this.chart = new JFreeChart(this.title, this.plot); this.chart.removeLegend(); createPaintScaleLegend(scale); setColorGradient(Color.yellow, Color.red, 0, 1); }