Example usage for org.jfree.chart.plot MeterPlot setValueFont

List of usage examples for org.jfree.chart.plot MeterPlot setValueFont

Introduction

In this page you can find the example usage for org.jfree.chart.plot MeterPlot setValueFont.

Prototype

public void setValueFont(Font font) 

Source Link

Document

Sets the font used to display the value label and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:org.jfree.chart.demo.MeterChartDemo1.java

private static JFreeChart createChart(ValueDataset valuedataset) {
    MeterPlot meterplot = new MeterPlot(valuedataset);
    meterplot.setRange(new Range(0.0D, 60D));
    meterplot.addInterval(new MeterInterval("Normal", new Range(0.0D, 35D), Color.lightGray,
            new BasicStroke(2.0F), new Color(0, 255, 0, 64)));
    meterplot.addInterval(new MeterInterval("Warning", new Range(35D, 50D), Color.lightGray,
            new BasicStroke(2.0F), new Color(255, 255, 0, 64)));
    meterplot.addInterval(new MeterInterval("Critical", new Range(50D, 60D), Color.lightGray,
            new BasicStroke(2.0F), new Color(255, 0, 0, 128)));
    meterplot.setNeedlePaint(Color.darkGray);
    meterplot.setDialBackgroundPaint(Color.white);
    meterplot.setDialOutlinePaint(Color.gray);
    meterplot.setDialShape(DialShape.CHORD);
    meterplot.setMeterAngle(260);//w w w.jav a2  s  . c  om
    meterplot.setTickLabelsVisible(true);
    meterplot.setTickLabelFont(new Font("Dialog", 1, 10));
    meterplot.setTickLabelPaint(Color.darkGray);
    meterplot.setTickSize(5D);
    meterplot.setTickPaint(Color.lightGray);
    meterplot.setValuePaint(Color.black);
    meterplot.setValueFont(new Font("Dialog", 1, 14));
    JFreeChart jfreechart = new JFreeChart("Meter Chart 1", JFreeChart.DEFAULT_TITLE_FONT, meterplot, true);
    return jfreechart;
}

From source file:org.jfree.chart.demo.MeterChartDemo3.java

private static JFreeChart createChart(String s, ValueDataset valuedataset, DialShape dialshape) {
    MeterPlot meterplot = new MeterPlot(valuedataset);
    meterplot.setDialShape(dialshape);/*w  ww . ja v  a 2s . c om*/
    meterplot.setRange(new Range(0.0D, 60D));
    meterplot.addInterval(new MeterInterval("Normal", new Range(0.0D, 35D), Color.lightGray,
            new BasicStroke(2.0F), new Color(0, 255, 0, 64)));
    meterplot.addInterval(new MeterInterval("Warning", new Range(35D, 50D), Color.lightGray,
            new BasicStroke(2.0F), new Color(255, 255, 0, 64)));
    meterplot.addInterval(new MeterInterval("Critical", new Range(50D, 60D), Color.lightGray,
            new BasicStroke(2.0F), new Color(255, 0, 0, 128)));
    meterplot.setNeedlePaint(Color.darkGray);
    meterplot.setDialBackgroundPaint(Color.white);
    meterplot.setDialOutlinePaint(Color.gray);
    meterplot.setMeterAngle(260);
    meterplot.setTickLabelsVisible(true);
    meterplot.setTickLabelFont(new Font("Dialog", 1, 10));
    meterplot.setTickLabelPaint(Color.darkGray);
    meterplot.setTickSize(5D);
    meterplot.setTickPaint(Color.lightGray);
    meterplot.setValuePaint(Color.black);
    meterplot.setValueFont(new Font("Dialog", 1, 14));
    JFreeChart jfreechart = new JFreeChart(s, JFreeChart.DEFAULT_TITLE_FONT, meterplot, true);
    return jfreechart;
}

From source file:it.eng.spagobi.engines.kpi.bo.charttypes.dialcharts.Meter.java

/**
 * Creates the MeterChart .//from   w w  w . java  2 s . c  o m
 * 
 * @return A MeterChart .
 */
