Example usage for org.jfree.chart StandardChartTheme apply

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

Introduction

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

Prototype

@Override
public void apply(JFreeChart chart) 

Source Link

Document

Applies this theme to the supplied chart.

Usage

From source file:com.uttesh.pdfngreport.util.chart.ChartStyle.java

/**
 * this method will set the style theme for pie chart.
 *
 * @see org.jfree.chart.StandardChartTheme
 * @param chart// w  w  w  .  j  a  v  a 2  s .co  m
 */
public static void theme(JFreeChart chart) {
    String fontName = "Lucida Sans";

    StandardChartTheme theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme();

    theme.setTitlePaint(Color.decode("#4572a7"));
    theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 16)); //title
    theme.setLargeFont(new Font(fontName, Font.BOLD, 15)); //axis-title
    theme.setRegularFont(new Font(fontName, Font.PLAIN, 11));
    theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint(Color.white);
    theme.setChartBackgroundPaint(Color.white);
    theme.setGridBandPaint(Color.red);
    theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint(Color.decode("#666666"));
    theme.apply(chart);
    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
}

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./*  ww w .ja v  a  2  s  .  c o  m*/
 * 
 * @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:com.opendoorlogistics.components.gantt.GanttChartComponent.java

@Override
public void execute(final ComponentExecutionApi api, int mode, Object configuration,
        ODLDatastore<? extends ODLTable> ioDs, ODLDatastoreAlterable<? extends ODLTableAlterable> outputDs) {
    // Get items and sort by resource then date
    final StringConventions sc = api.getApi().stringConventions();
    List<GanttItem> items = GanttItem.beanMapping.getTableMapping(0).readObjectsFromTable(ioDs.getTableAt(0));

    // Rounding doubles to longs can create small errors where a start time is 1 millisecond after an end.
    // Set all start times to be <= end time
    for (GanttItem item : items) {
        if (item.getStart() == null || item.getEnd() == null) {
            throw new RuntimeException("Found Gannt item with null start or end time.");
        }//from  w w  w.  j  a  v  a 2 s. com

        if (item.getStart().getValue() > item.getEnd().getValue()) {
            item.setStart(item.getEnd());
        }
    }

    Collections.sort(items, new Comparator<GanttItem>() {

        @Override
        public int compare(GanttItem o1, GanttItem o2) {
            int diff = sc.compareStandardised(o1.getResourceId(), o2.getResourceId());
            if (diff == 0) {
                diff = o1.getStart().compareTo(o2.getStart());
            }
            if (diff == 0) {
                diff = o1.getEnd().compareTo(o2.getEnd());
            }
            if (diff == 0) {
                diff = sc.compareStandardised(o1.getActivityId(), o2.getActivityId());
            }
            if (diff == 0) {
                diff = Colours.compare(o1.getColor(), o2.getColor());
            }
            return diff;
        }
    });

    // Filter any zero duration items
    Iterator<GanttItem> it = items.iterator();
    while (it.hasNext()) {
        GanttItem item = it.next();
        if (item.getStart().compareTo(item.getEnd()) == 0) {
            it.remove();
        }
    }

    // Get average colour for each activity type
    Map<String, CalculateAverageColour> calcColourMap = api.getApi().stringConventions()
            .createStandardisedMap();
    for (GanttItem item : items) {
        CalculateAverageColour calc = calcColourMap.get(item.getActivityId());
        if (calc == null) {
            calc = new CalculateAverageColour();
            calcColourMap.put(item.getActivityId(), calc);
        }
        calc.add(item.getColor());
    }

    // Put into colour map
    Map<String, Color> colourMap = api.getApi().stringConventions().createStandardisedMap();
    for (Map.Entry<String, CalculateAverageColour> entry : calcColourMap.entrySet()) {
        colourMap.put(entry.getKey(), entry.getValue().getAverage());
    }

    // Split items by resource
    ArrayList<ArrayList<GanttItem>> splitByResource = new ArrayList<>();
    ArrayList<GanttItem> current = null;
    for (GanttItem item : items) {
        if (current == null
                || sc.compareStandardised(current.get(0).getResourceId(), item.getResourceId()) != 0) {
            current = new ArrayList<>();
            splitByResource.add(current);
        }
        current.add(item);
    }

    // put into jfreechart's task data structure
    TaskSeries ts = new TaskSeries("Resources");
    for (ArrayList<GanttItem> resource : splitByResource) {
        // get earliest and latest time (last time may not be in the last item)
        ODLTime earliest = resource.get(0).getStart();
        ODLTime latest = null;
        for (GanttItem item : resource) {
            if (latest == null || latest.compareTo(item.getEnd()) < 0) {
                latest = item.getEnd();
            }
        }

        Task task = new Task(resource.get(0).getResourceId(), new Date(earliest.getTotalMilliseconds()),
                new Date(latest.getTotalMilliseconds()));

        // add all items as subtasks
        for (GanttItem item : resource) {
            task.addSubtask(new MySubtask(item, new Date(item.getStart().getTotalMilliseconds()),
                    new Date(item.getEnd().getTotalMilliseconds())));
        }

        ts.add(task);
    }
    TaskSeriesCollection collection = new TaskSeriesCollection();
    collection.add(ts);

    // Create the plot
    CategoryAxis categoryAxis = new CategoryAxis(null);
    DateAxis dateAxis = new DateAxis("Time");
    CategoryItemRenderer renderer = new MyRenderer(collection, colourMap);
    final CategoryPlot plot = new CategoryPlot(collection, categoryAxis, dateAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.getDomainAxis().setLabel(null);

    ((DateAxis) plot.getRangeAxis()).setDateFormatOverride(new DateFormat() {

        @Override
        public Date parse(String source, ParsePosition pos) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
            toAppendTo.append(new ODLTime(date.getTime()).toString());
            return toAppendTo;
        }
    });

    // Create the chart and apply the standard theme without shadows to it
    api.submitControlLauncher(new ControlLauncherCallback() {

        @Override
        public void launchControls(ComponentControlLauncherApi launcherApi) {
            JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
            StandardChartTheme theme = new StandardChartTheme("standard theme", false);
            theme.setBarPainter(new StandardBarPainter());
            theme.apply(chart);

            class MyPanel extends ChartPanel implements Disposable {

                public MyPanel(JFreeChart chart) {
                    super(chart);
                }

                @Override
                public void dispose() {
                    // TODO Auto-generated method stub

                }

            }
            MyPanel chartPanel = new MyPanel(chart);
            launcherApi.registerPanel("Resource Gantt", null, chartPanel, true);
        }
    });

}

