Search in sources :

Example 31 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project lotro-tools by dmorcellet.

the class ScalableStatChartController method buildChart.

private JFreeChart buildChart() {
    String xAxisLabel = "Item level";
    String yAxisLabel = getTitle();
    String title = yAxisLabel;
    XYDataset xydataset = createDataset();
    JFreeChart jfreechart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, xydataset, 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 plot = jfreechart.getXYPlot();
    plot.setDomainPannable(false);
    XYToolTipGenerator tooltip = new StandardXYToolTipGenerator() {

        @Override
        public String generateLabelString(XYDataset dataset, int series, int item) {
            String name = (String) ((XYSeriesCollection) dataset).getSeriesKey(series);
            double value = dataset.getYValue(series, item);
            int level = (int) dataset.getXValue(series, item);
            return name + ": " + level + " -> " + value;
        }
    };
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setBaseToolTipGenerator(tooltip);
    plot.setRenderer(renderer);
    // X axis
    NumberAxis axis = (NumberAxis) plot.getDomainAxis();
    axis.setAxisLinePaint(foregroundColor);
    axis.setLabelPaint(foregroundColor);
    axis.setTickLabelPaint(foregroundColor);
    // Y axis
    NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis();
    valueAxis.setAutoRange(true);
    valueAxis.setAutoRangeIncludesZero(false);
    valueAxis.setAxisLinePaint(foregroundColor);
    valueAxis.setLabelPaint(foregroundColor);
    valueAxis.setTickLabelPaint(foregroundColor);
    LegendTitle legend = jfreechart.getLegend();
    legend.setPosition(RectangleEdge.BOTTOM);
    legend.setItemPaint(foregroundColor);
    legend.setBackgroundPaint(backgroundPaint);
    return jfreechart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) LegendTitle(org.jfree.chart.title.LegendTitle) Paint(java.awt.Paint) 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)

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