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

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

Introduction

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

Prototype

public void setNumberFormatOverride(NumberFormat formatter) 

Source Link

Document

Sets the number format override.

Usage

From source file:info.novatec.testit.livingdoc.confluence.macros.historic.AggregationExecutionChartBuilder.java

@SuppressWarnings("deprecation")
private void customizeChart(JFreeChart chart) throws IOException {
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(settings.isBorder());

    TextTitle chartTitle = chart.getTitle();
    customizeTitle(chartTitle, DEFAULT_TITLE_FONT);

    addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT);
    addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata"));

    StackedBarRenderer renderer = new StackedBarRenderer(true);
    plot.setRenderer(renderer);//  w  ww  .  j  a v  a  2 s.  c om

    int index = 0;
    renderer.setSeriesPaint(index++, GREEN_COLOR);
    if (settings.isShowIgnored()) {
        renderer.setSeriesPaint(index++, Color.yellow);
    }
    renderer.setSeriesPaint(index, Color.red);

    renderer.setToolTipGenerator(new DefaultTooltipGenerator());
    renderer.setItemURLGenerator(new CategoryURLGenerator() {

        @Override
        public String generateURL(CategoryDataset data, int series, int category) {
            Comparable<?> valueKey = data.getColumnKey(category);
            ChartLongValue value = (ChartLongValue) valueKey;
            return "javascript:" + settings.getExecutionUID() + "_showHistoricChart('" + value.getId() + "');";
        }
    });

    CategoryAxis domainAxis = plot.getDomainAxis();
    customizeAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setCategoryMargin(0.01);

    ValueAxis rangeAxis = plot.getRangeAxis();
    customizeAxis(rangeAxis);
    rangeAxis.setLowerBound(0);
    rangeAxis.setUpperBound(1.0);

    if (rangeAxis instanceof NumberAxis) {
        NumberAxis numberAxis = (NumberAxis) rangeAxis;
        numberAxis.setTickUnit(new NumberTickUnit(.10));
        numberAxis.setNumberFormatOverride(PERCENT_FORMATTER);
    }

    plot.setForegroundAlpha(0.8f);
}

From source file:org.yccheok.jstock.gui.portfolio.DividendSummaryBarChartJDialog.java

private JFreeChart createBarChart(CategoryDataset dataset) {
    final int size = ((DefaultCategoryDataset) dataset).getColumnCount();
    double total = 0.0;
    for (int i = 0; i < size; i++) {
        total += ((DefaultCategoryDataset) dataset).getValue(0, i).doubleValue();
    }/* w ww .j  av a2s .c o m*/

    final JStockOptions jStockOptions = JStock.instance().getJStockOptions();
    final String currencySymbol = jStockOptions.getCurrencySymbol(jStockOptions.getCountry());
    // Use apostrophes to escape currencySymbol. If currencySymbol contains
    // apostrophes, we may need to escape those by doubling them.
    final NumberFormat currencyFormat = new DecimalFormat("'" + currencySymbol.replace("'", "''") + "'#,##0");

    final String title = MessageFormat.format(
            org.yccheok.jstock.internationalization.GUIBundle
                    .getString("DividendSummaryBarChartJDialog_DividendByYear_template"),
            this.jComboBox1.getSelectedItem(), currencyFormat.format(total));
    final String domain_label = org.yccheok.jstock.internationalization.GUIBundle
            .getString("DividendSummaryBarChartJDialog_Year");
    final String range_label = org.yccheok.jstock.internationalization.GUIBundle
            .getString("DividendSummaryBarChartJDialog_Dividend");
    // create the chart...
    final JFreeChart freeChart = ChartFactory.createBarChart(title, // chart title
            domain_label, // domain axis label
            range_label, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );
    org.yccheok.jstock.charting.Utils.applyChartTheme(freeChart);
    NumberAxis rangeAxis1 = (NumberAxis) ((CategoryPlot) freeChart.getPlot()).getRangeAxis();
    rangeAxis1.setNumberFormatOverride(currencyFormat);
    return freeChart;
}

From source file:mil.tatrc.physiology.utilities.csv.plots.CSVPlotTool.java

