Search in sources :

Example 6 with DefaultValueDataset

use of org.jfree.data.general.DefaultValueDataset in project SIMVA-SoS by SESoS.

the class MeterChartTest method testDrawWithNullInfo.

/**
 * Draws the chart with a single range.  At one point, this caused a null
 * pointer exception (fixed now).
 */
@Test
public void testDrawWithNullInfo() {
    MeterPlot plot = new MeterPlot(new DefaultValueDataset(60.0));
    plot.addInterval(new MeterInterval("Normal", new Range(0.0, 80.0)));
    JFreeChart chart = new JFreeChart(plot);
    BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
    g2.dispose();
// FIXME we should really assert a value here
}
Also used : DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) MeterInterval(org.jfree.chart.plot.MeterInterval) Rectangle2D(java.awt.geom.Rectangle2D) Range(org.jfree.data.Range) MeterPlot(org.jfree.chart.plot.MeterPlot) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Test(org.junit.Test)

Example 7 with DefaultValueDataset

use of org.jfree.data.general.DefaultValueDataset in project adempiere by adempiere.

the class PerformanceIndicator method createChart.

//	getGoal
private JFreeChart createChart() {
    JFreeChart chart = null;
    //	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());
    //
    //setBackground(m_goal.getColor());
    setForeground(GraphUtil.getForeground(getBackground()));
    //	Performance Line
    int percent = m_goal.getPercent();
    if (//	draw 100% line
    percent > 100)
        m_line = s_width100;
    else
        //	draw Performance Line
        m_line = s_width100 * m_goal.getGoalPerformanceDouble();
    String title = m_text;
    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 //label
            MeterInterval(//label
            "Normal", //range
            new Range(rangeLo, rangeHi), colorSchema.getColor(rangeHi), new BasicStroke(7.0f), //Color.lightGray
            new Color(-13091716)));
            rangeLo = rangeHi;
        }
    }
    plot.setRange(new Range(0, rangeLo));
    //Color.GRAY);
    plot.setDialBackgroundPaint(new Color(-13091716));
    plot.setUnits(m_goal.getName());
    //CIRCLE);        
    plot.setDialShape(DialShape.CHORD);
    //plot.setDialBackgroundPaint(new GradientPaint(0, 0, m_goal.getColor(), 0, 1000, Color.black));
    plot.setNeedlePaint(Color.white);
    plot.setTickSize(2000);
    plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 12));
    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, 15), plot, false);
    return chart;
}
Also used : DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) Range(org.jfree.data.Range) JFreeChart(org.jfree.chart.JFreeChart) MeterPlot(org.jfree.chart.plot.MeterPlot) Font(java.awt.Font) MColorSchema(org.compiere.model.MColorSchema) RectangleInsets(org.jfree.ui.RectangleInsets)

Example 8 with DefaultValueDataset

use of org.jfree.data.general.DefaultValueDataset in project adempiere by adempiere.

the class WPerformanceIndicator method createChart.

//	getGoal
private JFreeChart createChart() {
    JFreeChart chart = null;
    //	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 //label
            MeterInterval(//label
            "Normal", //range
            new Range(rangeLo, rangeHi), colorSchema.getColor(rangeHi), new BasicStroke(7.0f), null));
            rangeLo = rangeHi;
        }
    }
    plot.setRange(new Range(0, rangeLo));
    // new Color(-13091716)
    plot.setDialBackgroundPaint(null);
    plot.setUnits("");
    //CIRCLE);
    plot.setDialShape(DialShape.CHORD);
    plot.setDialOutlinePaint(Color.GRAY);
    plot.setNeedlePaint(Color.BLACK);
    plot.setTickSize(2000);
    plot.setTickPaint(Color.DARK_GRAY);
    plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 8));
    plot.setTickLabelPaint(Color.DARK_GRAY);
    plot.setValueFont(new Font("SansSerif", Font.BOLD, 8));
    plot.setValuePaint(Color.BLUE);
    plot.setNoDataMessageFont(new Font("SansSerif", Font.BOLD, 8));
    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;
}
Also used : DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) BasicStroke(java.awt.BasicStroke) MColorSchema(org.compiere.model.MColorSchema) RectangleInsets(org.jfree.ui.RectangleInsets) Range(org.jfree.data.Range) JFreeChart(org.jfree.chart.JFreeChart) MeterPlot(org.jfree.chart.plot.MeterPlot) Font(java.awt.Font)

Example 9 with DefaultValueDataset

use of org.jfree.data.general.DefaultValueDataset in project bamboobsc by billchen198318.

the class CommonMeterChartAction method fillChart.

