Example usage for org.jfree.chart.labels StandardCategoryItemLabelGenerator StandardCategoryItemLabelGenerator

List of usage examples for org.jfree.chart.labels StandardCategoryItemLabelGenerator StandardCategoryItemLabelGenerator

Introduction

In this page you can find the example usage for org.jfree.chart.labels StandardCategoryItemLabelGenerator StandardCategoryItemLabelGenerator.

Prototype

public StandardCategoryItemLabelGenerator(String labelFormat, DateFormat formatter) 

Source Link

Document

Creates a new generator with the specified date formatter.

Usage

From source file:org.jfree.chart.demo.ItemLabelDemo3.java

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Item Label Demo 3", "Category", "Value",
            categorydataset, PlotOrientation.VERTICAL, false, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.white);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setVisible(false);//from   www. j  a v  a 2 s.c o m
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperMargin(0.14999999999999999D);
    CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
    StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator(
            "{1}", NumberFormat.getInstance());
    categoryitemrenderer.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator);
    categoryitemrenderer.setBaseItemLabelFont(new Font("SansSerif", 0, 12));
    categoryitemrenderer.setBaseItemLabelsVisible(true);
    categoryitemrenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.CENTER, TextAnchor.CENTER, -1.5707963267948966D));
    return jfreechart;
}

From source file:de.fub.maps.project.detector.model.statistics.BarChartPanel.java

/**
 * Creates new form StatisticSegmentLengthBarChart
 *//* ww w .j  a v a 2 s .c o  m*/
public BarChartPanel() {
    initComponents();
    barChart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.VERTICAL, true, true,
            true);
    plot = barChart.getCategoryPlot();

    BarRenderer barRenderer = new BarRenderer();
    barRenderer.setMaximumBarWidth(.05);
    barRenderer.setBasePaint(Color.BLUE);
    barRenderer.setAutoPopulateSeriesPaint(false);
    barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    barRenderer.setBarPainter(new StandardBarPainter());
    barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat()));
    barRenderer.setBaseItemLabelsVisible(true);
    plot.setRenderer(barRenderer);
    plot.getDomainAxis().setMaximumCategoryLabelLines(3);
    plot.setBackgroundPaint(Color.white);
    barChart.setBackgroundPaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.getDomainAxis().setMaximumCategoryLabelLines(3);
    chartPanel = new ChartPanel(barChart, false);
    chartPanel.setVerticalAxisTrace(false);
    chartPanel.setDisplayToolTips(true);
    chartPanel.setBackground(Color.white);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:de.fub.maps.project.plugins.tasks.eval.OverviewChart.java

/**
 * Creates new form OverviewChart/*  www. jav a 2s .c  o  m*/
 */
public OverviewChart() {
    initComponents();
    barchart1.getRangeAxis()
            .setLabel(NbBundle.getMessage(OverviewChart.class, "overview.chart1.rangeaxis1.name"));
    barchart1.getPlot().setRangeAxis(1,
            new NumberAxis(NbBundle.getMessage(OverviewChart.class, "overview.chart1.rangeaxis2.name")));
    barchart1.getPlot().getRangeAxis(1).setUpperMargin(.1);
    barchart1.getPlot().getRangeAxis(0).setUpperMargin(.1);
    barchart1.getPlot().getRenderer(0).setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat()));
    barchart1.getPlot().getRenderer(0).setBaseItemLabelsVisible(true);
    BarRenderer barRenderer = new BarRenderer();
    barRenderer.setBarPainter(new StandardBarPainter());
    barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat()));
    barRenderer.setBaseItemLabelsVisible(true);
    barRenderer.setAutoPopulateSeriesFillPaint(true);
    barRenderer.setAutoPopulateSeriesPaint(true);
    barRenderer.setShadowVisible(false);
    barchart1.getPlot().setRenderer(1, barRenderer);
    CategoryPlot plot = barchart1.getPlot();
    plot.setDataset(1, new DefaultCategoryDataset());
    plot.mapDatasetToRangeAxis(0, 0);
    plot.mapDatasetToRangeAxis(1, 1);
}