public void formatXYPlot(JFreeChart chart, Paint bgColor) {
    XYPlot plot = (XYPlot) chart.getPlot();

    //For Scientific notation
    NumberFormat formatter = new DecimalFormat("0.######E0");

    for (int i = 0; i < plot.getDomainAxisCount(); i++) {
        plot.getDomainAxis(i).setLabelFont(largeFont);
        plot.getDomainAxis(i).setTickLabelFont(smallFont);
        plot.getDomainAxis(i).setLabelPaint(bgColor == Color.red ? Color.white : Color.black);
        plot.getDomainAxis(i).setTickLabelPaint(bgColor == Color.red ? Color.white : Color.black);
    }//from   w ww  .  ja  v  a 2  s. c  o m
    for (int i = 0; i < plot.getRangeAxisCount(); i++) {
        plot.getRangeAxis(i).setLabelFont(largeFont);
        plot.getRangeAxis(i).setTickLabelFont(smallFont);
        plot.getRangeAxis(i).setLabelPaint(bgColor == Color.red ? Color.white : Color.black);
        plot.getRangeAxis(i).setTickLabelPaint(bgColor == Color.red ? Color.white : Color.black);
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(i);
        rangeAxis.setNumberFormatOverride(formatter);
    }

    //White background outside of plottable area
    chart.setBackgroundPaint(bgColor);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    chart.getLegend().setItemFont(smallFont);
    chart.getTitle().setFont(largeFont);
    chart.getTitle().setPaint(bgColor == Color.red ? Color.white : Color.black);
}

From source file:com.sixrr.metrics.ui.charts.HistogramDialog.java

private JFreeChart createChart(IntervalXYDataset dataset, boolean isIntegral) {
    final String title = getTitle();
    final NumberAxis xAxis = new NumberAxis();
    if (isIntegral) {
        xAxis.setTickUnit(new NumberTickUnit(1.0));
    }//from w w w.  j a v  a2s  .  c o m
    if (metricType == MetricType.Ratio || metricType == MetricType.RecursiveRatio) {
        xAxis.setNumberFormatOverride(new PercentFormatter());
    }

    final XYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator();

    final XYItemRenderer renderer = new XYBarRenderer();
    renderer.setToolTipGenerator(tooltipGenerator);
    renderer.setURLGenerator(null);

    final ValueAxis yAxis = new NumberAxis();
    final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    return new JFreeChart(title, JFreeChartConstants.DEFAULT_TITLE_FONT, plot, true);
}

From source file:com.signalcollect.sna.gephiconnectors.SignalCollectGephiConnector.java

/**
 * Gets the Label Propagation in the graph and creates a chart out of it
 * /*  w w  w. jav  a2s.  c  om*/
 * @throws IOException
 */
public void getLabelPropagation() throws IOException {

    Map<Integer, Map<String, Integer>> m = LabelPropagation.run(graph, signalSteps.get());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    final JFreeChart chart = ChartFactory.createStackedBarChart("Evolving Label Propagation", "Signal Step",
            null, dataset, PlotOrientation.VERTICAL, false, false, false);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    StackedBarRenderer renderer = new StackedBarRenderer();

    plot.setDataset(dataset);
    plot.setRenderer(renderer);
    renderer.setBaseItemLabelGenerator(
            new StandardCategoryItemLabelGenerator("{0} {2} {3}", NumberFormat.getInstance()));
    renderer.setBaseItemLabelsVisible(true);
    if (signalSteps.get() > 10) {
        long stepInterval = Math.round(new Double(signalSteps.get().doubleValue() / 10d));
        for (int i = (int) stepInterval; i <= signalSteps.get(); i += stepInterval) {
            Set<Map.Entry<String, Integer>> entrySet = m.get(new Integer(i)).entrySet();
            for (Map.Entry<String, Integer> subentry : entrySet) {
                dataset.addValue(subentry.getValue(), subentry.getKey(), new Integer(i));
            }
        }
    } else {
        for (Map.Entry<Integer, Map<String, Integer>> entry : m.entrySet()) {
            for (Map.Entry<String, Integer> subentry : entry.getValue().entrySet()) {
                dataset.addValue(subentry.getValue(), subentry.getKey(), entry.getKey());
            }
        }
    }
    renderer.setRenderAsPercentages(true);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1200, 600));
    ApplicationFrame f = new ApplicationFrame("Label Propagation");
    f.setContentPane(chartPanel);
    f.pack();
    f.setVisible(true);
}

From source file:org.vast.stt.renderer.JFreeChart.XYPlotBuilder.java

public void createPlot(ChartScene scene) {
    this.scene = scene; //  scene contains the axis info, so passing it in here for now

    datasetCount = 0;//from   w  w  w .  j a va  2 s  .c  o m
    rangeAxisCount = 0;
    currentItem = null;
    axisTable.clear();
    plot = new XYPlot();

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    String axisName = "Time (s)";
    NumberAxis domainAxis = new NumberAxis(axisName);
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setAutoRange(false);
    domainAxis.setNumberFormatOverride(new DateFormat());
    domainAxis.setTickLabelInsets(new RectangleInsets(0, 30, 0, 30));
    domainAxis.setLowerBound(scene.getDomainMin());
    domainAxis.setUpperBound(scene.getDomainMax());
    plot.setDomainAxis(datasetCount, domainAxis);
}

