Example usage for org.jfree.chart JFreeChart getRenderingHints

List of usage examples for org.jfree.chart JFreeChart getRenderingHints

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getRenderingHints.

Prototype

public RenderingHints getRenderingHints() 

Source Link

Document

Returns the collection of rendering hints for the chart.

Usage

From source file:com.sdk.connector.chart.FrequencyDomainRenderer.java

/**
 * Creates a new demo application.//from  w  ww .  j ava 2  s  . c o  m
 *
 * @param title  the frame title.
 */
public FrequencyDomainRenderer(String title, JPanel panel, String side, String type) {

    this.side = side;
    this.type = type;
    serie.setKey(side);

    dataset.addSeries(serie);
    JFreeChart chart = ChartFactory.createXYAreaChart(title,
            java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("frequency.xlabel"),
            java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("frequency.ylabel2"),
            dataset, PlotOrientation.VERTICAL, true, true, false);

    //        TextTitle t1 = new TextTitle( "Espectro de Frequncia Estimado (PSD)", new Font("SansSerif", Font.BOLD, 14)  );
    //        //TextTitle t2 = new TextTitle( "valores atualizados a cada potncia de 2", new Font("SansSerif", Font.PLAIN, 11)      );
    //        chart.addSubtitle(t1);
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    chart.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    chart.getRenderingHints().put(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    chart.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS,
            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    chart.getRenderingHints().put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    chart.getRenderingHints().put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    chart.getRenderingHints().put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 100);
    //chart.addSubtitle(t2);
    plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.BLUE);
    plot.setRangeGridlinePaint(Color.CYAN);
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f));

    //plot.setRangePannable(true);
    plot.setForegroundAlpha(0.65f);

    //XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer = plot.getRenderer();
    renderer.setSeriesOutlinePaint(0, Color.BLACK);
    if (side.startsWith(
            java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("side.left"))) {
        renderer.setSeriesPaint(0, Color.BLUE);
    } else {
        renderer.setSeriesPaint(0, Color.RED);
    }
    //        renderer.setSeriesLinesVisible(0, true);
    //        renderer.setSeriesShapesVisible(0, false);
    //        renderer.setSeriesLinesVisible(1, true);
    //        renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.BLACK);
    plot.setRangeGridlinePaint(Color.BLACK);
    plot.setForegroundAlpha(0.5f);

    Color color1 = new Color(0, 0, 0, 24);
    Color color2 = new Color(255, 255, 255, 24);

    GradientPaint gp = new GradientPaint(0, 0, color1, 0, 0, color2);
    plot.setBackgroundPaint(gp);

    final ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickMarkPaint(Color.black);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    NumberAxis numDomainAxis = (NumberAxis) plot.getDomainAxis();
    numDomainAxis.setAutoRangeIncludesZero(true);
    //
    //        final NumberAxis rangeAxis = new LogarithmicAxis("Log(y)");
    //
    //        plot.setRangeAxis(rangeAxis);
    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setTickMarkPaint(Color.black);

    numRangeAxis = (NumberAxis) plot.getRangeAxis();
    numRangeAxis.setAutoRangeIncludesZero(true);

    vlfTarget.setLabel("VLF");
    vlfTarget.setLabelFont(new Font("SansSerif", Font.ITALIC, 9));
    vlfTarget.setLabelAnchor(RectangleAnchor.CENTER);
    vlfTarget.setLabelTextAnchor(TextAnchor.CENTER);
    vlfTarget.setPaint(new Color(0, 100, 255, 128));
    // plot.addRangeMarker(target, Layer.BACKGROUND);
    plot.addDomainMarker(vlfTarget, Layer.BACKGROUND);

    lfTarget.setLabel("LF");
    lfTarget.setLabelFont(new Font("SansSerif", Font.ITALIC, 9));
    lfTarget.setLabelAnchor(RectangleAnchor.CENTER);
    lfTarget.setLabelTextAnchor(TextAnchor.CENTER);
    lfTarget.setPaint(new Color(255, 255, 0, 128));
    // plot.addRangeMarker(target, Layer.BACKGROUND);
    plot.addDomainMarker(lfTarget, Layer.BACKGROUND);

    hfTarget.setLabel("HF");
    hfTarget.setLabelFont(new Font("SansSerif", Font.ITALIC, 9));
    hfTarget.setLabelAnchor(RectangleAnchor.CENTER);
    hfTarget.setLabelTextAnchor(TextAnchor.CENTER);
    hfTarget.setPaint(new Color(255, 0, 255, 128));
    // plot.addRangeMarker(target, Layer.BACKGROUND);
    plot.addDomainMarker(hfTarget, Layer.BACKGROUND);
    plot.setNoDataMessage(
            java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("message.wait"));

    chartPanel = new ChartPanel(chart);

    panel.setLayout(new GridLayout(0, 1));
    panel.add(chartPanel);
    panel.repaint();
    panel.revalidate();

}

