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

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

Introduction

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

Prototype

public ItemLabelPosition(ItemLabelAnchor itemLabelAnchor, TextAnchor textAnchor, TextAnchor rotationAnchor,
        double angle) 

Source Link

Document

Creates a new position record.

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  w  w  w.j  a  v  a 2 s  .com*/
    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:storybook.ui.chart.jfreechart.ChartUtil.java

public static ItemLabelPosition getNiceItemLabelPosition() {
    ItemLabelAnchor localItemLabelAnchor = ItemLabelAnchor.OUTSIDE6;
    TextAnchor localTextAnchor1 = TextAnchor.BOTTOM_LEFT;
    TextAnchor localTextAnchor2 = TextAnchor.TOP_LEFT;
    double d = Math.toRadians(270.0D);
    return new ItemLabelPosition(localItemLabelAnchor, localTextAnchor1, localTextAnchor2, d);
}

From source file:com.crunchify.jsp.servlet.BarServlet.java

public JFreeChart getChart() {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(15, "1", "451");
    dataset.addValue(12, "1", "851");
    dataset.addValue(10, "2", "362");
    dataset.addValue(5, "2", "142");

    JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 3", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            false, // include legend
            true, false);//w w  w .j ava  2s . co  m

    chart.setBackgroundPaint(Color.lightGray);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setNoDataMessage("NO DATA!");

    CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { Color.red, Color.blue, Color.green,
            Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue });

    renderer.setItemLabelsVisible(true);
    ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER,
            45.0);
    renderer.setPositiveItemLabelPosition(p);
    plot.setRenderer(renderer);

    // change the margin at the top of the range axis...
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);

    return chart;

}

From source file:eu.delving.sip.base.ReportChartHelper.java

private static JPanel finishBarChart(JFreeChart chart, Color... colors) {
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangePannable(true);/*from   w  w w . j a va2 s  .  co  m*/
    if (colors.length > 0)
        plot.setRenderer(new CustomRenderer(colors));
    BarRenderer bar = (BarRenderer) plot.getRenderer();
    bar.setItemLabelAnchorOffset(9D);
    bar.setBaseItemLabelsVisible(true);
    bar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    bar.setMaximumBarWidth(0.05);
    bar.setItemMargin(0.03D);
    bar.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT, -1.5707963267948966D));
    bar.setPositiveItemLabelPositionFallback(
            new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT, -1.5707963267948966D));
    CategoryAxis x = plot.getDomainAxis();
    x.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    x.setCategoryMargin(0.25D);
    x.setUpperMargin(0.02D);
    x.setLowerMargin(0.02D);
    NumberAxis y = (NumberAxis) plot.getRangeAxis();
    y.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    y.setUpperMargin(0.10000000000000001D);
    ChartUtilities.applyCurrentTheme(chart);
    return new ChartPanel(chart);
}

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);//from   w  ww . ja va 2  s  .  c o m
    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:graficarordenamiento.Graficador.java

public void crearGrafico() {
    // Creando el Grafico
    chart = ChartFactory.createBarChart("Grfico de barras", null, null, dataset, PlotOrientation.VERTICAL,
            false, false, false);// ww w .j  a  va 2  s.c  o m

    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.WHITE, 700, 0, Color.BLACK.brighter(), false));
    chart.setBackgroundImageAlpha(0.5f);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setNoDataMessage("NO DATA!");
    plot.setRangeGridlinePaint(Color.red);
    plot.setBackgroundPaint(new GradientPaint(0, 0, Color.LIGHT_GRAY, 0, 100, Color.darkGray));
    plot.setBackgroundImageAlpha(0.5f);
    //plot.setDomainGridlinesVisible(true);

    BarRenderer rend = (BarRenderer) plot.getRenderer();

    final ItemLabelPosition e = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 45.0);

    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));

    rend.setSeriesPaint(0, gp0);
    rend.setSeriesPaint(1, gp1);
    rend.setSeriesPaint(2, gp2);
    plot.setRenderer(rend);

    // change the margin at the top of the range axis...
    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);

    // set up gradient paints for series...

}

From source file:org.neo4j.bench.chart.JFreeBarChart.java

@Override
protected JFreeChart createChart(AbstractDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart("Performance chart", "Bench case", "Time(s)",
            (DefaultCategoryDataset) dataset, PlotOrientation.VERTICAL, true, true, false);

    rotateCategoryAxis(chart, Math.PI / 4.0);
    CategoryPlot plot = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setItemLabelGenerator(new CategoryItemLabelGenerator() {
        public String generateColumnLabel(CategoryDataset dataset, int column) {
            return "col" + column;
        }/* www .  j a v a  2  s  .c  o  m*/

        public String generateLabel(CategoryDataset dataset, int row, int column) {
            return "" + dataset.getValue(row, column).intValue();
        }

        public String generateRowLabel(CategoryDataset dataset, int row) {
            return "row" + row;
        }
    });
    renderer.setBaseItemLabelPaint(Color.black);
    renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE12,
            TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0));
    renderer.setItemLabelsVisible(true);

    return chart;
}

From source file:se.backede.jeconomix.forms.report.TransactionReport.java