From source file:com.pureinfo.srm.reports.impl.CategoryChartBuilder.java

/**
 * @see com.pureinfo.srm.reports.IChartBuilder#buildChart(java.util.List,
 *      int, java.lang.String)//from w w  w. j  ava  2s.  c o  m
 */
public JFreeChart buildChart() {
    CategoryDataset dataset = createDataset();

    JFreeChart jfreechart = MyChartFactory.createBarChart3D(null, m_sXAxisName, m_sYXxisName, dataset,
            PlotOrientation.VERTICAL, false, false, false);

    CategoryPlot categoryplot = jfreechart.getCategoryPlot();
    jfreechart.setBackgroundPaint(Color.white);
    categoryplot.setDomainGridlinesVisible(false);
    categoryplot.setRangeGridlinesVisible(true);

    categoryplot.setForegroundAlpha(0.8f);
    categoryplot.setDrawingSupplier(new DefaultDrawingSupplier(MyPaintMgr.getPaints(),
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
    CategoryAxis categoryAxisX = categoryplot.getDomainAxis();
    categoryAxisX.setTickLabelsVisible(true);
    categoryAxisX.setLabel(null);
    categoryAxisX.setMaximumCategoryLabelWidthRatio(.8f);
    ValueAxis categoryAxisY = categoryplot.getRangeAxis();
    categoryAxisY.setVerticalTickLabels(false);

    //        categoryplot.setDrawSharedDomainAxis(false);
    categoryAxisX.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));

    BarRenderer3D barrenderer3d = (BarRenderer3D) categoryplot.getRenderer();
    barrenderer3d.setDrawBarOutline(false);
    barrenderer3d.setItemLabelsVisible(true);

    barrenderer3d.setBaseItemLabelsVisible(false);
    barrenderer3d.setSeriesVisible(Boolean.FALSE);

    //CategoryPlot categoryPlot = jfreechart.getCategoryPlot();
    //        categoryPlot.setBackgroundPaint(Color.lightGray);
    //        categoryPlot.setDomainGridlinePaint(Color.white);
    //        categoryPlot.setRangeGridlinePaint(Color.white);
    //
    //        BarRenderer barRenderer = (BarRenderer) categoryPlot.getRenderer();
    //        barRenderer.setDrawBarOutline(false);
    //        barRenderer.setMaxBarWidth(0.03);
    //        GradientPaint gradientPaint = new GradientPaint(0.0F, 0.0F,
    // Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    //        barRenderer.setSeriesPaint(0, gradientPaint);

    DecimalFormat format = null;
    if (m_dblMaxData > 1) {
        format = new DecimalFormat("#,###");
    } else {
        StringBuffer sb = new StringBuffer();
        sb.append("0.00#");
        for (double i = m_dblMaxData; i != 0 && i < 1; i *= 10f) {
            sb.append("#");
        }
        format = new DecimalFormat(sb.toString());
    }
    fillChartInfo(dataset, format);
    barrenderer3d.setMaxBarWidth(8.0 / m_ChartInfo.getChartSize().x);
    NumberAxis numberAxis = (NumberAxis) categoryplot.getRangeAxis(0);
    numberAxis.setUpperMargin(0.149999999999D);
    numberAxis.setNumberFormatOverride(format);

    categoryAxisX.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    NumberAxis dataNumberAxis = (NumberAxis) categoryplot.getRangeAxisForDataset(0);
    dataNumberAxis.setUpperMargin(0.149999999999D);
    dataNumberAxis.setNumberFormatOverride(format);

    //        CategoryItemRenderer renderer = categoryPlot.getRenderer();
    //        CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{2}", format);
    //        renderer.setItemLabelGenerator(generator);
    //        renderer.setItemLabelFont(new Font("Serif", 0, 9));
    //        renderer.setItemLabelsVisible(true);
    return jfreechart;
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.StackedBarChartRenderer.java

/**
 * /*from w ww  .jav  a2  s  . c  o  m*/
 */
public void createChart() {

    CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset();
    report = ChartFactory.createStackedBarChart(this.datasetStrategy.getTitle(),
            this.datasetStrategy.getYAxisLabel(), this.datasetStrategy.getXAxisLabel(), categorydataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    // report.setBackgroundPaint( Color.lightGray );
    report.setAntiAlias(false);
    report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d));
    CategoryPlot categoryplot = (CategoryPlot) report.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.lightGray);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    if (datasetStrategy instanceof CloverBarChartStrategy
            || datasetStrategy instanceof MultiCloverBarChartStrategy) {
        numberaxis.setRange(0.0D, StackedBarChartRenderer.NUMBER_AXIS_RANGE);
        numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    numberaxis.setLowerMargin(0.0D);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setBaseItemLabelsVisible(true);
    stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setBaseItemLabelFont(StackedBarRenderer.DEFAULT_VALUE_LABEL_FONT.deriveFont(Font.BOLD));
    int height = (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * 2)
            + ChartUtils.STANDARD_BARCHART_ADDITIONAL_HEIGHT + 10;
    if (height > ChartUtils.MINIMUM_HEIGHT) {
        super.setHeight(height);
    } else {
        super.setHeight(ChartUtils.MINIMUM_HEIGHT);
    }
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) {
        stackedbarrenderer.setSeriesPaint(i, paints[i]);
    }

}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.SurefirePercentAxisDecorator.java

