List of usage examples for org.jfree.chart.axis NumberAxis createIntegerTickUnits
public static TickUnitSource createIntegerTickUnits()
From source file:com.intel.stl.ui.main.view.PacketRateChartRangeUpdater.java
@Override public void updateChartRange(JFreeChart chart, long lower, long upper) { if (lower > upper) { return;//from w ww. jav a 2s. c om } XYPlot xyplot = (XYPlot) chart.getPlot(); NumberAxis range = (NumberAxis) xyplot.getRangeAxis(); range.setRangeWithMargins(lower, upper); range.setLowerBound(0); // If upper is less than 1000, don't do anything to convert the y-axis // label and // convert the unit tick. TickUnitSource unitSrc = createTickUnits(upper); if (unitSrc != null) { // Change tick values only if upper is above 1000. range.setStandardTickUnits(unitSrc); xyplot.getRenderer().setBaseToolTipGenerator( new PktsRateToolTipGenerator("<html><b>{0}</b><br> Time: {1}<br> Data: {2}</html>", Util.getHHMMSS(), new DecimalFormat("#,##0.00" + " " + unitDes))); } else { range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } // y-axis label setChartRangeLabel(range); }
From source file:vteaexploration.plottools.panels.XYChartPanel.java
private ChartPanel createChart(int x, int y, int l, String xText, String yText, String lText, Color imageGateColor) {/* w ww . j a v a 2 s .co m*/ XYShapeRenderer renderer = new XYShapeRenderer(); XYShapeRenderer rendererGate = new XYShapeRenderer(); PaintScaleLegend psl = new PaintScaleLegend(new LookupPaintScale(0, 100, new Color(0, 0, 0)), new NumberAxis("")); if (l > 0) { double max = getMaximumOfData((ArrayList) plotValues.get(1), l); double min = this.getMinimumOfData((ArrayList) plotValues.get(1), l); double range = max - min; if (max == 0) { max = 1; } //System.out.println("PROFILING-DETAILS: Points to plot: " + ((ArrayList) plotValues.get(1)).size()); LookupPaintScale ps = new LookupPaintScale(min, max + 100, new Color(0, 0, 0)); renderer.setPaintScale(ps); ps.add(min, TENPERCENT); ps.add(min + (1 * (range / 10)), XYChartPanel.TENPERCENT); ps.add(min + (2 * (range / 10)), XYChartPanel.TWENTYPERCENT); ps.add(min + (3 * (range / 10)), XYChartPanel.THIRTYPERCENT); ps.add(min + (4 * (range / 10)), XYChartPanel.FORTYPERCENT); ps.add(min + (5 * (range / 10)), XYChartPanel.FIFTYPERCENT); ps.add(min + (6 * (range / 10)), XYChartPanel.SIXTYPERCENT); ps.add(min + (7 * (range / 10)), XYChartPanel.SEVENTYPERCENT); ps.add(min + (8 * (range / 10)), XYChartPanel.EIGHTYPERCENT); ps.add(min + (9 * (range / 10)), XYChartPanel.NINETYPERCENT); ps.add(max, XYChartPanel.ALLPERCENT); NumberAxis lAxis = new NumberAxis(lText); lAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); psl = new PaintScaleLegend(ps, lAxis); psl.setBackgroundPaint(VTC._VTC.BACKGROUND); psl.setPosition(RectangleEdge.RIGHT); psl.setMargin(4, 4, 40, 4); psl.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); } else { renderer.setBaseFillPaint(TENPERCENT); } Ellipse2D shape = new Ellipse2D.Double(0, 0, size, size); Ellipse2D shapeGate = new Ellipse2D.Double(-2, -2, size + 4, size + 4); renderer.setBaseShape(shape); rendererGate.setBaseShape(shapeGate); NumberAxis xAxis = new NumberAxis(""); NumberAxis yAxis = new NumberAxis(""); xAxis.setAutoRangeIncludesZero(false); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(createXYZDataset((ArrayList) plotValues.get(1), x, y, l), xAxis, yAxis, renderer); plot.getDomainAxis(); plot.getRangeAxis(); plot.setDomainPannable(false); plot.setRangePannable(false); plot.setRenderer(0, renderer); plot.setRenderer(1, rendererGate); plot.setDataset(0, createXYZDataset((ArrayList) plotValues.get(1), x, y, l)); if (imageGate) { roiCreated(impoverlay); XYZDataset set = createXYZDataset(ImageGateOverlay, x, y, l); plot.setDataset(1, set); plot.setRenderer(1, new XYShapeRenderer() { @Override protected java.awt.Paint getPaint(XYDataset dataset, int series, int item) { return imageGateOutline; } @Override public Shape getItemShape(int row, int col) { return new Ellipse2D.Double(-2, -2, size + 4, size + 4); } }); } //System.out.println("PROFILING: Generating plot with " + plot.getDatasetCount() + " datasets."); //System.out.println("PROFILING: Generating plot with " + ImageGateOverlay.size() + " objects gated."); try { if (getRangeofData((ArrayList) plotValues.get(1), x) > 16384) { LogAxis logAxisX = new LogAxis(); logAxisX.setAutoRange(true); plot.setDomainAxis(logAxisX); } if (getRangeofData((ArrayList) plotValues.get(1), y) > 16384) { LogAxis logAxisY = new LogAxis(); logAxisY.setAutoRange(true); plot.setRangeAxis(logAxisY); } } catch (NullPointerException e) { } ; JFreeChart chart = new JFreeChart("Plot of " + xText + " vs. " + yText, plot); chart.removeLegend(); //LUT if (l > 0) chart.addSubtitle(psl); //notifiyUpdatePlotWindowListeners(); return new ChartPanel(chart, true, true, false, false, true); }
From source file:org.korosoft.hudson.plugin.dynamic.CukeTestResultChartAction.java
private JFreeChart createChart(List<ChartBuildEntry> history) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String seriesFailed = "Failed"; String seriesPassed = "Passed"; String seriesRegression = "Failed [Regression]"; String seriesImprovement = "Passed [Improvement]"; dataset.setValue(0, seriesFailed, "0"); dataset.setValue(0, seriesRegression, "0"); dataset.setValue(0, seriesImprovement, "0"); dataset.setValue(0, seriesPassed, "0"); dataset.removeColumn(0);/* w w w . ja v a 2s. com*/ for (ChartBuildEntry entry : history) { final String buildLabel = Integer.toString(entry.buildNo); dataset.setValue(entry.failed, seriesFailed, buildLabel); dataset.setValue(entry.regressed, seriesRegression, buildLabel); dataset.setValue(entry.improved, seriesImprovement, buildLabel); dataset.setValue(entry.passed, seriesPassed, buildLabel); } JFreeChart chart = ChartFactory.createStackedAreaChart(null, "Build #", "Number of scenarios", dataset, PlotOrientation.VERTICAL, true, true, true); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.getDomainAxis().setAxisLineVisible(false); plot.getDomainAxis().setCategoryMargin(0); plot.getDomainAxis().setUpperMargin(0); plot.getDomainAxis().setLowerMargin(0); plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getRenderer().setSeriesPaint(0, new Color(0xFF8080)); plot.getRenderer().setSeriesPaint(1, new Color(0xFF0000)); plot.getRenderer().setSeriesPaint(2, new Color(0x0000C0)); plot.getRenderer().setSeriesPaint(3, new Color(0x8080FF)); return chart; }
From source file:at.ac.tuwien.inso.subcat.ui.widgets.TrendChart.java
private void initCharts() { dataset = new DefaultCategoryDataset(); // XY:s/*from w ww. j a va 2s . c om*/ NumberAxis rangeAxis1 = new NumberAxis("Values"); rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer renderer1 = new LineAndShapeRenderer(); renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); trendPlot = new CategoryPlot(dataset, null, rangeAxis1, renderer1); trendPlot.setDomainGridlinesVisible(true); // Box: NumberAxis rangeAxis2 = new NumberAxis("Values"); rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer2 = new BarRenderer(); renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); sizePlot = new CategoryPlot(dataset, null, rangeAxis2, renderer2); sizePlot.setDomainGridlinesVisible(true); }
From source file:eu.hydrologis.jgrass.charting.impl.JGrassXYBarChart.java
/** * Toggel the axis ticks to show a standard thing or just integers * /* w w w . j a v a 2 s.c o m*/ * @param showIntegers - flag to activate integer ticks */ public void toggleIntegerTicks(boolean showIntegers) { if (thePlot != null) { NumberAxis rangeAxis = (NumberAxis) ((XYPlot) thePlot).getRangeAxis(); if (showIntegers) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } else { rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); } } }
From source file:edu.ucla.stat.SOCR.chart.demo.AreaChartDemo1.java
/** * Creates a Area chart.//from w ww .j a v a 2s . co m * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createAreaChart(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); if (isDemo) { TextTitle subtitle = 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."); subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12)); subtitle.setPosition(RectangleEdge.TOP); subtitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.05, 0.05, 0.05, 0.05)); subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM); chart.addSubtitle(subtitle); } CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(0.5f); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); AreaRenderer renderer = (AreaRenderer) plot.getRenderer(); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); if (isDemo) { domainAxis.addCategoryLabelToolTip("Type 1", "The first type."); domainAxis.addCategoryLabelToolTip("Type 2", "The second type."); domainAxis.addCategoryLabelToolTip("Type 3", "The third type."); } NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. setCategorySummary(dataset); return chart; }
From source file:userinterface.graph.Histogram.java
/** * Initialize all the fields of the Histogram and set some properties *//*from ww w . j a va 2 s . com*/ public void init() { keyToSeries = new HashMap<SeriesKey, XYIntervalSeries>(); keyToGraphSeries = new HashMap<SeriesKey, SeriesSettings>(); chart = this.getChart(); plot = chart.getXYPlot(); plot.setBackgroundPaint((Paint) Color.white); plot.setDrawingSupplier(new DefaultDrawingSupplier(SeriesSettings.DEFAULT_PAINTS, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, SeriesSettings.DEFAULT_SHAPES)); seriesCollection = (XYIntervalSeriesCollection) plot.getDataset(); maxProb = 1.0; minProb = 0.0; numOfBuckets = 10; // default value, can be altered plot.setRenderer(new ClusteredXYBarRenderer()); addToolTip(); ticks = new ArrayList<Double>(); setCustomDomainAxis(); plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); }
From source file:com.mentor.questa.vrm.jenkins.QuestaVrmHostAction.java
private JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title "Relative time", // unused "count", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls );/*from w ww . ja v a 2s .c o m*/ chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); 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()); StackedAreaRenderer ar = new StackedAreaRenderer2() { private long getTime(CategoryDataset dataset, int column) { Long offset = (Long) dataset.getColumnKey(column); return getRegressionResult().getRegressionBegin().getTime() + offset * 1000; } @Override public String generateURL(CategoryDataset dataset, int row, int column) { return "javascript:getSummary(" + getTime(dataset, column) + ");"; } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { String host = (String) dataset.getRowKey(row); Date date = new Date(getTime(dataset, column)); int value = (Integer) dataset.getValue(row, column); return value + " on " + host + "@" + date.toString(); } }; plot.setRenderer(ar); // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java
private static JFreeChart createStackedBarChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createStackedBarChart("StackedBar Chart Demo 1", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation true, // include legend true, // tooltips? false // URLs? );//from ww w .j a va2s. c om chart.setBackgroundPaint(Color.white); 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); // 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); return chart; }
From source file:eu.hydrologis.jgrass.charting.impl.JGrassXYLineChart.java
/** * Toggel the axis ticks to show a standard thing or just integers * /*from w w w.j a v a2 s. co m*/ * @param showIntegers - flag to activate integer ticks */ public void toggleIntegerTicks(boolean showIntegers) { if (thePlot != null) { final NumberAxis rangeAxis = (NumberAxis) ((XYPlot) thePlot).getRangeAxis(); if (showIntegers) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } else { rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); } } }