Search in sources :

Example 1 with XYStepAreaRenderer

use of org.jfree.chart.renderer.xy.XYStepAreaRenderer in project lotro-companion by dmorcellet.

the class CraftingHistoryChartController method buildChart.

private JFreeChart buildChart() {
    String title = "";
    if (_showTitle) {
        title = _stats.getProfession().getLabel();
    }
    updateData();
    JFreeChart jfreechart = ChartFactory.createXYStepChart(title, "Time", "Tier", _data, PlotOrientation.VERTICAL, true, true, false);
    Color foregroundColor = GuiFactory.getForegroundColor();
    Paint backgroundPaint = GuiFactory.getBackgroundPaint();
    jfreechart.setBackgroundPaint(backgroundPaint);
    TextTitle t = new TextTitle(title);
    t.setFont(t.getFont().deriveFont(24.0f));
    t.setPaint(foregroundColor);
    jfreechart.setTitle(t);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(false);
    XYStepAreaRenderer xysteparearenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES);
    XYToolTipGenerator tooltip = new StandardXYToolTipGenerator() {

        @Override
        public String generateLabelString(XYDataset dataset, int series, int item) {
            String label;
            int tier = (int) dataset.getYValue(series, item);
            if (tier == 0) {
                label = "Started profession";
            } else {
                CraftingLevel level = CraftingLevel.getByTier(tier);
                if (level != null) {
                    if (series == 0)
                        label = level.getMastery().getLabel();
                    else if (series == 1)
                        label = level.getProficiency().getLabel();
                    else
                        label = "???";
                } else {
                    label = "???";
                }
            }
            double timestamp = dataset.getXValue(series, item);
            String date = Formats.getDateString(Long.valueOf((long) timestamp));
            return label + " (" + date + ")";
        }
    };
    xysteparearenderer.setBaseToolTipGenerator(tooltip);
    xysteparearenderer.setSeriesPaint(0, new Color(255, 235, 31));
    xysteparearenderer.setSeriesPaint(1, new Color(130, 80, 57));
    xyplot.setRenderer(xysteparearenderer);
    DateAxis axis = (DateAxis) xyplot.getDomainAxis();
    SimpleDateFormat sdf = Formats.getDateFormatter();
    axis.setDateFormatOverride(sdf);
    axis.setAxisLinePaint(foregroundColor);
    axis.setLabelPaint(foregroundColor);
    axis.setTickLabelPaint(foregroundColor);
    NumberAxis valueAxis = (NumberAxis) xyplot.getRangeAxis();
    valueAxis.setAutoRange(false);
    valueAxis.setAxisLinePaint(foregroundColor);
    valueAxis.setLabelPaint(foregroundColor);
    valueAxis.setTickLabelPaint(foregroundColor);
    CraftingLevel maxLevel = CraftingLevel.getMaximumLevel();
    valueAxis.setRange(0, maxLevel.getTier());
    NumberFormat nf = new NumberFormat() {

        private String format(int number) {
            CraftingLevel level = CraftingLevel.getByTier(number);
            String ret = (level != null) ? level.getProficiency().getLabel() : "???";
            return ret;
        }

        @Override
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
            return toAppendTo.append(format((int) number));
        }

        @Override
        public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
            return toAppendTo.append(format((int) number));
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    };
    valueAxis.setNumberFormatOverride(nf);
    LegendTitle legend = jfreechart.getLegend();
    legend.setItemPaint(foregroundColor);
    legend.setBackgroundPaint(backgroundPaint);
    return jfreechart;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) XYStepAreaRenderer(org.jfree.chart.renderer.xy.XYStepAreaRenderer) LegendTitle(org.jfree.chart.title.LegendTitle) Paint(java.awt.Paint) FieldPosition(java.text.FieldPosition) JFreeChart(org.jfree.chart.JFreeChart) Paint(java.awt.Paint) TextTitle(org.jfree.chart.title.TextTitle) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) XYDataset(org.jfree.data.xy.XYDataset) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) CraftingLevel(delta.games.lotro.lore.crafting.CraftingLevel) SimpleDateFormat(java.text.SimpleDateFormat) NumberFormat(java.text.NumberFormat) ParsePosition(java.text.ParsePosition)

Example 2 with XYStepAreaRenderer

use of org.jfree.chart.renderer.xy.XYStepAreaRenderer in project lotro-companion by dmorcellet.

