Search in sources :

Example 16 with StandardXYToolTipGenerator

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);
}
Also used : BasicStroke(java.awt.BasicStroke) XYSeries(org.jfree.data.xy.XYSeries) GridBagConstraints(java.awt.GridBagConstraints) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) ChartPanel(org.jfree.chart.ChartPanel) Insets(java.awt.Insets) NumberAxis(org.jfree.chart.axis.NumberAxis) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) DecimalFormat(java.text.DecimalFormat) StandardXYSeriesLabelGenerator(org.jfree.chart.labels.StandardXYSeriesLabelGenerator) Color(java.awt.Color) LegendTitle(org.jfree.chart.title.LegendTitle) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) XYDataset(org.jfree.data.xy.XYDataset) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

Example 17 with StandardXYToolTipGenerator

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

JFreeChart (org.jfree.chart.JFreeChart)17 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)17 NumberAxis (org.jfree.chart.axis.NumberAxis)16 XYPlot (org.jfree.chart.plot.XYPlot)16 Color (java.awt.Color)10 LegendTitle (org.jfree.chart.title.LegendTitle)10 XYDataset (org.jfree.data.xy.XYDataset)10 DecimalFormat (java.text.DecimalFormat)9 SimpleDateFormat (java.text.SimpleDateFormat)8 XYToolTipGenerator (org.jfree.chart.labels.XYToolTipGenerator)8 DateAxis (org.jfree.chart.axis.DateAxis)7 BasicStroke (java.awt.BasicStroke)6 Font (java.awt.Font)6 GridBagConstraints (java.awt.GridBagConstraints)6 Stroke (java.awt.Stroke)6 ValueAxis (org.jfree.chart.axis.ValueAxis)6 StandardXYSeriesLabelGenerator (org.jfree.chart.labels.StandardXYSeriesLabelGenerator)6 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)6 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)6 XYSeries (org.jfree.data.xy.XYSeries)5