Search in sources :

Example 11 with StandardXYSeriesLabelGenerator

use of org.jfree.chart.labels.StandardXYSeriesLabelGenerator 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)

Aggregations

StandardXYSeriesLabelGenerator (org.jfree.chart.labels.StandardXYSeriesLabelGenerator)11 JFreeChart (org.jfree.chart.JFreeChart)7 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)7 XYPlot (org.jfree.chart.plot.XYPlot)7 DecimalFormat (java.text.DecimalFormat)6 NumberAxis (org.jfree.chart.axis.NumberAxis)6 BasicStroke (java.awt.BasicStroke)5 Color (java.awt.Color)5 Font (java.awt.Font)5 GridBagConstraints (java.awt.GridBagConstraints)5 Stroke (java.awt.Stroke)5 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)5 LegendTitle (org.jfree.chart.title.LegendTitle)5 XYDataset (org.jfree.data.xy.XYDataset)5 XYSeries (org.jfree.data.xy.XYSeries)5 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)5 Insets (java.awt.Insets)4 ChartPanel (org.jfree.chart.ChartPanel)4 Test (org.junit.Test)4 ValueAxis (org.jfree.chart.axis.ValueAxis)3