public JFreeChart createChart() {
    logger.debug("IN");
    if (dataset == null) {
        logger.debug("The dataset to be represented is null");
        return null;
    }
    MeterPlot plot = new MeterPlot((ValueDataset) dataset);
    logger.debug("Created new plot");
    plot.setRange(new Range(lower, upper));
    logger.debug("Setted plot range");

    for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
        KpiInterval interval = (KpiInterval) iterator.next();
        plot.addInterval(new MeterInterval(interval.getLabel(), new Range(interval.getMin(), interval.getMax()),
                Color.lightGray, new BasicStroke(2.0f), interval.getColor()));
        logger.debug("Added new interval to the plot");
    }

    plot.setNeedlePaint(Color.darkGray);
    plot.setDialBackgroundPaint(Color.white);
    plot.setDialOutlinePaint(Color.gray);
    plot.setDialShape(DialShape.CHORD);
    plot.setMeterAngle(260);
    plot.setTickLabelsVisible(true);
    Font f = new Font("Arial", Font.PLAIN, 11);
    plot.setTickLabelFont(f);
    plot.setTickLabelPaint(Color.darkGray);
    plot.setTickSize(5.0);
    plot.setTickPaint(Color.lightGray);
    plot.setValuePaint(Color.black);
    plot.setValueFont(new Font("Arial", Font.PLAIN, 14));
    logger.debug("Setted all properties of the plot");

    JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    logger.debug("Created the chart");
    chart.setBackgroundPaint(color);
    logger.debug("Setted background color of the chart");

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    logger.debug("Setted the title of the chart");
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
        logger.debug("Setted the subtitle of the chart");
    }
    logger.debug("OUT");
    return chart;
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

/**
 * Creates a JFreeChart object from a dial definition object. All of the settings for the dial image are defined
 * by the dial definition.//from   ww w . j  a  va 2s .  c  o m
 * 
 * @param widget
 *          The dial definition object.
 * @param title
 *          The dial title.
 * @param units
 *          The dial units
 * @return A JFreeChart object for the dial
 */
private static JFreeChart createDial(final DialWidgetDefinition widget, final String title,
        final String units) {
    MeterPlot meter = new MeterPlot(widget);

    JFreeChartEngine.updatePlot(meter, widget);
    meter.setUnits(units);

    meter.setValuePaint(widget.getValuePaint());
    meter.setTickPaint(widget.getTickPaint());
    int tickSize = widget.getTickSize();
    if (tickSize == 0) {
        meter.setTickLabelsVisible(false);
    } else {
        meter.setTickLabelsVisible(true);
        meter.setTickSize(tickSize);
    }
    if (widget.getValueFont() != null) {
        meter.setValueFont(widget.getValueFont());
    } else {
        meter.setValuePaint(JFreeChartEngine.getTransparent());
    }
    // TODO support title fonts in the definition
    Font titleFont = widget.getTitleFont();

    JFreeChart chart = new JFreeChart(title, titleFont, meter, false);

    // TODO support any other MeterPlot properties

    return chart;
}

From source file:com.liferay.server.admin.web.internal.portlet.action.ViewChartMVCResourceCommand.java

protected MeterPlot getMeterPlot(ThemeDisplay themeDisplay, ValueDataset valueDataset) {

    MeterPlot meterPlot = new MeterPlot(valueDataset);

    meterPlot.addInterval(new MeterInterval(themeDisplay.translate("normal"), new Range(0.0D, 75D),
            Color.lightGray, new BasicStroke(2.0F), new Color(0, 255, 0, 64)));

    meterPlot.addInterval(new MeterInterval(themeDisplay.translate("warning"), new Range(75D, 90D),
            Color.lightGray, new BasicStroke(2.0F), new Color(255, 255, 0, 64)));

    meterPlot.addInterval(new MeterInterval(themeDisplay.translate("critical"), new Range(90D, 100D),
            Color.lightGray, new BasicStroke(2.0F), new Color(255, 0, 0, 128)));

    meterPlot.setDialBackgroundPaint(Color.white);
    meterPlot.setDialShape(DialShape.PIE);
    meterPlot.setDialOutlinePaint(Color.gray);
    meterPlot.setTickLabelFont(new Font(null, Font.PLAIN, 10));
    meterPlot.setTickLabelPaint(Color.darkGray);
    meterPlot.setTickLabelsVisible(true);
    meterPlot.setTickPaint(Color.lightGray);
    meterPlot.setTickSize(5D);/*from   ww  w.ja v a 2 s  . c o m*/
    meterPlot.setMeterAngle(180);
    meterPlot.setNeedlePaint(Color.darkGray);
    meterPlot.setRange(new Range(0.0D, 100D));
    meterPlot.setValueFont(new Font(null, Font.PLAIN, 10));
    meterPlot.setValuePaint(Color.black);
    meterPlot.setUnits("%");

    return meterPlot;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.Meter.java

/**
 * Creates the chart ./*from  www. j  a v a2s .  co m*/
 * 
 * @param chartTitle  the chart title.
 * @param dataset  the dataset.
 * 
 * @return A chart .
 */

public JFreeChart createChart(DatasetMap datasets) {

    Dataset dataset = (Dataset) datasets.getDatasets().get("1");

    MeterPlot plot = new MeterPlot((ValueDataset) dataset);
    plot.setRange(new Range(lower, upper));

    for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
        KpiInterval interval = (KpiInterval) iterator.next();

        plot.addInterval(new MeterInterval(interval.getLabel(), new Range(interval.getMin(), interval.getMax()),
                Color.lightGray, new BasicStroke(2.0f), interval.getColor()));
    }

    plot.setNeedlePaint(Color.darkGray);
    plot.setDialBackgroundPaint(Color.white);
    plot.setDialOutlinePaint(Color.gray);
    plot.setDialShape(DialShape.CHORD);
    plot.setMeterAngle(260);
    plot.setTickLabelsVisible(true);
    //set tick label style
    Font tickLabelsFont = new Font(labelsTickStyle.getFontName(), Font.PLAIN, labelsTickStyle.getSize());
    plot.setTickLabelFont(tickLabelsFont);
    plot.setTickLabelPaint(labelsTickStyle.getColor());
    plot.setTickSize(5.0);
    plot.setTickPaint(Color.lightGray);
    if (units != null) {
        plot.setUnits(units);
    }

    plot.setValuePaint(labelsValueStyle.getColor());
    plot.setValueFont(new Font(labelsValueStyle.getFontName(), Font.PLAIN, labelsValueStyle.getSize()));

    JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(color);

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    return chart;
}

