Search in sources :

Example 1 with TickUnitSource

use of org.jfree.chart.axis.TickUnitSource in project lotro-companion by dmorcellet.

the class CharacterLevelChartController method buildChart.

private JFreeChart buildChart() {
    String title = "Characters levelling";
    String timeAxisLabel = "Time";
    String valueAxisLabel = "Level";
    XYDataset xydataset = createDataset();
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, timeAxisLabel, valueAxisLabel, xydataset, 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);
            int level = (int) dataset.getYValue(series, item);
            double timestamp = dataset.getXValue(series, item);
            String date = Formats.getDateString(Long.valueOf((long) timestamp));
            return name + " - " + level + " (" + date + ")";
        }
    };
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseToolTipGenerator(tooltip);
    // Time axis
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    SimpleDateFormat sdf = Formats.getDateFormatter();
    axis.setDateFormatOverride(sdf);
    axis.setAxisLinePaint(foregroundColor);
    axis.setLabelPaint(foregroundColor);
    axis.setTickLabelPaint(foregroundColor);
    // Level axis
    NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis();
    valueAxis.setAutoRange(true);
    valueAxis.setAxisLinePaint(foregroundColor);
    valueAxis.setLabelPaint(foregroundColor);
    valueAxis.setTickLabelPaint(foregroundColor);
    TickUnitSource ticks = getLevelTicks();
    valueAxis.setStandardTickUnits(ticks);
    LegendTitle legend = jfreechart.getLegend();
    legend.setPosition(RectangleEdge.BOTTOM);
    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) TickUnitSource(org.jfree.chart.axis.TickUnitSource) 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) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Color (java.awt.Color)1 Paint (java.awt.Paint)1 SimpleDateFormat (java.text.SimpleDateFormat)1 JFreeChart (org.jfree.chart.JFreeChart)1 DateAxis (org.jfree.chart.axis.DateAxis)1 NumberAxis (org.jfree.chart.axis.NumberAxis)1 TickUnitSource (org.jfree.chart.axis.TickUnitSource)1 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)1 XYToolTipGenerator (org.jfree.chart.labels.XYToolTipGenerator)1 XYPlot (org.jfree.chart.plot.XYPlot)1 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)1 LegendTitle (org.jfree.chart.title.LegendTitle)1 TextTitle (org.jfree.chart.title.TextTitle)1 XYDataset (org.jfree.data.xy.XYDataset)1