From source file:org.jfree.chart.demo.WaterfallChartDemo1.java

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createWaterfallChart("Product Cost Breakdown", "Expense Category",
            "Cost Per Unit", categorydataset, PlotOrientation.VERTICAL, false, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    categoryplot.setRangeGridlinesVisible(true);
    categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    ValueAxis valueaxis = categoryplot.getRangeAxis();
    DecimalFormat decimalformat = new DecimalFormat("##,###");
    decimalformat.setNegativePrefix("(");
    decimalformat.setNegativeSuffix(")");
    TickUnits tickunits = new TickUnits();
    tickunits.add(new NumberTickUnit(5D, decimalformat));
    tickunits.add(new NumberTickUnit(10D, decimalformat));
    tickunits.add(new NumberTickUnit(20D, decimalformat));
    tickunits.add(new NumberTickUnit(50D, decimalformat));
    tickunits.add(new NumberTickUnit(100D, decimalformat));
    tickunits.add(new NumberTickUnit(200D, decimalformat));
    tickunits.add(new NumberTickUnit(500D, decimalformat));
    tickunits.add(new NumberTickUnit(1000D, decimalformat));
    tickunits.add(new NumberTickUnit(2000D, decimalformat));
    tickunits.add(new NumberTickUnit(5000D, decimalformat));
    valueaxis.setStandardTickUnits(tickunits);
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    barrenderer.setBase(5D);//  w w  w .ja  v a 2  s.  co m
    DecimalFormat decimalformat1 = new DecimalFormat("$##,###.00");
    decimalformat1.setNegativePrefix("(");
    decimalformat1.setNegativeSuffix(")");
    barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1));
    barrenderer.setBaseItemLabelsVisible(true);
    return jfreechart;
}

From source file:org.jfree.chart.demo.ItemLabelDemo5.java

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Item Label Demo 5", null, null, categorydataset,
            PlotOrientation.VERTICAL, false, true, false);
    jfreechart.setBackgroundPaint(new Color(255, 255, 255));
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    MyStackedBarRenderer mystackedbarrenderer = new MyStackedBarRenderer();
    categoryplot.setRenderer(mystackedbarrenderer);
    ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 0.0D);//w w w.j  av  a 2  s. c  om
    mystackedbarrenderer.setPositiveItemLabelPositionFallback(itemlabelposition);
    mystackedbarrenderer.setNegativeItemLabelPositionFallback(itemlabelposition);
    StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator(
            "{0}", NumberFormat.getInstance());
    mystackedbarrenderer.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator);
    mystackedbarrenderer.setBaseItemLabelsVisible(true);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperBound(100D);
    return jfreechart;
}

From source file:servlet.SalesReportEventsBarChart.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   ww w.  jav a 2 s  .co  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    List<ArrayList> data = productSession.getEventSessionNo();

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (int i = 0; i < data.size(); i++) {
        dataset.addValue(Integer.valueOf(data.get(i).get(1).toString()), "Sessions",
                data.get(i).get(0).toString());
    }

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    JFreeChart barChart = ChartFactory.createBarChart("No of Sessions", "Event", "Sessions", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    CategoryPlot cplot = (CategoryPlot) barChart.getPlot();
    cplot.setBackgroundPaint(Color.WHITE);//change background color

    //set  bar chart color
    ((BarRenderer) cplot.getRenderer()).setBarPainter(new StandardBarPainter());

    BarRenderer r = (BarRenderer) barChart.getCategoryPlot().getRenderer();
    r.setSeriesPaint(0, Color.GREEN);

    r.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getInstance()));
    r.setBaseItemLabelsVisible(true);

    CategoryAxis categoryAxis = cplot.getDomainAxis();
    categoryAxis.setUpperMargin(0.15);

    NumberAxis rangeAxis = (NumberAxis) cplot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.15);

    int width = 550; /* Width of the image */

    int height = 450; /* Height of the image */

    response.setContentType("image/png");
    OutputStream out = response.getOutputStream();

    ChartUtilities.writeChartAsPNG(out, barChart, 400, 300, info);

}

From source file:org.perfrepo.web.controller.reports.testgroup.TestGroupChartBean.java

public void drawChart(OutputStream out, Object data) throws IOException {
    if (data instanceof ChartData) {
        ChartData chartData = (ChartData) data;
        JFreeChart chart = ChartFactory.createBarChart(chartData.getTitle(), "Test", "%",
                processDataSet(chartData), PlotOrientation.HORIZONTAL, false, true, false);
        chart.addSubtitle(new TextTitle("Comparison", new Font("Dialog", Font.ITALIC, 10)));
        chart.setBackgroundPaint(Color.white);
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CustomRenderer renderer = new CustomRenderer();

        plot.setBackgroundPaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        renderer.setBaseItemLabelGenerator(
                new StandardCategoryItemLabelGenerator("{2}%", NumberFormat.getInstance()));
        renderer.setBaseItemLabelsVisible(true);
        renderer.setDrawBarOutline(false);
        renderer.setMaximumBarWidth(1d / (chartData.getTests().length + 4.0));
        plot.setRenderer(renderer);//from   w w w  .  j a v a2  s  . co m

        CategoryAxis categoryAxis = plot.getDomainAxis();
        categoryAxis.setCategoryMargin(0.1);

        categoryAxis.setUpperMargin(0.1);
        categoryAxis.setLowerMargin(0.1);
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setUpperMargin(0.10);
        BufferedImage buffImg = chart.createBufferedImage(640, chartData.getTests().length * 100 + 100);
        ImageIO.write(buffImg, "gif", out);
    }
}