From source file:org.adempiere.webui.apps.graph.WPerformanceIndicator.java

private JFreeChart createChart() {
    JFreeChart chart = null;/*from   ww  w  .  ja v a 2  s.co  m*/

    //   Set Text
    StringBuffer text = new StringBuffer(m_goal.getName());
    if (m_goal.isTarget())
        text.append(": ").append(m_goal.getPercent()).append("%");
    else
        text.append(": ").append(s_format.format(m_goal.getMeasureActual()));

    m_text = text.toString();

    //   ToolTip
    text = new StringBuffer();
    if (m_goal.getDescription() != null)
        text.append(m_goal.getDescription()).append(": ");
    text.append(s_format.format(m_goal.getMeasureActual()));
    if (m_goal.isTarget())
        text.append(" ").append(Msg.getMsg(Env.getCtx(), "of")).append(" ")
                .append(s_format.format(m_goal.getMeasureTarget()));
    setTooltiptext(text.toString());
    //
    DefaultValueDataset data = new DefaultValueDataset((float) m_goal.getPercent());
    MeterPlot plot = new MeterPlot(data);

    MColorSchema colorSchema = m_goal.getColorSchema();
    int rangeLo = 0;
    int rangeHi = 0;
    for (int i = 1; i <= 4; i++) {
        switch (i) {
        case 1:
            rangeHi = colorSchema.getMark1Percent();
            break;
        case 2:
            rangeHi = colorSchema.getMark2Percent();
            break;
        case 3:
            rangeHi = colorSchema.getMark3Percent();
            break;
        case 4:
            rangeHi = colorSchema.getMark4Percent();
            break;
        }
        if (rangeHi == 9999)
            rangeHi = (int) Math.floor(rangeLo * 1.5);
        if (rangeLo < rangeHi) {
            plot.addInterval(new MeterInterval("Normal", //label
                    new Range(rangeLo, rangeHi), //range
                    colorSchema.getColor(rangeHi), new BasicStroke(7.0f), new Color(-13091716)));
            rangeLo = rangeHi;
        }
    }
    plot.setRange(new Range(0, rangeLo));

    plot.setDialBackgroundPaint(new Color(-13091716));
    plot.setUnits("");
    plot.setDialShape(DialShape.CHORD);//CIRCLE);
    plot.setNeedlePaint(Color.white);
    plot.setTickSize(2000);
    plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 8));
    plot.setValueFont(new Font("SansSerif", Font.BOLD, 8));
    plot.setNoDataMessageFont(new Font("SansSerif", Font.BOLD, 8));
    plot.setTickLabelPaint(Color.white);
    plot.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));

    chart = new JFreeChart(m_text, new Font("SansSerif", Font.BOLD, 9), plot, false);

    return chart;
}

From source file:org.adempiere.webui.apps.graph.jfreegraph.PerformanceGraphBuilder.java