From source file:org.yccheok.jstock.charting.Utils.java

/**
 * Applying chart theme based on given JFreeChart.
 *
 * @param chart the JFreeChart/*  ww w.ja  v  a 2  s .  c om*/
 */
public static void applyChartThemeEx(JFreeChart chart) {
    final StandardChartTheme chartTheme;
    final JStockOptions.ChartTheme theme = JStock.instance().getJStockOptions().getChartTheme();

    if (theme == JStockOptions.ChartTheme.Light) {
        applyChartTheme(chart);
        return;
    } else {
        assert (theme == JStockOptions.ChartTheme.Dark);
        chartTheme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createDarknessTheme();
    }

    // The default font used by JFreeChart unable to render Chinese properly.
    // We need to provide font which is able to support Chinese rendering.
    final Locale defaultLocale = Locale.getDefault();
    if (org.yccheok.jstock.gui.Utils.isSimplifiedChinese(defaultLocale)
            || org.yccheok.jstock.gui.Utils.isTraditionalChinese(defaultLocale)) {
        final Font oldExtraLargeFont = chartTheme.getExtraLargeFont();
        final Font oldLargeFont = chartTheme.getLargeFont();
        final Font oldRegularFont = chartTheme.getRegularFont();
        final Font oldSmallFont = chartTheme.getSmallFont();

        final Font extraLargeFont = new Font("Sans-serif", oldExtraLargeFont.getStyle(),
                oldExtraLargeFont.getSize());
        final Font largeFont = new Font("Sans-serif", oldLargeFont.getStyle(), oldLargeFont.getSize());
        final Font regularFont = new Font("Sans-serif", oldRegularFont.getStyle(), oldRegularFont.getSize());
        final Font smallFont = new Font("Sans-serif", oldSmallFont.getStyle(), oldSmallFont.getSize());

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

    // Apply and return early.
    chartTheme.apply(chart);
}

From source file:org.yccheok.jstock.charting.Utils.java

/**
 * Applying chart theme based on given JFreeChart.
 *
 * @param chart the JFreeChart//from w w w. j ava 2  s . co  m
 */
public static void applyChartTheme(JFreeChart chart) {
    final StandardChartTheme chartTheme = (StandardChartTheme) org.jfree.chart.StandardChartTheme
            .createJFreeTheme();
    chartTheme.setXYBarPainter(barPainter);
    chartTheme.setShadowVisible(false);
    chartTheme.setPlotBackgroundPaint(Color.WHITE);
    chartTheme.setDomainGridlinePaint(Color.LIGHT_GRAY);
    chartTheme.setRangeGridlinePaint(Color.LIGHT_GRAY);
    chartTheme.setPlotOutlinePaint(Color.LIGHT_GRAY);

    // The default font used by JFreeChart unable to render Chinese properly.
    // We need to provide font which is able to support Chinese rendering.
    final Locale defaultLocale = Locale.getDefault();
    if (org.yccheok.jstock.gui.Utils.isSimplifiedChinese(defaultLocale)
            || org.yccheok.jstock.gui.Utils.isTraditionalChinese(defaultLocale)) {
        final Font oldExtraLargeFont = chartTheme.getExtraLargeFont();
        final Font oldLargeFont = chartTheme.getLargeFont();
        final Font oldRegularFont = chartTheme.getRegularFont();
        final Font oldSmallFont = chartTheme.getSmallFont();

        final Font extraLargeFont = new Font("Sans-serif", oldExtraLargeFont.getStyle(),
                oldExtraLargeFont.getSize());
        final Font largeFont = new Font("Sans-serif", oldLargeFont.getStyle(), oldLargeFont.getSize());
        final Font regularFont = new Font("Sans-serif", oldRegularFont.getStyle(), oldRegularFont.getSize());
        final Font smallFont = new Font("Sans-serif", oldSmallFont.getStyle(), oldSmallFont.getSize());

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

    if (chart.getPlot() instanceof CombinedDomainXYPlot) {
        @SuppressWarnings("unchecked")
        List<Plot> plots = ((CombinedDomainXYPlot) chart.getPlot()).getSubplots();
        for (Plot plot : plots) {
            final int domainAxisCount = ((XYPlot) plot).getDomainAxisCount();
            final int rangeAxisCount = ((XYPlot) plot).getRangeAxisCount();
            for (int i = 0; i < domainAxisCount; i++) {
                ((XYPlot) plot).getDomainAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                ((XYPlot) plot).getDomainAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
            for (int i = 0; i < rangeAxisCount; i++) {
                ((XYPlot) plot).getRangeAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                ((XYPlot) plot).getRangeAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
        }
    } else {
        final Plot plot = chart.getPlot();
        if (plot instanceof XYPlot) {
            final org.jfree.chart.plot.XYPlot xyPlot = (org.jfree.chart.plot.XYPlot) plot;
            final int domainAxisCount = xyPlot.getDomainAxisCount();
            final int rangeAxisCount = xyPlot.getRangeAxisCount();
            for (int i = 0; i < domainAxisCount; i++) {
                xyPlot.getDomainAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                xyPlot.getDomainAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
            for (int i = 0; i < rangeAxisCount; i++) {
                xyPlot.getRangeAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                xyPlot.getRangeAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
        }
        //else if (plot instanceof org.jfree.chart.plot.PiePlot) {
        //    final org.jfree.chart.plot.PiePlot piePlot = (org.jfree.chart.plot.PiePlot)plot;
        //    
        //}
    }

    chartTheme.apply(chart);
}

From source file:v800_trainer.JCicloTronic.java

public void applyChartTheme(JFreeChart chart) {

    final StandardChartTheme chartTheme = (StandardChartTheme) org.jfree.chart.StandardChartTheme
            .createJFreeTheme();//from   w ww. j av a2s.  c  o  m

    final Font extraLargeFont = new Font(Hauptfenster.getFont().getFontName(),
            Hauptfenster.getFont().getStyle(), (int) (FontSize * 1.2));
    final Font largeFont = new Font(Hauptfenster.getFont().getFontName(), Hauptfenster.getFont().getStyle(),
            (int) (FontSize * 1));
    final Font regularFont = new Font(Hauptfenster.getFont().getFontName(), Hauptfenster.getFont().getStyle(),
            (int) (FontSize * 0.8));
    final Font smallFont = new Font(Hauptfenster.getFont().getFontName(), Hauptfenster.getFont().getStyle(),
            (int) (FontSize * 0.4));

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

    chartTheme.apply(chart);

}