Search in sources :

Example 11 with LegendTitle

use of org.jfree.chart.title.LegendTitle 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 12 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project dbeaver by serge-rider.

the class DashboardRendererBase method createDefaultLegend.

protected void createDefaultLegend(DashboardItemViewConfiguration viewConfig, JFreeChart chart) {
    Color gridColor = AWTUtils.makeAWTColor(UIStyles.getDefaultTextForeground());
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.BOTTOM);
    legend.setBorder(0, 0, 0, 0);
    legend.setBackgroundPaint(chart.getBackgroundPaint());
    legend.setItemPaint(gridColor);
    legend.setItemFont(DEFAULT_LEGEND_FONT);
    if (viewConfig != null && !viewConfig.isLegendVisible()) {
        legend.setVisible(false);
    }
}
Also used : LegendTitle(org.jfree.chart.title.LegendTitle)

Example 13 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project n2a by frothga.

the class Plot method updateChart.

public void updateChart(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();
    plot.setNotify(false);
    updateDatasets();
    LegendTitle legend = chart.getLegend();
    legend.setVisible(columnCount <= 10);
    NumberAxis axis0 = (NumberAxis) plot.getRangeAxis();
    axis0.setAutoRangeIncludesZero(false);
    if (range0 > 0)
        axis0.setAutoRangeMinimumSize(range0 / 2);
    else
        axis0.setAutoRangeMinimumSize(1);
    // range locked
    if (!Double.isNaN(ymin))
        axis0.setRange(ymin, ymax);
    if (!Double.isNaN(xmin)) {
        ValueAxis x = plot.getDomainAxis();
        x.setRange(xmin, xmax);
    }
    int count = dataset0.getSeriesCount();
    float shift = 0;
    if (dataset1 != null) {
        // So we use only half of the color range
        count *= 2;
        shift = 0.75f + 0.5f / count;
    }
    XYLineAndShapeRenderer renderer;
    XYItemRenderer ir = plot.getRenderer();
    if (ir instanceof XYLineAndShapeRenderer) {
        renderer = (XYLineAndShapeRenderer) ir;
    } else {
        renderer = new XYLineAndShapeRenderer();
        plot.setRenderer(renderer);
    }
    for (int i = 0; i < dataset0.getSeriesCount(); i++) {
        Column column = left.get(i);
        // does not fire renderer change event
        styleSeries(renderer, i, column, count, shift);
    }
    // fires renderer change event
    renderer.setDrawSeriesLineAsPath(true);
    if (dataset1 == null) {
        axis0.setTickMarkPaint(Color.black);
        axis0.setTickLabelPaint(Color.black);
        axis0.setAxisLinePaint(Color.black);
        plot.setDataset(1, null);
        plot.setRangeAxis(1, null);
        plot.setRenderer(1, null);
    } else {
        Color color0 = Color.getHSBColor(0.0f, 1.0f, 0.8f);
        axis0.setTickMarkPaint(color0);
        axis0.setTickLabelPaint(color0);
        axis0.setAxisLinePaint(color0);
        plot.setDataset(1, dataset1);
        plot.mapDatasetToRangeAxis(1, 1);
        NumberAxis axis1 = (NumberAxis) plot.getRangeAxis(1);
        if (axis1 == null) {
            axis1 = new NumberAxis();
            axis1.setAutoRangeIncludesZero(false);
            axis1.setTickLabelFont(axis0.getTickLabelFont());
            Color color1 = Color.getHSBColor(0.5f, 1.0f, 0.8f);
            axis1.setTickMarkPaint(color1);
            axis1.setTickLabelPaint(color1);
            axis1.setAxisLinePaint(color1);
            plot.setRangeAxis(1, axis1);
        }
        // else we created axis1, so all the initial settings are correct
        if (range1 > 0)
            axis1.setAutoRangeMinimumSize(range1 / 2);
        else
            axis1.setAutoRangeMinimumSize(1);
        count = dataset1.getSeriesCount() * 2;
        shift = 0.25f + 0.5f / count;
        ir = plot.getRenderer(1);
        if (ir instanceof XYLineAndShapeRenderer) {
            renderer = (XYLineAndShapeRenderer) ir;
        } else {
            renderer = new XYLineAndShapeRenderer();
            plot.setRenderer(1, renderer);
        }
        for (int i = 0; i < dataset1.getSeriesCount(); i++) {
            Column column = right.get(i);
            styleSeries(renderer, i, column, count, shift);
        }
        renderer.setDrawSeriesLineAsPath(true);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    }
    plot.setNotify(true);
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) LegendTitle(org.jfree.chart.title.LegendTitle) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer)