the class FactionHistoryChartController method buildChart.

private JFreeChart buildChart() {
    String title = "";
    if (_showTitle) {
        title = _stats.getFaction().getName();
    }
    updateData();
    JFreeChart jfreechart = ChartFactory.createXYStepChart(title, "Time", "Level", _data, PlotOrientation.VERTICAL, true, true, false);
    Color foregroundColor = GuiFactory.getForegroundColor();
    Paint backgroundPaint = GuiFactory.getBackgroundPaint();
    jfreechart.setBackgroundPaint(backgroundPaint);
    TextTitle t = new TextTitle(title);
    t.setFont(t.getFont().deriveFont(24.0f));
    t.setPaint(foregroundColor);
    jfreechart.setTitle(t);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(false);
    XYStepAreaRenderer xysteparearenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES);
    Faction faction = _stats.getFaction();
    final FactionLevel[] levels = faction.getLevels();
    XYToolTipGenerator tooltip = new StandardXYToolTipGenerator() {

        @Override
        public String generateLabelString(XYDataset dataset, int series, int item) {
            String label = "???";
            int tier = (int) dataset.getYValue(series, item);
            for (FactionLevel level : levels) {
                if (level.getValue() == tier) {
                    label = level.getName();
                }
            }
            double timestamp = dataset.getXValue(series, item);
            String date = Formats.getDateString(Long.valueOf((long) timestamp));
            return label + " (" + date + ")";
        }
    };
    xysteparearenderer.setBaseToolTipGenerator(tooltip);
    xysteparearenderer.setSeriesPaint(0, new Color(0, 0, 255));
    xyplot.setRenderer(xysteparearenderer);
    DateAxis axis = (DateAxis) xyplot.getDomainAxis();
    SimpleDateFormat sdf = Formats.getDateFormatter();
    axis.setDateFormatOverride(sdf);
    axis.setAxisLinePaint(foregroundColor);
    axis.setLabelPaint(foregroundColor);
    axis.setTickLabelPaint(foregroundColor);
    NumberAxis valueAxis = (NumberAxis) xyplot.getRangeAxis();
    valueAxis.setAutoRange(false);
    valueAxis.setAxisLinePaint(foregroundColor);
    valueAxis.setLabelPaint(foregroundColor);
    valueAxis.setTickLabelPaint(foregroundColor);
    final int min = levels[0].getValue();
    int max = levels[levels.length - 1].getValue();
    valueAxis.setRange(min, max);
    NumberFormat nf = new NumberFormat() {

        private String format(int number) {
            String ret = levels[number - min].getName();
            return ret;
        }

        @Override
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
            return toAppendTo.append(format((int) number));
        }

        @Override
        public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
            return toAppendTo.append(format((int) number));
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    };
    valueAxis.setNumberFormatOverride(nf);
    LegendTitle legend = jfreechart.getLegend();
    legend.setItemPaint(foregroundColor);
    legend.setBackgroundPaint(backgroundPaint);
    return jfreechart;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) XYStepAreaRenderer(org.jfree.chart.renderer.xy.XYStepAreaRenderer) LegendTitle(org.jfree.chart.title.LegendTitle) Paint(java.awt.Paint) FieldPosition(java.text.FieldPosition) JFreeChart(org.jfree.chart.JFreeChart) FactionLevel(delta.games.lotro.lore.reputation.FactionLevel) Paint(java.awt.Paint) TextTitle(org.jfree.chart.title.TextTitle) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) XYDataset(org.jfree.data.xy.XYDataset) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) SimpleDateFormat(java.text.SimpleDateFormat) Faction(delta.games.lotro.lore.reputation.Faction) NumberFormat(java.text.NumberFormat) ParsePosition(java.text.ParsePosition)

Example 3 with XYStepAreaRenderer

use of org.jfree.chart.renderer.xy.XYStepAreaRenderer in project pentaho-platform by pentaho.

the class JFreeChartEngine method createTimeSeriesCollectionChart.