/**
 *
 *///from w  ww.j a v  a 2  s  .c  om
public void createChart() {

    XYPlot xyplot = (XYPlot) report.getPlot();
    if (this.decoratedChart instanceof TimeChartRenderer && this.results != null && !this.results.isEmpty()) {

        Iterator iter = this.results.iterator();
        TimeSeriesCollection defaultdataset = new TimeSeriesCollection();
        TimeSeries s1 = new TimeSeries("% success", Day.class);

        while (iter.hasNext()) {
            SurefireReportBean surefire = (SurefireReportBean) iter.next();
            Date date = surefire.getDateGeneration();
            s1.addOrUpdate(new Day(TimePeriod.DAY.normalize(date)), surefire.getSucessRate() / PCENT);

        }

        defaultdataset.addSeries(s1);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setSeriesPaint(0, ChartColor.DARK_BLUE);
        renderer.setBaseShapesVisible(true);
        renderer.setDrawOutlines(true);
        StandardXYItemLabelGenerator labelgenerator = new StandardXYItemLabelGenerator(
                StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, TimePeriod.DAY.getDateFormat(),
                NumberFormat.getPercentInstance(Locale.getDefault()));
        renderer.setBaseItemLabelGenerator(labelgenerator);
        renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, ITEM_LABEL_FONT_SIZE));
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BASELINE_RIGHT));

        renderer.setBaseStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

        LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(0));
        legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle.setFrame(new BlockBorder());
        legendtitle.setBackgroundPaint(ChartColor.WHITE);

        LegendTitle legendtitle1 = new LegendTitle(renderer);
        legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle1.setFrame(new BlockBorder());
        legendtitle1.setBackgroundPaint(ChartColor.WHITE);

        BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
        blockcontainer.add(legendtitle, RectangleEdge.LEFT);
        blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
        blockcontainer.add(new EmptyBlock(BLOCK_CONTAINER_WIDTH, 0.0D));

        CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
        compositetitle.setPosition(RectangleEdge.BOTTOM);

        report.clearSubtitles();
        report.addSubtitle(compositetitle);

        xyplot.setDataset(1, defaultdataset);

        NumberAxis valueaxis = new NumberAxis("% success");
        valueaxis.setLowerMargin(0.0D);
        valueaxis.setUpperMargin(AXIS_UPPER_MARGIN);
        valueaxis.setRangeWithMargins(0.0D, 1.0D);
        valueaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
        xyplot.setRangeAxis(1, valueaxis);
        xyplot.mapDatasetToRangeAxis(1, 1);
        xyplot.setRenderer(1, renderer);
    }

}

From source file:org.vimarsha.ui.TimeSlicedClassiferForm.java

private JFreeChart createChart(XYSeriesCollection dataSet, String chartTitle) {
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, "Time slice number", "Classification",
            dataSet, PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();//  w w w  .  j ava 2s  .com
    NumberAxis range = (NumberAxis) plot.getRangeAxis();

    range.setRange(0, 1.1);
    TickUnits units = new TickUnits();
    units.add(new NumberTickUnit(0));
    units.add(new NumberTickUnit(0.5));
    units.add(new NumberTickUnit(1));

    range.setStandardTickUnits(units);
    range.setNumberFormatOverride(new DecimalFormat() {
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
            if (number == 1)
                return toAppendTo.append("badfs");
            else if (number == 0.5)
                return toAppendTo.append("badma");
            else
                return toAppendTo.append("good");
        }
    });

    return chart;
}