Example 14 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project violations-plugin by jenkinsci.

the class SeverityTypeDataSet method createChart.

/**
 * Create a JFree chart for this dataset.
 *
 * @return the chart.
 */
public JFreeChart createChart() {
    CategoryDataset dataset = buildDataSet();
    JFreeChart chart = // chart
    ChartFactory.createStackedAreaChart(// chart
    null, // unused
    null, // range axis label
    "count", // data
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips
    true, // urls
    false);
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(ALPHA);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);
    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (Boolean.getBoolean(AbstractViolationsBuildAction.VIOLATIONS_PLUGIN_CHART_AUTORANGE_PROPERTY)) {
        rangeAxis.setAutoRange(true);
        rangeAxis.setAutoRangeIncludesZero(false);
        rangeAxis.setAutoRangeMinimumSize(50);
    }
    StackedAreaRenderer renderer = new StackedAreaRenderer2();
    plot.setRenderer(renderer);
    renderer.setSeriesPaint(2, RED);
    renderer.setSeriesPaint(1, VIOLET);
    renderer.setSeriesPaint(0, YELLOW);
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, INSET));
    return chart;
}
Also used : ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) ShiftedCategoryAxis(hudson.util.ShiftedCategoryAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleInsets(org.jfree.ui.RectangleInsets) LegendTitle(org.jfree.chart.title.LegendTitle) StackedAreaRenderer2(hudson.util.StackedAreaRenderer2) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) StackedAreaRenderer(org.jfree.chart.renderer.category.StackedAreaRenderer)

Example 15 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project SIMVA-SoS by SESoS.

the class StandardChartTheme method applyToTitle.

/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    } else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    } else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    } else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) PaintScaleLegend(org.jfree.chart.title.PaintScaleLegend) BlockContainer(org.jfree.chart.block.BlockContainer) ValueAxis(org.jfree.chart.axis.ValueAxis) Iterator(java.util.Iterator) LabelBlock(org.jfree.chart.block.LabelBlock) Block(org.jfree.chart.block.Block) Title(org.jfree.chart.title.Title) TextTitle(org.jfree.chart.title.TextTitle) LegendTitle(org.jfree.chart.title.LegendTitle) CompositeTitle(org.jfree.chart.title.CompositeTitle) LegendTitle(org.jfree.chart.title.LegendTitle) List(java.util.List) CompositeTitle(org.jfree.chart.title.CompositeTitle)

Aggregations

LegendTitle (org.jfree.chart.title.LegendTitle)31 JFreeChart (org.jfree.chart.JFreeChart)19 NumberAxis (org.jfree.chart.axis.NumberAxis)17 XYPlot (org.jfree.chart.plot.XYPlot)15 Color (java.awt.Color)14 Font (java.awt.Font)13 TextTitle (org.jfree.chart.title.TextTitle)12 ValueAxis (org.jfree.chart.axis.ValueAxis)11 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)11 XYDataset (org.jfree.data.xy.XYDataset)10 BasicStroke (java.awt.BasicStroke)9 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)9 Paint (java.awt.Paint)8 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)8 DecimalFormat (java.text.DecimalFormat)7 GridBagConstraints (java.awt.GridBagConstraints)6 Stroke (java.awt.Stroke)6 ChartPanel (org.jfree.chart.ChartPanel)6 XYSeries (org.jfree.data.xy.XYSeries)6 StandardXYSeriesLabelGenerator (org.jfree.chart.labels.StandardXYSeriesLabelGenerator)5