private static JFreeChart createTimeSeriesCollectionChart(final TimeSeriesCollectionChartDefinition chartDefinition) {
    JFreeChart chart = null;
    // TODO Make the following accessible from the chartDefinition
    String domainAxisLabel = null;
    String rangeAxisLabel = null;
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------
    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();
    DateAxis domainAxis = new DateAxis(domainAxisLabel, TimeZone.getDefault());
    ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel);
    XYItemRenderer renderer = null;
    switch(chartDefinition.getChartType()) {
        case LINE_CHART_TYPE:
            renderer = chartDefinition.isThreeD() ? new XYLine3DRenderer() : new XYLineAndShapeRenderer(true, false);
            ((XYLineAndShapeRenderer) renderer).setShapesVisible(chartDefinition.isMarkersVisible());
            ((XYLineAndShapeRenderer) renderer).setBaseShapesFilled(chartDefinition.isMarkersVisible());
            break;
        case AREA_CHART_TYPE:
            renderer = new XYAreaRenderer();
            break;
        case STEP_CHART_TYPE:
            renderer = new XYStepRenderer();
            break;
        case STEP_AREA_CHART_TYPE:
            renderer = new XYStepAreaRenderer();
            break;
        case DIFFERENCE_CHART_TYPE:
            renderer = new XYDifferenceRenderer();
            break;
        case DOT_CHART_TYPE:
            renderer = new XYDotRenderer();
            ((XYDotRenderer) renderer).setDotHeight(chartDefinition.getDotHeight());
            ((XYDotRenderer) renderer).setDotWidth(chartDefinition.getDotWidth());
            break;
        default:
            // should log an error if invalid chart type passed in - at least return null for no renderer
            return null;
    }
    if (tooltips) {
        XYToolTipGenerator generator = new StandardXYToolTipGenerator(chartDefinition.getTooltipContent(), new SimpleDateFormat(chartDefinition.getTooltipXFormat()), new DecimalFormat(chartDefinition.getTooltipYFormat()));
        renderer.setToolTipGenerator(generator);
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }
    renderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth()));
    XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer);
    JFreeChartEngine.updatePlot(plot, chartDefinition);
    chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) DecimalFormat(java.text.DecimalFormat) XYStepAreaRenderer(org.jfree.chart.renderer.xy.XYStepAreaRenderer) XYDotRenderer(org.jfree.chart.renderer.xy.XYDotRenderer) XYDifferenceRenderer(org.jfree.chart.renderer.xy.XYDifferenceRenderer) JFreeChart(org.jfree.chart.JFreeChart) XYAreaRenderer(org.jfree.chart.renderer.xy.XYAreaRenderer) XYLine3DRenderer(org.jfree.chart.renderer.xy.XYLine3DRenderer) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) XYStepRenderer(org.jfree.chart.renderer.xy.XYStepRenderer) StandardXYURLGenerator(org.jfree.chart.urls.StandardXYURLGenerator) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with XYStepAreaRenderer

use of org.jfree.chart.renderer.xy.XYStepAreaRenderer in project SIMVA-SoS by SESoS.

the class ChartFactory method createXYStepAreaChart.

/**
 * Creates a filled stepped XY plot with default settings.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the plot orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A chart.
 */
public static JFreeChart createXYStepAreaChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {
    ParamChecks.nullNotPermitted(orientation, "orientation");
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }
    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    XYItemRenderer renderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES, toolTipGenerator, urlGenerator);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) StandardXYURLGenerator(org.jfree.chart.urls.StandardXYURLGenerator) XYURLGenerator(org.jfree.chart.urls.XYURLGenerator) XYStepAreaRenderer(org.jfree.chart.renderer.xy.XYStepAreaRenderer) StandardXYURLGenerator(org.jfree.chart.urls.StandardXYURLGenerator) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer)

Example 5 with XYStepAreaRenderer

use of org.jfree.chart.renderer.xy.XYStepAreaRenderer in project pentaho-platform by pentaho.

the class JFreeChartEngine method createXYSeriesCollectionChart.