public void addLineChart(Map<String, List<TransactionReportDto>> reports, Boolean average) {
    JFreeChart lineChart = ChartFactory.createLineChart("TOTAL", "MONTH", "Kr",
            ReportUtils.createDataset(reports, average), PlotOrientation.VERTICAL, true, true, true);

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(lineChartPanel.getWidth(), lineChartPanel.getHeight()));

    CategoryAxis axis = lineChart.getCategoryPlot().getDomainAxis();
    CategoryItemRenderer renderer = lineChart.getCategoryPlot().getRenderer();

    ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.HALF_ASCENT_CENTER,
            TextAnchor.BOTTOM_CENTER, 0);
    renderer.setBasePositiveItemLabelPosition(position);

    renderer.setBaseItemLabelGenerator(new CategoryItemLabelGenerator() {

        @Override//ww  w .  j av a2s .  c  o  m
        public String generateLabel(CategoryDataset dataset, int series, int category) {
            if (average) {
                if (series == 0) {
                    Number value = dataset.getValue(series, category);
                    String result = value.toString(); // could apply formatting here
                    return result;
                }
            } else {
                Number value = dataset.getValue(series, category);
                String result = value.toString(); // could apply formatting here
                return result;
            }
            return null;
        }

        @Override
        public String generateRowLabel(CategoryDataset cd, int i) {
            return null;
        }

        @Override
        public String generateColumnLabel(CategoryDataset cd, int i) {
            return null;
        }
    });

    renderer.setBaseItemLabelsVisible(true);
    lineChartPanel.setLayout(new BorderLayout());
    lineChartPanel.add(chartPanel, BorderLayout.NORTH);
}

From source file:Visao.grafico.Grafico.java

public void criaGrafico() {
    CategoryDataset cds = createDataset();
    titulo = "Grfico de " + ControlePrincipal.tipo_grafico;
    String eixoy = "Valores";
    String txt_legenda = "Ledenda:";
    boolean legenda = true;
    boolean tooltips = true;
    boolean urls = true;
    graf = ChartFactory.createBarChart3D(ControlePrincipal.descricao, txt_legenda, eixoy, cds,
            PlotOrientation.VERTICAL, legenda, tooltips, urls);

    CategoryPlot plot = (CategoryPlot) graf.getPlot();
    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(false);
    //ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER,
    //TextAnchor.CENTER, TextAnchor.CENTER, 0.0);
    //renderer.setBasePositiveItemLabelPosition(p);

    /*ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0);
    renderer.setBasePositiveItemLabelPosition(p);
    ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0);
    renderer.setPositiveItemLabelPosition(p2);*/

    CategoryItemRenderer line = plot.getRenderer();

    //aqui  definido o label  
    line.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    line.setBaseItemLabelsVisible(true);
    line.setBaseItemLabelPaint(Color.BLACK);
    ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER,
            TextAnchor.CENTER, 0.0);//from  w  w  w . j  a  v a 2  s.  c o  m
    line.setBasePositiveItemLabelPosition(p);

    myChartPanel = new ChartPanel(graf, true);
    myChartPanel.setSize(jPanel1.getWidth(), jPanel1.getHeight());
    myChartPanel.setVisible(true);
    jPanel1.removeAll();
    jPanel1.add(myChartPanel);
    jPanel1.revalidate();
    jPanel1.repaint();

}

From source file:edu.indiana.htrc.visual.HTRCBarChartDrawer.java

@Override
public File draw() {

    System.out.println("draw bar!!!!!!!!!!!!!");

    DefaultCategoryDataset bar_dataset = new DefaultCategoryDataset();
    /*dataset.setValue(6, "Profit", "Jane");
    dataset.setValue(7, "Profit", "Tom");
    dataset.setValue(8, "Profit", "Jill");
    dataset.setValue(5, "Profit", "John");
    dataset.setValue(12, "Profit", "Fred");*/
    Set<String> key_set = input_map.keySet();
    Iterator<String> iter = key_set.iterator();

    while (iter.hasNext()) {
        String key = iter.next();
        int value = input_map.get(key);
        bar_dataset.setValue(value, dataset_label, key);
    }/*w ww  . j  a  v a  2 s .c  o m*/

    JFreeChart chart = null;
    if (is3D) {
        chart = ChartFactory.createBarChart3D(chart_name, x_axis_label, y_axis_label, bar_dataset,
                PlotOrientation.VERTICAL, true, true, false);
    } else {
        chart = ChartFactory.createBarChart(chart_name, x_axis_label, y_axis_label, bar_dataset,
                PlotOrientation.VERTICAL, true, true, false);
    }

    CategoryPlot p = chart.getCategoryPlot();
    /*  NumberAxis rangeAxis = (NumberAxis) p.getRangeAxis();
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());*/
    BarRenderer renderer = (BarRenderer) p.getRenderer();
    DecimalFormat decimalformat1 = new DecimalFormat("##");

    StandardCategoryItemLabelGenerator label_generator = new StandardCategoryItemLabelGenerator("{2}",
            decimalformat1);

    renderer.setItemLabelGenerator(label_generator);

    final ItemLabelPosition pos = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.CENTER_RIGHT,
            TextAnchor.CENTER_RIGHT, 0/* -Math.PI / 2.0*/
    );
    renderer.setPositiveItemLabelPosition(pos);
    final CategoryAxis domainAxis = p.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    renderer.setMaximumBarWidth(.15);
    renderer.setItemLabelsVisible(true);
    chart.getCategoryPlot().setRenderer(renderer);
    File img = new File("../webapps/HTRC-UI-AuditAnalyzer/images/" + System.currentTimeMillis() + ".jpg");

    try {
        ChartUtilities.saveChartAsJPEG(img, chart, 1400, 600);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
    }
    return img;
}