public JFreeChart createIndicatorChart(IndicatorModel model) {
    JFreeChart chart = null;//from   w  ww.  j a v  a 2s .  c om
    DefaultValueDataset data = new DefaultValueDataset((float) model.goalModel.getPercent());
    MeterPlot plot = new MeterPlot(data);

    MColorSchema colorSchema = model.goalModel.getColorSchema();
    int rangeLo = 0;
    int rangeHi = 0;
    Point2D start = new Point2D.Float(0, 0);
    Point2D end = new Point2D.Float(50, 50);
    float[] dist = { 0.0f, 0.2f, 0.45f, 0.75f, 1.0f };
    for (int i = 1; i <= 4; i++) {
        switch (i) {
        case 1:
            rangeHi = colorSchema.getMark1Percent();
            break;
        case 2:
            rangeHi = colorSchema.getMark2Percent();
            break;
        case 3:
            rangeHi = colorSchema.getMark3Percent();
            break;
        case 4:
            rangeHi = colorSchema.getMark4Percent();
            break;
        }
        if (rangeHi == 9999)
            rangeHi = (int) Math.floor(rangeLo * 1.5);
        if (rangeLo < rangeHi) {
            Color[] colors = { colorSchema.getColor(rangeHi).brighter().brighter(),
                    colorSchema.getColor(rangeHi).brighter(), colorSchema.getColor(rangeHi),
                    colorSchema.getColor(rangeHi).darker(), colorSchema.getColor(rangeHi).darker().darker() };
            LinearGradientPaint p = new LinearGradientPaint(start, end, dist, colors);

            plot.addInterval(new MeterInterval("Normal", //label
                    new Range(rangeLo, rangeHi), //range
                    p, new BasicStroke(7.0f), model.dialBackground));
            rangeLo = rangeHi;
        }
    }
    plot.setRange(new Range(0, rangeLo));
    plot.setDialBackgroundPaint(model.dialBackground);
    plot.setUnits("");
    plot.setDialShape(DialShape.CHORD);
    plot.setNeedlePaint(model.needleColor);
    plot.setTickSize(2000);
    plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 8));
    plot.setValueFont(new Font("SansSerif", Font.BOLD, 8));
    plot.setNoDataMessageFont(new Font("SansSerif", Font.BOLD, 8));
    plot.setTickLabelPaint(model.tickColor);
    plot.setValuePaint(new Color(0.0f, 0.0f, 0.0f, 0.0f));
    plot.setTickPaint(model.tickColor);
    //
    chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 9), plot, false);

    return chart;
}

From source file:ucar.unidata.idv.flythrough.Flythrough.java

/**
 * _more_/*  w  w  w.j  av a 2s  .com*/
 *
 * @param pt1 _more_
 *
 * @throws Exception _more_
 */
protected void processReadout(FlythroughPoint pt1) throws Exception {

    Font font = new Font("Dialog", Font.BOLD, 22);
    dials = new ArrayList<JComponent>();
    if ((readoutLabel == null) || (pt1 == null)) {
        return;
    }

    List<ReadoutInfo> samples = new ArrayList<ReadoutInfo>();
    readoutLabel.setText(readout.getReadout(pt1.getEarthLocation(), showReadout, true, samples));

    if (!showReadout) {
        return;
    }

    List comps = new ArrayList();
    for (FlythroughDecorator decorator : decorators) {
        decorator.handleReadout(pt1, samples);
    }

    for (ReadoutInfo info : samples) {
        Real r = info.getReal();
        if (r == null) {
            continue;
        }

        Unit unit = info.getUnit();
        if (unit == null) {
            unit = r.getUnit();
        }
        String name = ucar.visad.Util.cleanTypeName(r.getType());

        String unitSuffix = "";
        if (unit != null) {
            unitSuffix = " [" + unit + "]";
        }

        double v = r.getValue(unit);
        if (v == v) {
            v = Misc.parseNumber(Misc.format(v));
        }

        JLabel label = new JLabel(name.replace("_", " "));

        label.setFont(font);
        DefaultValueDataset dataset = new DefaultValueDataset(new Double(v));
        MeterPlot plot = new MeterPlot(dataset);
        if (info.getRange() != null) {
            Range range = info.getRange();
            plot.setRange(new org.jfree.data.Range(range.getMin(), range.getMax()));
        }
        if (unit != null) {
            plot.setUnits(unit.toString());
        } else {
            plot.setUnits("");
        }
        plot.setDialBackgroundPaint(Color.white);
        plot.setTickLabelsVisible(true);
        plot.setValueFont(font);
        plot.setTickLabelFont(font);
        plot.setTickLabelPaint(Color.darkGray);
        plot.setTickPaint(Color.black);
        plot.setValuePaint(Color.black);

        JFreeChart chart = new JFreeChart("", plot);
        TextTitle title = new TextTitle(" " + label.getText() + " ", font);
        title.setBackgroundPaint(Color.gray);
        title.setPaint(Color.white);
        chart.setTitle(title);
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(dialDimension);
        chartPanel.setSize(new Dimension(150, 150));
        plot.setBackgroundPaint(new Color(255, 255, 255, 0));
        plot.setBackgroundImageAlpha(0.0f);
        chart.setBackgroundPaint(new Color(255, 255, 255, 0));
        chartPanel.setBackground(new Color(255, 255, 255, 0));
        comps.add(chartPanel);
        dials.add(chartPanel);
    }

    readoutDisplay.removeAll();
    updateDashboard();

}

