/** * Test if switchedLog10 and switchedPow10 are inverses of each other */ public void testSwitchedLog10() { assertFalse("Axis should not allow negative values", this.axis.getAllowNegativesFlag()); assertEquals(Math.log(0.5) / LogarithmicAxis.LOG10_VALUE, this.axis.switchedLog10(0.5), EPSILON); checkSwitchedLogPowRoundTrip(20); checkSwitchedLogPowRoundTrip(10); checkSwitchedLogPowRoundTrip(5); checkSwitchedLogPowRoundTrip(2); checkSwitchedLogPowRoundTrip(1); checkSwitchedLogPowRoundTrip(0.5); checkSwitchedLogPowRoundTrip(0.2); checkSwitchedLogPowRoundTrip(0.0001); }
public JFreeChart showChart(IntervalXYDataset dataset) { JFreeChart chart = ChartFactory.createHistogram("", "", "", dataset, PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeAxis(new LogarithmicAxis("packetCount")); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setVisible(false); rangeAxis.setAutoTickUnitSelection(true); rangeAxis.setAutoRangeIncludesZero(true); DateAxis dAxis = new DateAxis(); dAxis.setRange((long) ControlsJPanel.QW_MIN * 1000L, (long) ControlsJPanel.QW_MAX * 1000L); plot.setDomainAxis(dAxis); plot.setRenderer(new XYAreaRenderer()); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); chart.setPadding(new RectangleInsets(0, 0, 0, 0)); return chart; }
/** * */ private static void createTestsResultsChartHelper(final String categoryLabel, final DefaultCategoryDataset dataset, final OutputStream out, final CategoryLabelPositions categoryLabelPosition) throws IOException { final JFreeChart chart = ChartFactory.createStackedAreaChart(null, categoryLabel, "Tests", dataset, PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); // change the auto tick unit selection to integer units only final CategoryPlot plot = chart.getCategoryPlot(); final LogarithmicAxis logarithmicAxis = new LogarithmicAxis("Tests"); logarithmicAxis.setStrictValuesFlag(false); logarithmicAxis.setAutoRangeIncludesZero(true); logarithmicAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setRangeAxis(logarithmicAxis); // final NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis(); // rotate X dates final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(categoryLabelPosition); // set area colors final StackedAreaRenderer area = (StackedAreaRenderer) plot.getRenderer(); area.setSeriesPaint(0, Color.RED); // first area area.setSeriesPaint(1, Color.PINK); // second area area.setSeriesPaint(2, Color.GREEN); // thirs area //plot.setRenderer(area); // write to reposnce final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); ChartUtilities.writeChartAsPNG(out, chart, IMG_WIDTH, IMG_HEIGHT, info); }
@Override public void init(ProcessContext ctx) throws Exception { super.init(ctx); dataset = new SimpleHistogramDataset(key); chart = ChartFactory.createHistogram( title, key, "#", dataset, PlotOrientation.VERTICAL, true, true, false ); chart.setBackgroundPaint(new Color(230, 230, 230)); XYPlot xyplot = (XYPlot) chart.getPlot(); if (logAxis) xyplot.setRangeAxis(new LogarithmicAxis("#")); chart.setTitle(title); xyplot.setForegroundAlpha(0.7F); xyplot.setBackgroundPaint(Color.WHITE); xyplot.setDomainGridlinePaint(new Color(150, 150, 150)); xyplot.setRangeGridlinePaint(new Color(150, 150, 150)); XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer(); xybarrenderer.setShadowVisible(false); xybarrenderer.setBarPainter(new StandardXYBarPainter()); // xybarrenderer.setDrawBarOutline(false); final ChartPanel chartPanel = new ChartPanel(chart); frame = new JFrame(); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(chartPanel, BorderLayout.CENTER); frame.setSize(width, height); frame.setVisible(true); }
/** * Creates a logarithmic axis. * @param minimum minimum value to be shown on the axis * @param maximum maximum value to be shown on the axis * @return the created axis */ protected NumberAxis createLogarithmicAxis(double minimum, double maximum) { NumberAxis axis = new LogarithmicAxis(""); axis.setAutoRange(false); ((LogarithmicAxis) axis).setStrictValuesFlag(false); axis.setRange(minimum, maximum); return axis; }
/** * Creates the chart. * * @return The created chart. * * @since 1.00 */ private JFreeChart createChart() { JFreeChart tChart = ChartFactory.createTimeSeriesChart( null, // chart title getXAxisLabel(), // domain axis label getYAxisLabel(), // range axis label dataset, // data true, // include legend false, // tooltips false); // urls tChart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) tChart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.GRAY); LogarithmicAxis rangeAxis = new LogarithmicAxis(getYAxisLabel()); rangeAxis.setStrictValuesFlag(false); plot.setRangeAxis(rangeAxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setPositiveArrowVisible(true); ValueAxis valueAxis = plot.getDomainAxis(); valueAxis.setPositiveArrowVisible(true); // add all timeseries to the dataset for (String key : timeSeries.keySet()) { dataset.addSeries(timeSeries.get(key)); } return tChart; }
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) { JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false); CategoryPlot plot = chart.getCategoryPlot(); Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white); plot.setBackgroundPaint(background); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); LogarithmicAxis rangeAxis = new LogarithmicAxis(null); rangeAxis.setStrictValuesFlag(false); rangeAxis.setAllowNegativesFlag(true); plot.setRangeAxis(rangeAxis); // Disable bar outlines. BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // Set up gradient paint for series. GradientPaint gp0 = new GradientPaint( 0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64) ); renderer.setSeriesPaint(0, gp0); // Rotate labels. CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // Set theme-specific colors. Color bgColor = getBackground(request); Color fgColor = getForeground(request); chart.setBackgroundPaint(bgColor); domainAxis.setTickLabelPaint(fgColor); domainAxis.setTickMarkPaint(fgColor); domainAxis.setAxisLinePaint(fgColor); rangeAxis.setTickLabelPaint(fgColor); rangeAxis.setTickMarkPaint(fgColor); rangeAxis.setAxisLinePaint(fgColor); return chart; }
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) { JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false); CategoryPlot plot = chart.getCategoryPlot(); Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white); plot.setBackgroundPaint(background); plot.setDomainGridlinePaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); LogarithmicAxis rangeAxis = new LogarithmicAxis(null); rangeAxis.setStrictValuesFlag(false); rangeAxis.setAllowNegativesFlag(true); // rangeAxis.setTickUnit(new NumberTickUnit(.1, new DecimalFormat("##0%"))); plot.setRangeAxis(rangeAxis); // Disable bar outlines. BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // Set up gradient paint for series. GradientPaint gp0 = new GradientPaint( 0.0f, 0.0f, Color.gray, 0.0f, 0.0f, new Color(0, 0, 64) ); renderer.setSeriesPaint(0, gp0); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, 11)); renderer.setItemLabelAnchorOffset(-45.0); renderer.setSeriesItemLabelPaint(0,Color.white); renderer.setBaseItemLabelPaint(Color.white); // Rotate labels. CategoryAxis domainAxis = plot.getDomainAxis(); // domainAxis.setCategoryLabelPositions(); // domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // Set theme-specific colors. Color bgColor = getBackground(request); Color fgColor = getForeground(request); chart.setBackgroundPaint(bgColor); domainAxis.setTickLabelPaint(fgColor); domainAxis.setTickMarkPaint(fgColor); domainAxis.setAxisLinePaint(fgColor); rangeAxis.setTickLabelPaint(fgColor); rangeAxis.setTickMarkPaint(fgColor); rangeAxis.setAxisLinePaint(fgColor); return chart; }
/** * Creates a new demo. * * @param title the frame title. */ public XYLogAxesDemo(final String title) { super(title); //Object[][][] data = new Object[3][50][2]; final XYSeries s1 = new XYSeries("Series 1"); final XYSeries s2 = new XYSeries("Series 2"); final XYSeries s3 = new XYSeries("Series 3"); // for (int i = 1; i <= 50; i++) { // s1.add(i, 1000 * Math.pow(i, -2)); // s2.add(i, 1000 * Math.pow(i, -3)); // s3.add(i, 1000 * Math.pow(i, -4)); // } for (int i = 1; i <= 50; i++) { s1.add(i, 10 * Math.exp(i / 5.0)); s2.add(i, 20 * Math.exp(i / 5.0)); s3.add(i, 30 * Math.exp(i / 5.0)); } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); dataset.addSeries(s3); final JFreeChart chart = ChartFactory.createXYLineChart( "Log Axis Demo", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, false ); final XYPlot plot = chart.getXYPlot(); final NumberAxis domainAxis = new NumberAxis("x"); final NumberAxis rangeAxis = new LogarithmicAxis("Log(y)"); plot.setDomainAxis(domainAxis); plot.setRangeAxis(rangeAxis); chart.setBackgroundPaint(Color.white); plot.setOutlinePaint(Color.black); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
private NumberAxis createAxis(final AxisType axisType, final String axisLabel) { NumberAxis numberAxis = axisType.equals(AxisType.LOGARITHMIC) ? new LogarithmicAxis(axisLabel) : new NumberAxis(axisLabel); numberAxis.setNumberFormatOverride((NumberFormat) numberFormat.clone()); return numberAxis; }