From source file:edu.gmu.cs.sim.util.media.chart.BarChartGenerator.java

void reviseRenderer(BarRenderer renderer) {
    renderer.setShadowVisible(false);/*  ww  w. ja  va 2s  . co m*/
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setBaseOutlineStroke(new BasicStroke(2.0f));
    renderer.setDrawBarOutline(true);
    renderer.setBaseItemLabelGenerator(
            new StandardCategoryItemLabelGenerator("{0}", java.text.NumberFormat.getInstance())); // {0} is the row key, {1} is the column key, {2} is the value
    renderer.setBaseItemLabelsVisible(true);
}

From source file:Visuals.BarChart.java

public ChartPanel drawBarChart() {
    DefaultCategoryDataset bardataset = new DefaultCategoryDataset();
    bardataset.addValue(new Double(low), "Low (" + low + ")", lowValue);
    bardataset.addValue(new Double(medium), "Medium (" + medium + ")", mediumValue);
    bardataset.addValue(new Double(high), "High (" + high + ")", highValue);
    bardataset.addValue(new Double(critical), "Critical (" + critical + ")", criticalValue);

    JFreeChart barchart = ChartFactory.createBarChart(title, // Title  
            riskCategory, riskCountTitle, bardataset // Dataset   
    );/*from w w w .j av  a  2 s.c o m*/

    final CategoryPlot plot = barchart.getCategoryPlot();
    CategoryItemRenderer renderer = new CustomRenderer();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    renderer.setBaseItemLabelGenerator(
            new StandardCategoryItemLabelGenerator(riskCountTitle, NumberFormat.getInstance()));

    DecimalFormat df = new DecimalFormat("##");
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", df));
    Font m1Font;
    m1Font = new Font("Cambria", Font.BOLD, 16);
    renderer.setItemLabelFont(m1Font);
    renderer.setItemLabelPaint(null);

    //barchart.removeLegend();
    plot.setRenderer(renderer);
    //renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE5, TextAnchor.CENTER));
    //renderer.setItemLabelsVisible(true);
    barchart.getCategoryPlot().setRenderer(renderer);

    LegendItemCollection chartLegend = new LegendItemCollection();
    Shape shape = new Rectangle(10, 10);
    chartLegend.add(new LegendItem("Low (" + low + ")", null, null, null, shape, new Color(230, 219, 27)));
    chartLegend
            .add(new LegendItem("Medium (" + medium + ")", null, null, null, shape, new Color(85, 144, 176)));
    chartLegend.add(new LegendItem("High (" + high + ")", null, null, null, shape, new Color(230, 90, 27)));
    chartLegend.add(
            new LegendItem("Critical (" + critical + ")", null, null, null, shape, new Color(230, 27, 27)));
    plot.setFixedLegendItems(chartLegend);
    plot.setBackgroundPaint(new Color(210, 234, 243));
    ChartPanel chartPanel = new ChartPanel(barchart);
    return chartPanel;
}

From source file:de.fub.maps.project.detector.model.inference.ui.charts.AttributeSelectionBarChart.java

/**
 * Creates new form AttributeSelectionBarChart
 *//*from  ww w. j  av a  2  s  .  c om*/
public AttributeSelectionBarChart() {
    initComponents();
    barChart = ChartFactory.createBarChart(
            NbBundle.getMessage(AttributeSelectionBarChart.class, "AttributeSelectionBarChart.CLT_Chart_Title"),
            NbBundle.getMessage(AttributeSelectionBarChart.class,
                    "AttributeSelectionBarChart.CLT_Domain_Axis_Name"),
            NbBundle.getMessage(AttributeSelectionBarChart.class,
                    "AttributeSelectionBarChart.CLT_Value_Axis_Name"),
            dataset, PlotOrientation.VERTICAL, true, true, true);
    plot = barChart.getCategoryPlot();
    Font font = new JLabel().getFont().deriveFont(Font.BOLD, 14);

    barChart.getTitle().setFont(font);
    barChart.getTitle().setPaint(new Color(153, 153, 153));

    plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT);

    plot.setBackgroundPaint(Color.white);
    plot.getRangeAxis().setAutoRange(true);
    plot.getRangeAxis().setUpperMargin(.1);

    BarRenderer barRenderer = new BarRenderer();
    barRenderer.setBarPainter(new StandardBarPainter());
    barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    barRenderer.setBaseFillPaint(Color.BLUE);
    barRenderer.setBasePaint(Color.BLUE);
    barRenderer.setAutoPopulateSeriesFillPaint(false);
    barRenderer.setAutoPopulateSeriesPaint(false);
    barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat()));
    barRenderer.setBaseItemLabelsVisible(true);

    plot.setRenderer(barRenderer);
    chartPanel = new ChartPanel(barChart, false);
    chartPanel.setVerticalAxisTrace(false);
    add(chartPanel, BorderLayout.CENTER);
}