private void fillChart(String title, float value, int lowerBound, int upperBound) throws Exception {
    DefaultValueDataset dataset = new DefaultValueDataset();
    dataset.setValue(value);
    DialPlot plot = new DialPlot();
    plot.setView(0.0d, 0.0d, 1.0d, 1.0d);
    plot.setDataset(0, dataset);
    StandardDialFrame frame = new StandardDialFrame();
    plot.setDialFrame(frame);
    DialBackground dialBackground = new DialBackground();
    dialBackground.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    plot.setBackground(dialBackground);
    DialTextAnnotation textAnnotation = new DialTextAnnotation(title);
    textAnnotation.setRadius(0.555555555555555555D);
    plot.addLayer(textAnnotation);
    DialValueIndicator valueIndicator = new DialValueIndicator(0);
    plot.addLayer(valueIndicator);
    StandardDialScale scale1 = new StandardDialScale();
    scale1.setLowerBound(lowerBound);
    scale1.setUpperBound(upperBound);
    // -120
    scale1.setStartAngle(-140);
    // -300D 
    scale1.setExtent(-260D);
    scale1.setTickRadius(0.88D);
    scale1.setTickLabelOffset(0.14999999999999999D);
    scale1.setTickLabelFont(new Font("", Font.TRUETYPE_FONT, 14));
    plot.addScale(0, scale1);
    StandardDialRange standarddialrange0 = new StandardDialRange(lowerBound, (upperBound * 0.6), Color.red);
    standarddialrange0.setInnerRadius(0.52000000000000002D);
    standarddialrange0.setOuterRadius(0.55000000000000004D);
    plot.addLayer(standarddialrange0);
    StandardDialRange standarddialrange1 = new StandardDialRange((upperBound * 0.6), (upperBound * 0.8), Color.orange);
    standarddialrange1.setInnerRadius(0.52000000000000002D);
    standarddialrange1.setOuterRadius(0.55000000000000004D);
    plot.addLayer(standarddialrange1);
    StandardDialRange standarddialrange2 = new StandardDialRange((upperBound * 0.8), upperBound, Color.green);
    standarddialrange2.setInnerRadius(0.52000000000000002D);
    standarddialrange2.setOuterRadius(0.55000000000000004D);
    plot.addLayer(standarddialrange2);
    Pointer pointer = new Pointer(0);
    pointer.setFillPaint(new Color(144, 196, 246));
    plot.addPointer(pointer);
    plot.mapDatasetToScale(0, 0);
    DialCap dialcap = new DialCap();
    dialcap.setRadius(0.0700000000000001D);
    plot.setCap(dialcap);
    this.chart = new JFreeChart(plot);
    //this.chart.setBackgroundPaint(new Color(234, 244, 253));
    this.chart.setBackgroundPaint(Color.white);
}
Also used : DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) StandardDialFrame(org.jfree.chart.plot.dial.StandardDialFrame) DialBackground(org.jfree.chart.plot.dial.DialBackground) StandardGradientPaintTransformer(org.jfree.ui.StandardGradientPaintTransformer) Color(java.awt.Color) Pointer(org.jfree.chart.plot.dial.DialPointer.Pointer) DialPlot(org.jfree.chart.plot.dial.DialPlot) DialTextAnnotation(org.jfree.chart.plot.dial.DialTextAnnotation) Font(java.awt.Font) JFreeChart(org.jfree.chart.JFreeChart) StandardDialScale(org.jfree.chart.plot.dial.StandardDialScale) DialValueIndicator(org.jfree.chart.plot.dial.DialValueIndicator) StandardDialRange(org.jfree.chart.plot.dial.StandardDialRange) DialCap(org.jfree.chart.plot.dial.DialCap)

Aggregations

DefaultValueDataset (org.jfree.data.general.DefaultValueDataset)9 JFreeChart (org.jfree.chart.JFreeChart)5 Font (java.awt.Font)3 MeterPlot (org.jfree.chart.plot.MeterPlot)3 Range (org.jfree.data.Range)3 Test (org.junit.Test)3 BasicStroke (java.awt.BasicStroke)2 Color (java.awt.Color)2 MColorSchema (org.compiere.model.MColorSchema)2 CategoryAxis (org.jfree.chart.axis.CategoryAxis)2 NumberAxis (org.jfree.chart.axis.NumberAxis)2 ValueAxis (org.jfree.chart.axis.ValueAxis)2 CategoryDataset (org.jfree.data.category.CategoryDataset)2 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)2 ValueDataset (org.jfree.data.general.ValueDataset)2 RectangleInsets (org.jfree.ui.RectangleInsets)2 Graphics2D (java.awt.Graphics2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 PrintWriter (java.io.PrintWriter)1