Example usage for org.jfree.chart StandardChartTheme createJFreeTheme

List of usage examples for org.jfree.chart StandardChartTheme createJFreeTheme

Introduction

In this page you can find the example usage for org.jfree.chart StandardChartTheme createJFreeTheme.

Prototype

public static ChartTheme createJFreeTheme() 

Source Link

Document

Creates and returns the default 'JFree' chart theme.

Usage

From source file:cl.apr.pdf.chart.BarChartAviso.java

public static BufferedImage crearBarchart(List<BarChartItem> barChartItems) {
    BufferedImage bi = null;/*from  w  w w.  java2 s.c  o m*/
    try {

        ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme());
        //ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme());

        /* Step - 1: Define the data for the bar chart  */
        DefaultCategoryDataset my_bar_chart_dataset = new DefaultCategoryDataset();
        int i = 0;
        for (BarChartItem barChartItem : barChartItems) {
            if (barChartItem.getNombre().equals("-")) {
                my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", (++i) + "");
            } else
                my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", barChartItem.getNombre());
        }
        //                my_bar_chart_dataset.addValue(34, "mes", "Ene");
        //                my_bar_chart_dataset.addValue(25, "mes", "Feb");
        //                my_bar_chart_dataset.addValue(22, "mes", "Mar");
        //                my_bar_chart_dataset.addValue(12, "mes", "Abr");
        //                my_bar_chart_dataset.addValue(40, "mes", "May");
        //                my_bar_chart_dataset.addValue(30, "mes", "jun");
        //                my_bar_chart_dataset.addValue(2, "mes", "Jul");
        //                my_bar_chart_dataset.addValue(15, "mes", "Ago");

        /* Step -2:Define the JFreeChart object to create bar chart */
        //JFreeChart chart=ChartFactory.createBarChart("Detalle de sus consumos","","MT3",my_bar_chart_dataset,PlotOrientation.VERTICAL,true,true,false);    
        JFreeChart chart = ChartFactory.createBarChart("", "", "MT3", my_bar_chart_dataset,
                PlotOrientation.VERTICAL, true, true, false);

        //chart.setBackgroundPaint(Color.lightGray);
        // get a reference to the plot for further customisation... 
        final CategoryPlot plot = chart.getCategoryPlot();
        CategoryItemRenderer renderer = new CustomRenderer();

        renderer.setSeriesPaint(0, Color.DARK_GRAY);

        plot.setRenderer(renderer);
        plot.setBackgroundPaint(Color.white);

        chart.setBorderVisible(false);
        chart.setBackgroundPaint(Color.white);
        chart.setBorderStroke(null);
        chart.getLegend().visible = false;
        /* Step -3: Write the output as PNG file with bar chart information */
        int width = 480; /* Width of the image */
        int height = 250; /* Height of the image */
        bi = chart.createBufferedImage(width, height);

        /*
                
        File BarChart=new File("output_chart.png");              
        ChartUtilities.saveChartAsPNG(BarChart,BarChartObject,width,height); 
                */
    } catch (Exception i) {
        System.out.println(i);
    }

    return bi;
}

From source file:jhplot.HPlotChart.java

/**
    * Set a custom theme for chart.. It can be: LEGACY_THEME, JFREE_THEME,
    * DARKNESS_THEME//from w w w . java 2 s  .c om
    * 
    * @param s
    *            a theme, can be either LEGACY_THEME, JFREE_THEME,
    *            DARKNESS_THEME
    */
public void setTheme(String s) {

    if (s.equals("LEGACY_THEME")) {
        ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
        ChartUtilities.applyCurrentTheme(chart);
    } else if (s.equals("JFREE_THEME")) {
        ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme());
        ChartUtilities.applyCurrentTheme(chart);
    } else if (s.equals("DARKNESS_THEME")) {
        ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme());
        ChartUtilities.applyCurrentTheme(chart);

    }
}

From source file:com.rapidminer.gui.viewer.metadata.model.AbstractAttributeStatisticsModel.java

/**
 * Changes the font of {@link JFreeChart}s to Sans Serif. This method uses a
 * {@link StandardChartTheme} to do so, so any changes to the look of the chart must be done
 * after calling this method./*w w  w .  j av  a  2 s . c om*/
 * 
 * @param chart
 *            the chart to change fonts for
 */
protected static void setDefaultChartFonts(JFreeChart chart) {
    final ChartTheme chartTheme = StandardChartTheme.createJFreeTheme();

    if (StandardChartTheme.class.isAssignableFrom(chartTheme.getClass())) {
        StandardChartTheme standardTheme = (StandardChartTheme) chartTheme;
        // The default font used by JFreeChart cannot render japanese etc symbols
        final Font oldExtraLargeFont = standardTheme.getExtraLargeFont();
        final Font oldLargeFont = standardTheme.getLargeFont();
        final Font oldRegularFont = standardTheme.getRegularFont();
        final Font oldSmallFont = standardTheme.getSmallFont();

        final Font extraLargeFont = new Font(Font.SANS_SERIF, oldExtraLargeFont.getStyle(),
                oldExtraLargeFont.getSize());
        final Font largeFont = new Font(Font.SANS_SERIF, oldLargeFont.getStyle(), oldLargeFont.getSize());
        final Font regularFont = new Font(Font.SANS_SERIF, oldRegularFont.getStyle(), oldRegularFont.getSize());
        final Font smallFont = new Font(Font.SANS_SERIF, oldSmallFont.getStyle(), oldSmallFont.getSize());

        standardTheme.setExtraLargeFont(extraLargeFont);
        standardTheme.setLargeFont(largeFont);
        standardTheme.setRegularFont(regularFont);
        standardTheme.setSmallFont(smallFont);

        standardTheme.apply(chart);
    }
}

From source file:jhplot.HChart.java

/**
 * Set a custom theme for chart.. It can be: LEGACY_THEME, JFREE_THEME,
 * DARKNESS_THEME//from   ww  w  .j  a  v  a 2  s  .  c  om
 * 
 * @param s
 *            a theme, can be either LEGACY_THEME, JFREE_THEME,
 *            DARKNESS_THEME
 */
public void setTheme(String s) {

    if (s.equals("LEGACY_THEME")) {
        ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
        applyThemeToChart();
    } else if (s.equals("JFREE_THEME")) {
        ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme());
        applyThemeToChart();
    } else if (s.equals("DARKNESS_THEME")) {
        ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme());
        applyThemeToChart();
    }
}