use of org.jfree.chart.labels.StandardXYToolTipGenerator in project mafscaling by vimsh.
the class VECalc method createChart.
protected void createChart(JPanel plotPanel, String xAxisName, String yAxisName) {
JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
chart.setBorderVisible(true);
chartPanel = new ChartPanel(chart, true, true, true, true, true);
chartPanel.setAutoscrolls(true);
chartPanel.setMouseZoomable(false);
GridBagConstraints gbl_chartPanel = new GridBagConstraints();
gbl_chartPanel.anchor = GridBagConstraints.CENTER;
gbl_chartPanel.insets = new Insets(3, 3, 3, 3);
gbl_chartPanel.weightx = 1.0;
gbl_chartPanel.weighty = 1.0;
gbl_chartPanel.fill = GridBagConstraints.BOTH;
gbl_chartPanel.gridx = 0;
gbl_chartPanel.gridy = 1;
plotPanel.add(chartPanel, gbl_chartPanel);
XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
lineRenderer.setUseFillPaint(true);
lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
lineRenderer.setSeriesStroke(0, stroke);
lineRenderer.setSeriesPaint(0, Color.RED);
lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
private static final long serialVersionUID = 7593430826693873496L;
public String generateLabel(XYDataset dataset, int series) {
XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
return xys.getDescription();
}
});
NumberAxis xAxis = new NumberAxis(xAxisName);
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis(yAxisName);
yAxis.setAutoRangeIncludesZero(false);
XYSeriesCollection lineDataset = new XYSeriesCollection();
XYPlot plot = chart.getXYPlot();
plot.setRangePannable(true);
plot.setDomainPannable(true);
plot.setDomainGridlinePaint(Color.DARK_GRAY);
plot.setRangeGridlinePaint(Color.DARK_GRAY);
plot.setBackgroundPaint(new Color(224, 224, 224));
plot.setDataset(0, lineDataset);
plot.setRenderer(0, lineRenderer);
plot.setDomainAxis(0, xAxis);
plot.setRangeAxis(0, yAxis);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
LegendTitle legend = new LegendTitle(plot.getRenderer());
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
chart.addLegend(legend);
}
use of org.jfree.chart.labels.StandardXYToolTipGenerator 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