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() 

Source Link

Document

Creates a new generator with a default number formatter.

Usage

From source file:scheduler.benchmarker.manager.CustomBarRenderer.java

public CustomBarRenderer(PluginColors colors) {
    //super();//from ww  w .ja v a 2s .  c  om
    pluginColors = colors;

    setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    setBaseItemLabelsVisible(true);
    setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 5", "Category", "Value",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    GroupedStackedBarRenderer groupedstackedbarrenderer = new GroupedStackedBarRenderer();
    KeyToGroupMap keytogroupmap = new KeyToGroupMap("G1");
    keytogroupmap.mapKeyToGroup("S1", "G1");
    keytogroupmap.mapKeyToGroup("S2", "G1");
    keytogroupmap.mapKeyToGroup("S3", "G2");
    keytogroupmap.mapKeyToGroup("S4", "G3");
    groupedstackedbarrenderer.setSeriesToGroupMap(keytogroupmap);
    groupedstackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    groupedstackedbarrenderer.setBaseItemLabelsVisible(true);
    groupedstackedbarrenderer.setPositiveItemLabelPositionFallback(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));
    groupedstackedbarrenderer.setItemMargin(0.10000000000000001D);
    SubCategoryAxis subcategoryaxis = new SubCategoryAxis("Category / Group");
    subcategoryaxis.setCategoryMargin(0.050000000000000003D);
    subcategoryaxis.addSubCategory("G1");
    subcategoryaxis.addSubCategory("G2");
    subcategoryaxis.addSubCategory("G3");
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setDomainAxis(subcategoryaxis);
    categoryplot.setRenderer(groupedstackedbarrenderer);
    return jfreechart;
}

From source file:org.bonitasoft.simulation.reporting.jasperreport.BarChartVisibleBarLabel.java

public void customize(JFreeChart chart, JRChart jasperChart) {

    BarRenderer bsr = (BarRenderer) chart.getCategoryPlot().getRenderer();
    bsr.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    bsr.setItemLabelsVisible(true);/*w  ww .  jav  a2  s.  c o  m*/
    // Set position of Items label : center
    bsr.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    bsr.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    // If there isn't enough space to draw the ItemLabel...
    bsr.setPositiveItemLabelPositionFallback(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER));
    bsr.setNegativeItemLabelPositionFallback(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER));
}

From source file:include.picture.MyBarChart.java

/**
*?
*///w  ww  .ja  va2 s .co  m
public void paint() {
    try {
        check();
        CategoryDataset dataset = getDataSet(series, category, data);
        JFreeChart chart = ChartFactory.createBarChart3D(title, axisXLabel, axisYLabel, dataset,
                PlotOrientation.VERTICAL, true, false, false);
        chart.setBackgroundPaint(Color.WHITE);
        BarRenderer3D renderer = new BarRenderer3D();
        CategoryPlot plot = chart.getCategoryPlot();
        renderer.setMaxBarWidth(0.01);
        renderer.setBaseOutlinePaint(Color.BLACK);
        renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        renderer.setItemLabelFont(new Font("", Font.PLAIN, 15));
        renderer.setItemLabelsVisible(true);
        renderer.setItemMargin(0.1);
        plot.setRenderer(renderer);
        FileOutputStream fos_jpg = null;
        try {
            fos_jpg = new FileOutputStream(fileName);
            ChartUtilities.writeChartAsJPEG(fos_jpg, 1000, chart, width, height, null);
        } finally {
            try {
                fos_jpg.close();
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } // end of try-catch

}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1", "Type", "Value",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(false);
    StatisticalBarRenderer statisticalbarrenderer = new StatisticalBarRenderer();
    statisticalbarrenderer.setErrorIndicatorPaint(Color.black);
    statisticalbarrenderer.setIncludeBaseInRange(false);
    categoryplot.setRenderer(statisticalbarrenderer);
    statisticalbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    statisticalbarrenderer.setBaseItemLabelsVisible(true);
    statisticalbarrenderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER));
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 7", "Category", "Value",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setRenderAsPercentages(true);
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setBaseItemLabelsVisible(true);
    stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Java Standard Class Library", "Release",
            "Class Count", categorydataset, PlotOrientation.VERTICAL, false, true, false);
    jfreechart.addSubtitle(new TextTitle("Number of Classes By Release"));
    TextTitle texttitle = new TextTitle(
            "Source: Java In A Nutshell (4th Edition) by David Flanagan (O'Reilly)");
    texttitle.setFont(new Font("SansSerif", 0, 10));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);/*from   w ww .  j a  va2s.  c o  m*/
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperMargin(0.14999999999999999D);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    lineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    lineandshaperenderer.setBaseItemLabelsVisible(true);
    return jfreechart;
}

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

