Example usage for org.jfree.chart.plot.dial DialPlot DialPlot

List of usage examples for org.jfree.chart.plot.dial DialPlot DialPlot

Introduction

In this page you can find the example usage for org.jfree.chart.plot.dial DialPlot DialPlot.

Prototype

public DialPlot(ValueDataset dataset) 

Source Link

Document

Creates a new instance of DialPlot.

Usage

From source file:org.cyberoam.iview.charts.MeterChart.java

/**
 * This method generates JFreeChart instance for Meter chart with dial port and iView customization.
 * @param reportID/* ww  w. ja va2s  .  c  o m*/
 * @param rsw
 * @param request
 * @return
 */
public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
    JFreeChart chart = null;
    ReportColumnBean reportColumnBean = null;
    GraphBean graphBean = null;
    try {
        DefaultValueDataset data = null;
        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        String yColumnDBname = reportColumnBean.getDbColumnName();
        rsw.first();
        double used = Double.parseDouble(rsw.getString(yColumnDBname));
        data = new DefaultValueDataset(100 - used);
        DialPlot plot = new DialPlot(data);
        chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);

        chart.setBackgroundPaint(Color.white);
        int imgWidth = graphBean.getWidth();
        int imgHeight = graphBean.getHeight();
        if (request != null && request.getParameter("imgwidth") != null
                && !"".equalsIgnoreCase(request.getParameter("imgwidth"))
                && !"null".equalsIgnoreCase(request.getParameter("imgwidth"))) {
            imgWidth = Integer.parseInt(request.getParameter("imgwidth"));
        }
        if (request != null && request.getParameter("imgheight") != null
                && !"".equalsIgnoreCase(request.getParameter("imgheight"))
                && !"null".equalsIgnoreCase(request.getParameter("imgheight"))) {
            imgHeight = Integer.parseInt(request.getParameter("imgheight"));
        }
        plot.setView((1 - ((double) imgWidth / (double) imgHeight)) / 2, plot.getViewY(),
                ((double) imgWidth / (double) imgHeight), plot.getViewHeight());
        StandardDialFrame dialFrame = new StandardDialFrame();
        dialFrame.setBackgroundPaint(new Color(54, 73, 109));
        dialFrame.setRadius(0.8);
        dialFrame.setStroke(new BasicStroke(0));
        plot.setDialFrame(dialFrame);
        GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
                new Color(196, 210, 219));
        DialBackground db = new DialBackground(gp);
        db.setGradientPaintTransformer(
                new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
        plot.setBackground(db);

        DialValueIndicator dvi = new DialValueIndicator(0);
        dvi.setRadius(0.55);
        dvi.setBackgroundPaint(gp);
        dvi.setNumberFormat(new DecimalFormat("###"));
        dvi.setFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        dvi.setOutlinePaint(Color.lightGray);
        plot.addLayer(dvi);

        StandardDialScale scale = new StandardDialScale(0, 100, -120, -300, 10, 4);
        scale.setTickRadius(0.75);
        scale.setTickLabelOffset(0.15);
        scale.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 9));
        plot.addScale(0, scale);

        StandardDialRange range = new StandardDialRange(0.0, 50.0, Color.green);
        range.setInnerRadius(0.35);
        range.setOuterRadius(0.38);
        plot.addLayer(range);

        StandardDialRange range2 = new StandardDialRange(50.0, 75.0, Color.yellow);
        range2.setInnerRadius(0.35);
        range2.setOuterRadius(0.38);
        plot.addLayer(range2);

        StandardDialRange range3 = new StandardDialRange(75.0, 100.0, Color.red);
        range3.setInnerRadius(0.35);
        range3.setOuterRadius(0.38);
        plot.addLayer(range3);

        DialPointer needle = new DialPointer.Pointer();
        needle.setRadius(0.55);
        plot.addLayer(needle);

        DialCap cap = new DialCap();
        cap.setRadius(0.05);
        plot.setCap(cap);

    } catch (Exception e) {
        CyberoamLogger.appLog.debug("MeterChart=>Exception : " + e, e);
    }
    return chart;
}

From source file:org.rdv.viz.dial.DialPanel.java

/**
 * Creates the panel containing the dial.
 * /*w  w  w  .  j  av  a2s . co m*/
 * @return  the dial panel
 */
private JPanel createDialPanel() {
    plot = new DialPlot(dataset);

    plot.setDialFrame(new StandardDialFrame());

    engineeringFormat = new EngineeringFormat();
    engineeringFormatWithUnit = new EngineeringFormat();

    dialValueIndicator = new DialValueIndicator();
    dialValueIndicator.setOutlinePaint(Color.black);
    dialValueIndicator.setRadius(0.7);
    dialValueIndicator.setVisible(false);
    dialValueIndicator.setNumberFormat(engineeringFormatWithUnit);
    plot.addLayer(dialValueIndicator);

    dialTextAnnotation = new DialTextAnnotation("");
    dialTextAnnotation.setRadius(0.8);
    plot.addLayer(dialTextAnnotation);

    DialPointer dialPointer = new DialPointer.Pointer();
    dialPointer.setRadius(0.9);
    plot.addPointer(dialPointer);

    plot.setCap(new DialCap());

    dialScale = new BoundedDialScale();
    dialScale.setStartAngle(-120);
    dialScale.setExtent(-300);
    dialScale.setMinorTickCount(5);
    dialScale.setTickLabelFormatter(engineeringFormat);
    dialScale.setTickRadius(0.9);

    JFreeChart chart = new JFreeChart(plot);
    chart.removeLegend();

    return new ChartPanel(chart);
}