private static JFreeChart createXYSeriesCollectionChart(final XYSeriesCollectionChartDefinition chartDefinition) {
    JFreeChart chart = null;
    // TODO Make the following accessible from the chartDefinition
    String domainAxisLabel = null;
    String rangeAxisLabel = null;
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------
    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();
    NumberAxis domainAxis = chartDefinition.isThreeD() ? new NumberAxis3D(domainAxisLabel) : new NumberAxis(domainAxisLabel);
    domainAxis.setAutoRangeIncludesZero(chartDefinition.isDomainIncludesZero());
    domainAxis.setAutoRangeStickyZero(chartDefinition.isDomainStickyZero());
    ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel);
    AbstractXYItemRenderer renderer = null;
    switch(chartDefinition.getChartType()) {
        case LINE_CHART_TYPE:
            renderer = chartDefinition.isThreeD() ? new XYLine3DRenderer() : new XYLineAndShapeRenderer(true, false);
            ((XYLineAndShapeRenderer) renderer).setShapesVisible(chartDefinition.isMarkersVisible());
            ((XYLineAndShapeRenderer) renderer).setBaseShapesFilled(chartDefinition.isMarkersVisible());
            break;
        case AREA_CHART_TYPE:
            renderer = new XYAreaRenderer();
            break;
        case STEP_CHART_TYPE:
            renderer = new XYStepRenderer();
            break;
        case STEP_AREA_CHART_TYPE:
            renderer = new XYStepAreaRenderer();
            break;
        case DIFFERENCE_CHART_TYPE:
            renderer = new XYDifferenceRenderer();
            break;
        case DOT_CHART_TYPE:
            renderer = new XYDotRenderer();
            ((XYDotRenderer) renderer).setDotHeight(chartDefinition.getDotHeight());
            ((XYDotRenderer) renderer).setDotWidth(chartDefinition.getDotWidth());
            break;
        default:
            // should log an error if invalid chart type passed in - at least return null for no renderer
            return null;
    }
    if (renderer != null && legend) {
        renderer.setLegendItemURLGenerator(new StandardXYSeriesLabelGenerator());
    }
    if (tooltips) {
        XYToolTipGenerator generator = new StandardXYToolTipGenerator(chartDefinition.getTooltipContent(), new DecimalFormat(chartDefinition.getTooltipXFormat()), new DecimalFormat(chartDefinition.getTooltipYFormat()));
        renderer.setToolTipGenerator(generator);
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }
    renderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth()));
    XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer);
    JFreeChartEngine.updatePlot(plot, chartDefinition);
    chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) StandardXYSeriesLabelGenerator(org.jfree.chart.labels.StandardXYSeriesLabelGenerator) DecimalFormat(java.text.DecimalFormat) NumberAxis3D(org.jfree.chart.axis.NumberAxis3D) XYStepAreaRenderer(org.jfree.chart.renderer.xy.XYStepAreaRenderer) XYDotRenderer(org.jfree.chart.renderer.xy.XYDotRenderer) XYDifferenceRenderer(org.jfree.chart.renderer.xy.XYDifferenceRenderer) JFreeChart(org.jfree.chart.JFreeChart) XYAreaRenderer(org.jfree.chart.renderer.xy.XYAreaRenderer) XYLine3DRenderer(org.jfree.chart.renderer.xy.XYLine3DRenderer) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) XYStepRenderer(org.jfree.chart.renderer.xy.XYStepRenderer) StandardXYURLGenerator(org.jfree.chart.urls.StandardXYURLGenerator) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator)

Aggregations

NumberAxis (org.jfree.chart.axis.NumberAxis)5 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)5 XYToolTipGenerator (org.jfree.chart.labels.XYToolTipGenerator)5 XYPlot (org.jfree.chart.plot.XYPlot)5 XYStepAreaRenderer (org.jfree.chart.renderer.xy.XYStepAreaRenderer)5 JFreeChart (org.jfree.chart.JFreeChart)4 SimpleDateFormat (java.text.SimpleDateFormat)3 DateAxis (org.jfree.chart.axis.DateAxis)3 StandardXYURLGenerator (org.jfree.chart.urls.StandardXYURLGenerator)3 Color (java.awt.Color)2 Paint (java.awt.Paint)2 DecimalFormat (java.text.DecimalFormat)2 FieldPosition (java.text.FieldPosition)2 NumberFormat (java.text.NumberFormat)2 ParsePosition (java.text.ParsePosition)2 ValueAxis (org.jfree.chart.axis.ValueAxis)2 AbstractXYItemRenderer (org.jfree.chart.renderer.xy.AbstractXYItemRenderer)2 XYAreaRenderer (org.jfree.chart.renderer.xy.XYAreaRenderer)2 XYDifferenceRenderer (org.jfree.chart.renderer.xy.XYDifferenceRenderer)2 XYDotRenderer (org.jfree.chart.renderer.xy.XYDotRenderer)2