From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java

/**
 *
 *///  ww  w.j av  a 2 s  .c o m
protected JFreeChart createMeterChart() throws JRException {
    JRMeterPlot jrPlot = (JRMeterPlot) getPlot();

    // Start by creating the plot that will hold the meter
    MeterPlot chartPlot = new MeterPlot((ValueDataset) getDataset());

    // Set the shape
    MeterShapeEnum shape = jrPlot.getShapeValue() == null ? MeterShapeEnum.PIE : jrPlot.getShapeValue();
    switch (shape) {
    case CHORD:
        chartPlot.setDialShape(DialShape.CHORD);
        break;
    case CIRCLE:
        chartPlot.setDialShape(DialShape.CIRCLE);
        break;
    case PIE:
    default:
        chartPlot.setDialShape(DialShape.PIE);
    }

    // Set the meter's range
    chartPlot.setRange(convertRange(jrPlot.getDataRange()));

    // Set the size of the meter
    int meterAngle = jrPlot.getMeterAngleInteger() == null ? 180 : jrPlot.getMeterAngleInteger();
    chartPlot.setMeterAngle(meterAngle);

    // Set the units - this is just a string that will be shown next to the
    // value
    String units = jrPlot.getUnits();
    if (units != null && units.length() > 0) {
        chartPlot.setUnits(units);
    }

    // Set the font used for tick labels
    if (jrPlot.getTickLabelFont() != null) {
        chartPlot.setTickLabelFont(fontUtil.getAwtFont(jrPlot.getTickLabelFont(), getLocale()));
    }

    // Set the spacing between ticks.  I hate the name "tickSize" since to me it
    // implies I am changing the size of the tick, not the spacing between them.
    double tickInterval = jrPlot.getTickIntervalDouble() == null ? 10.0 : jrPlot.getTickIntervalDouble();
    chartPlot.setTickSize(tickInterval);

    // Set all the colors we support
    Color color = jrPlot.getMeterBackgroundColor();
    if (color != null) {
        chartPlot.setDialBackgroundPaint(color);
    }

    color = jrPlot.getNeedleColor();
    if (color != null) {
        chartPlot.setNeedlePaint(color);
    }

    // localizing the default format, can be overridden by display.getMask()
    chartPlot.setTickLabelFormat(NumberFormat.getInstance(getLocale()));

    // Set how the value is displayed.
    JRValueDisplay display = jrPlot.getValueDisplay();
    if (display != null) {
        if (display.getColor() != null) {
            chartPlot.setValuePaint(display.getColor());
        }

        if (display.getMask() != null) {
            chartPlot.setTickLabelFormat(
                    new DecimalFormat(display.getMask(), DecimalFormatSymbols.getInstance(getLocale())));
        }

        if (display.getFont() != null) {
            chartPlot.setValueFont(fontUtil.getAwtFont(display.getFont(), getLocale()));
        }

    }

    color = jrPlot.getTickColor();
    if (color != null) {
        chartPlot.setTickPaint(color);
    }

    // Now define all of the intervals, setting their range and color
    List<JRMeterInterval> intervals = jrPlot.getIntervals();
    if (intervals != null) {
        Iterator<JRMeterInterval> iter = intervals.iterator();
        while (iter.hasNext()) {
            JRMeterInterval interval = iter.next();
            chartPlot.addInterval(convertInterval(interval));
        }
    }

    // Actually create the chart around the plot
    JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null,
            chartPlot, isShowLegend());

    // Set all the generic options
    configureChart(jfreeChart);

    return jfreeChart;
}