From source file:eu.planets_project.tb.impl.chart.ExperimentChartServlet.java

/**
 * Process a GET request.//from   w w  w . j  av a2  s  .  c  om
 *
 * @param request  the request.
 * @param response  the response.
 *
 * @throws ServletException if there is a servlet related problem.
 * @throws IOException if there is an I/O problem.
 */
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    OutputStream out = response.getOutputStream();
    try {
        String type = request.getParameter("type");
        String format = request.getParameter("format");
        String eid = request.getParameter("eid");

        JFreeChart chart = null;
        if ("pie".equalsIgnoreCase(type)) {
            chart = createPieChart();
        } else if ("bar".equalsIgnoreCase(type)) {
            chart = createBarChart();
        } else if ("time".equalsIgnoreCase(type)) {
            chart = createTimeSeriesChart();
        } else if ("exp".equalsIgnoreCase(type)) {
            chart = createXYChart(eid);
        } else if ("wall".equalsIgnoreCase(type)) {
            chart = createWallclockChart(eid);
        } else {
            chart = null;
        }
        // Render
        if (chart != null) {
            if ("svg".equalsIgnoreCase(format)) {
                response.setContentType("image/svg+xml");
                writeChartAsSVG(out, chart, 600, 500);
            } else {
                response.setContentType("image/png");
                // force aliasing of the rendered content..
                chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);
                ChartUtilities.writeChartAsPNG(out, chart, 600, 500);
            }
        }
    } catch (Exception e) {
        System.err.println(e.toString());
        e.printStackTrace();
    } finally {
        out.close();
    }

}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java

/**
 * Updates the chart panel to show the provided {@link JFreeChart}. If the chart is
 * <code>null</code> an empty Plot will be shown. If an overlay has been defined and the chart
 * is a {@link XYPlot} the overlay is also drawn.
 *///from   w  ww  .j ava  2 s  . co m
private synchronized void updateChartPanel(final JFreeChart chart) {
    Runnable updateChartPanelRunnable = new Runnable() {

        @Override
        public void run() {
            if (chart != chartPanel.getChart()) {
                if (chart == null) {
                    chartPanel.setChart(new JFreeChart(new CategoryPlot()));

                    fireChartChanged(new JFreeChart(new CategoryPlot()));
                } else {
                    RenderingHints renderingHints = chart.getRenderingHints();

                    // enable antialiasing
                    renderingHints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON));

                    // disable normalization (normalization tries to draw the center of strokes
                    // at whole pixels, which causes e.g.
                    // scaled shapes to appear more like potatoes than like circles)
                    renderingHints.add(new RenderingHints(RenderingHints.KEY_STROKE_CONTROL,
                            RenderingHints.VALUE_STROKE_PURE));
                    chart.setRenderingHints(renderingHints);

                    chartPanel.setChart(chart);
                    fireChartChanged(chart);
                }
            }
            if (chart != null) {
                chartPanel.removeOverlay(crosshairOverlay);
                crosshairOverlay = new MultiAxesCrosshairOverlay();

                if (chart.getPlot() instanceof XYPlot) {
                    // add overlays for range axes
                    int axisIdx = 0;
                    for (RangeAxisConfig rangeAxisConfig : plotInstance.getCurrentPlotConfigurationClone()
                            .getRangeAxisConfigs()) {
                        for (AxisParallelLineConfiguration line : rangeAxisConfig.getCrossHairLines()
                                .getLines()) {
                            Crosshair crosshair = new Crosshair(line.getValue(), line.getFormat().getColor(),
                                    line.getFormat().getStroke());
                            crosshairOverlay.addRangeCrosshair(axisIdx, crosshair);
                        }
                        ++axisIdx;
                    }

                    // add overlays for domain axis
                    for (AxisParallelLineConfiguration line : plotInstance.getCurrentPlotConfigurationClone()
                            .getDomainConfigManager().getCrosshairLines().getLines()) {
                        Crosshair crosshair = new Crosshair(line.getValue(), line.getFormat().getColor(),
                                line.getFormat().getStroke());
                        crosshairOverlay.addDomainCrosshair(crosshair);
                    }
                    chartPanel.addOverlay(crosshairOverlay);
                }
            }
        }
    };

    if (SwingUtilities.isEventDispatchThread()) {
        updateChartPanelRunnable.run();
    } else {
        SwingUtilities.invokeLater(updateChartPanelRunnable);
    }

}

