Example usage for org.jfree.chart.axis NumberAxis getStandardTickUnits

List of usage examples for org.jfree.chart.axis NumberAxis getStandardTickUnits

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis getStandardTickUnits.

Prototype

public TickUnitSource getStandardTickUnits() 

Source Link

Document

Returns the source for obtaining standard tick units for the axis.

Usage

From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpressionTest.java

@Test
public void testStandardTickUnitsApplyFormat() throws Exception {
    NumberAxis axis = new NumberAxis();
    final TickUnits standardTickUnits = (TickUnits) axis.getStandardTickUnits();
    final double initialFirstTickUnitSize = standardTickUnits.get(0).getSize();
    assertTickUnitSizeByPattern("", initialFirstTickUnitSize);

    assertTickUnitSizeByPattern("#,###", 1.0);
    assertTickUnitSizeByPattern("#", 1.0);
    assertTickUnitSizeByPattern("#.#", 0.1);
    assertTickUnitSizeByPattern("#.####", 1.0E-4);
}

From source file:com.idealista.solrmeter.view.statistic.HistogramChartPanel.java

private Component createChartPanel() {
    XYBarDataset xyBarDataset = new XYBarDataset(xyDataset, BAR_WIDTH);
    NumberAxis xaxis = new NumberAxis(I18n.get("statistic.histogramChartPanel.time"));
    NumberAxis yaxis = new NumberAxis(I18n.get("statistic.histogramChartPanel.numberOfQueries"));

    xaxis.setStandardTickUnits(/*w w w  . j ava2  s.  c  o  m*/
            new ChartUtils.LowerBoundedTickUnitSource(xaxis.getStandardTickUnits(), LOWER_TICK_UNIT));

    XYPlot plot = new XYPlot(xyBarDataset, xaxis, yaxis, new XYBarRenderer());

    JFreeChart chart = new JFreeChart(I18n.get("statistic.histogramChartPanel.title"), null, plot, false);

    ChartPanel chartPanel = new ChartPanel(chart);

    chartPanel.setBorder(CHART_BORDER);
    chartPanel.setMinimumDrawHeight(0);
    chartPanel.setMinimumDrawWidth(0);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);

    return chartPanel;
}

From source file:com.idealista.solrmeter.view.statistic.QueryTimeHistoryPanel.java

/**
 * Creates and initializes the chart panel.
 *//* w w  w.  ja v  a  2s. c o m*/
public ChartPanel createChartPanel() {
    XYBarDataset barDataset = new XYBarDataset(dataset, BAR_WIDTH);
    NumberAxis xaxis = new NumberAxis(I18n.get("statistic.queryTimeHistoryPanel.time"));
    NumberAxis yaxis = new NumberAxis(I18n.get("statistic.queryTimeHistoryPanel.averageQueryTime"));

    xaxis.setStandardTickUnits(
            new ChartUtils.LowerBoundedTickUnitSource(xaxis.getStandardTickUnits(), LOWER_TICK_UNIT));

    XYPlot plot = new XYPlot(barDataset, xaxis, yaxis, new XYBarRenderer());

    JFreeChart chart = new JFreeChart(I18n.get("statistic.queryTimeHistoryPanel.queryHistory"), null, plot,
            false);

    ChartPanel chartPanel = new ChartPanel(chart);

    chartPanel.setBorder(CHART_BORDER);
    chartPanel.setMinimumDrawHeight(0);
    chartPanel.setMinimumDrawWidth(0);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);

    return chartPanel;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpressionTest.java

private void assertTickUnitSizeByPattern(String pattern, double tickUnitSize) {
    NumberAxis axis = new NumberAxis();
    DecimalFormat formatter = new DecimalFormat(pattern, new DecimalFormatSymbols(new Locale("en_US")));
    expression.standardTickUnitsApplyFormat(axis, formatter);
    final TickUnits standardTickUnits = (TickUnits) axis.getStandardTickUnits();
    // first n standard tick unit elements should be removed
    Assert.assertEquals(tickUnitSize, standardTickUnits.get(0).getSize(), 0.0000000001);
}

From source file:net.sf.jasperreports.charts.util.ChartUtil.java

public void setAutoTickUnit(NumberAxis numberAxis) {
    if (numberAxis.isAutoTickUnitSelection()) {
        Range range = numberAxis.getRange();
        if (range.getLength() >= AUTO_TICK_UNIT_THRESHOLD) {
            // this is a workaround for a floating point error makes JFreeChart
            // select tick units that are too small when the values are very large
            double autoSize = range.getLength() / AUTO_TICK_UNIT_THRESHOLD;
            TickUnit unit = numberAxis.getStandardTickUnits().getCeilingTickUnit(autoSize);
            numberAxis.setTickUnit((NumberTickUnit) unit, false, false);
        }// w  ww . ja  va2  s  .c om
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.AbstractChartExpression.java

/**
 * Reduces standard tick unit array to meet  formatting  precision and avoid duplicated values (PRD-5821)
 *
 * @return/*www  .j ava 2 s  .c  om*/
 */
protected void standardTickUnitsApplyFormat(NumberAxis numberAxis, NumberFormat format) {
    final TickUnits standardTickUnits = (TickUnits) numberAxis.getStandardTickUnits();
    TickUnits cutTickUnits = new TickUnits();
    double formatterMinSize = 1 / Math.pow(10, format.getMaximumFractionDigits());
    for (int i = 0; i < standardTickUnits.size(); i++) {
        if (Double.compare(standardTickUnits.get(i).getSize(), formatterMinSize) >= 0) {
            cutTickUnits.add(new NumberTickUnit(standardTickUnits.get(i).getSize()));
        }
    }
    numberAxis.setStandardTickUnits(cutTickUnits);
}