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