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;
}
Aggregations