From source file:eu.planets_project.tb.impl.chart.ExperimentChartServlet.java

public JFreeChart createWallclockChart(String expId) {
    ExperimentPersistencyRemote edao = ExperimentPersistencyImpl.getInstance();
    long eid = Long.parseLong(expId);
    log.info("Building experiment chart for eid = " + eid);
    Experiment exp = edao.findExperiment(eid);

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    final String expName = exp.getExperimentSetup().getBasicProperties().getExperimentName();

    boolean hasSuccesses = false;
    boolean hasFails = false;

    for (BatchExecutionRecordImpl batch : exp.getExperimentExecutable().getBatchExecutionRecords()) {
        int i = 1;
        List<ExecutionRecordImpl> runs = new ArrayList<ExecutionRecordImpl>(batch.getRuns());
        Collections.sort(runs, new RunComparator());
        for (ExecutionRecordImpl exr : runs) {
            //log.info("Found Record... "+exr+" stages: "+exr.getStages());
            if (exr != null && exr.getStages() != null) {
                // Look up the object, so we can get the name.
                DigitalObjectRefBean dh = new DataHandlerImpl().get(exr.getDigitalObjectReferenceCopy());
                String dobName = "Object " + i;
                if (dh != null)
                    dobName = dh.getName();

                ResultsForDigitalObjectBean res = new ResultsForDigitalObjectBean(
                        exr.getDigitalObjectReferenceCopy());
                Double time = null;
                boolean success = false;
                // First, attempt to pull from stage records:
                // FIXME: Note that this record is really at the wrong level.
                /*/* w  w w .ja  v a  2 s. co m*/
                if( exr.getStages().size() == 1 ) {
                for( ExecutionStageRecordImpl exsr : exr.getStages() ) {
                    Double stageTime = exsr.getDoubleMeasurement( TecRegMockup.PROP_SERVICE_TIME );
                    if( stageTime != null ) {
                        time = stageTime;
                        success = exsr.isMarkedAsSuccessful();
                    }
                }
                }
                */
                // Pick up from record duration:
                if (time == null && res.getExecutionDuration() != null) {
                    //convert from milli seconds to seconds
                    time = (double) res.getExecutionDuration() / 1000.0;
                    success = res.getHasExecutionSucceededOK();
                }
                log.info("Found DOB: {" + exr.getDigitalObjectReferenceCopy() + "} {" + dobName + "} w/ time "
                        + time);
                if (res.getExecutionRecord() != null)
                    log.info("Timing: " + res.getExecutionRecord().getStartDate() + " "
                            + res.getExecutionRecord().getEndDate());
                if (time != null) {
                    if (success) {
                        dataset.addValue(time, "Succeeded", dobName);
                        hasSuccesses = true;
                    } else {
                        dataset.addValue(time, "Failed", dobName);
                        hasFails = true;
                    }
                }
            }
            // Increment, for the next run.
            i++;
        }
    }
    int si = dataset.getRowIndex("Succeeded");
    int ri = dataset.getRowIndex("Failed");

    // Create the chart.
    JFreeChart chart = ChartFactory.createStackedBarChart(null, "Digital Object", "Time [s]", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);

    // set the range axis to display integers only...
    //final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    //rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardBarPainter());

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f,
            new Color(0.0f, 0.9f, 0.0f));
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(0.9f, 0.0f, 0.0f));
    if (hasSuccesses)
        renderer.setSeriesPaint(si, gp0);
    if (hasFails)
        renderer.setSeriesPaint(ri, gp1);

    // Set the tooltips...
    //renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator("xy_chart.jsp","series","section"));
    renderer.setBaseToolTipGenerator(new MeasurementToolTipGenerator());

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0));

    // More settings
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Remove the border, as the SVG renderer has problems with the text overflowing.
    chart.getLegend().setBorder(0.0, 0.0, 0.0, 0.0);
    // Remove the padding between the axes and the plot:
    chart.getPlot().setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    // Set a gradient fill, fading towards the top:
    final GradientPaint gpb0 = new GradientPaint(0.0f, 0.0f, new Color(245, 245, 245), 0.0f, 0.0f, Color.white);
    chart.getPlot().setBackgroundPaint(gpb0);

    return chart;
}