public static JFreeChart createChart() {
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(1.0D, "S1", "Category 1");
    dataset1.addValue(4D, "S1", "Category 2");
    dataset1.addValue(3D, "S1", "Category 3");
    dataset1.addValue(5D, "S1", "Category 4");
    dataset1.addValue(5D, "S1", "Category 5");
    dataset1.addValue(7D, "S1", "Category 6");
    dataset1.addValue(7D, "S1", "Category 7");
    dataset1.addValue(8D, "S1", "Category 8");
    dataset1.addValue(5D, "S2", "Category 1");
    dataset1.addValue(7D, "S2", "Category 2");
    dataset1.addValue(6D, "S2", "Category 3");
    dataset1.addValue(8D, "S2", "Category 4");
    dataset1.addValue(4D, "S2", "Category 5");
    dataset1.addValue(4D, "S2", "Category 6");
    dataset1.addValue(2D, "S2", "Category 7");
    dataset1.addValue(1.0D, "S2", "Category 8");
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.addValue(9D, "T1", "Category 1");
    dataset2.addValue(7D, "T1", "Category 2");
    dataset2.addValue(2D, "T1", "Category 3");
    dataset2.addValue(6D, "T1", "Category 4");
    dataset2.addValue(6D, "T1", "Category 5");
    dataset2.addValue(9D, "T1", "Category 6");
    dataset2.addValue(5D, "T1", "Category 7");
    dataset2.addValue(4D, "T1", "Category 8");
    DefaultCategoryDataset dataset3 = new DefaultCategoryDataset();
    dataset3.addValue(94D, "R1", "Category 1");
    dataset3.addValue(75D, "R1", "Category 2");
    dataset3.addValue(22D, "R1", "Category 3");
    dataset3.addValue(74D, "R1", "Category 4");
    dataset3.addValue(83D, "R1", "Category 5");
    dataset3.addValue(9D, "R1", "Category 6");
    dataset3.addValue(23D, "R1", "Category 7");
    dataset3.addValue(98D, "R1", "Category 8");
    ///*from www  .  j  ava  2 s . com*/
    StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator();
    BarRenderer renderer1 = new BarRenderer();
    renderer1.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator);
    renderer1.setBaseItemLabelsVisible(true);
    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    LineAndShapeRenderer renderer3 = new LineAndShapeRenderer();
    //plot
    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset1);
    plot.setRenderer(renderer1);
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);
    plot.setDataset(2, dataset3);
    plot.setRenderer(2, renderer3);
    plot.setDomainAxis(new CategoryAxis("Category"));
    //more rangeAxis
    plot.setRangeAxis(new NumberAxis("Value"));
    plot.setRangeAxis(1, new NumberAxis("Axis 2"));
    plot.mapDatasetToRangeAxis(2, 1);
    //
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    //chart
    JFreeChart chart = new JFreeChart(plot);
    chart.setTitle("Overlaid Bar Chart");
    return chart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart3D("Student Grades", "Students", "Grade",
            categorydataset, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    CustomBarRenderer3D custombarrenderer3d = new CustomBarRenderer3D();
    custombarrenderer3d.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    custombarrenderer3d.setBaseItemLabelsVisible(true);
    custombarrenderer3d.setItemLabelAnchorOffset(10D);
    custombarrenderer3d.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    categoryplot.setRenderer(custombarrenderer3d);
    ValueMarker valuemarker = new ValueMarker(0.69999999999999996D, new Color(200, 200, 255),
            new BasicStroke(1.0F), new Color(200, 200, 255), new BasicStroke(1.0F), 1.0F);
    categoryplot.addRangeMarker(valuemarker, Layer.BACKGROUND);
    custombarrenderer3d.setBaseItemLabelsVisible(true);
    custombarrenderer3d.setMaximumBarWidth(0.050000000000000003D);
    CategoryTextAnnotation categorytextannotation = new CategoryTextAnnotation("Minimum grade to pass",
            "Robert", 0.70999999999999996D);
    categorytextannotation.setCategoryAnchor(CategoryAnchor.START);
    categorytextannotation.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categoryplot.addAnnotation(categorytextannotation);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    numberaxis.setUpperMargin(0.10000000000000001D);
    return jfreechart;
}

From source file:org.openfaces.component.chart.impl.configuration.GridLabelsConfigurator.java

private void setGenerator(AbstractRenderer renderer) {
    if (renderer instanceof AbstractCategoryItemRenderer) {
        ((AbstractCategoryItemRenderer) renderer)
                .setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    } else if (renderer instanceof AbstractXYItemRenderer) {
        ((AbstractXYItemRenderer) renderer).setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    }/*from   www.j a  va  2 s  . co m*/

}