org.jfree.chart.plot.MeterInterval Java Examples

The following examples show how to use org.jfree.chart.plot.MeterInterval. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JRFillChart.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Converts a JasperReports meter interval to one that JFreeChart understands.
 *
 * @param interval the JasperReports definition of an interval
 * @param evaluation current evaluation time
 * @return the JFreeChart version of the same interval
 * @throws JRException thrown when the interval contains an invalid range
 */
protected MeterInterval convertInterval(JRMeterInterval interval, byte evaluation) throws JRException
{
	String label = interval.getLabel();
	if (label == null)
	{
		label = "";
	}

	Range range = convertRange(interval.getDataRange(), evaluation);

	Color color = interval.getBackgroundColor();
	float[] components = color.getRGBColorComponents(null);
	float alpha = (float)(interval.getAlphaDouble() == null ? JRMeterInterval.DEFAULT_TRANSPARENCY : interval.getAlphaDouble());

	Color alphaColor = new Color(components[0], components[1], components[2], alpha);

	return new MeterInterval(label, range, alphaColor, null, alphaColor);
}
 
Example #2
Source File: DefaultChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Converts a JasperReports meter interval to one that JFreeChart understands.
 *
 * @param interval the JasperReports definition of an interval
 * @return the JFreeChart version of the same interval
 * @throws JRException thrown when the interval contains an invalid range
 */
protected MeterInterval convertInterval(JRMeterInterval interval) throws JRException
{
	String label = interval.getLabel();
	if (label == null)
	{
		label = "";
	}

	Range range = convertRange(interval.getDataRange());

	Color color = interval.getBackgroundColor() == null ? getChart().getBackcolor() : interval.getBackgroundColor();//FIXMETHEME check this null protection
	float[] components = color.getRGBColorComponents(null);

	float alpha = (float)(interval.getAlphaDouble() == null ? JRMeterInterval.DEFAULT_TRANSPARENCY : interval.getAlphaDouble());
	Color alphaColor = new Color(components[0], components[1], components[2], alpha);

	return new MeterInterval(label, range, alphaColor, null, alphaColor);
}
 
Example #3
Source File: GenericChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Converts a JasperReports meter interval to one that JFreeChart understands.
 *
 * @param interval the JasperReports definition of an interval
 * @return the JFreeChart version of the same interval
 * @throws JRException thrown when the interval contains an invalid range
 */
protected MeterInterval convertInterval(JRMeterInterval interval) throws JRException
{
	String label = interval.getLabel();
	if (label == null)
		label = "";

	Range range = convertRange(interval.getDataRange());

	Color color = interval.getBackgroundColor() != null ? interval.getBackgroundColor() : (Color)ChartThemesConstants.TRANSPARENT_PAINT;
	float[] components = color.getRGBColorComponents(null);

	float alpha = (float)(interval.getAlphaDouble() == null ? JRMeterInterval.DEFAULT_TRANSPARENCY : interval.getAlphaDouble());
	Color alphaColor = new Color(components[0], components[1], components[2], alpha);

	return new MeterInterval(label, range, alphaColor, null, alphaColor);
}
 
Example #4
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Converts a JasperReports meter interval to one that JFreeChart understands.
 *
 * @param interval the JasperReports definition of an interval
 * @return the JFreeChart version of the same interval
 * @throws JRException thrown when the interval contains an invalid range
 */
protected MeterInterval convertInterval(JRMeterInterval interval) throws JRException
{
	String label = interval.getLabel();
	if (label == null)
		label = "";

	Range range = convertRange(interval.getDataRange());

	Color color = interval.getBackgroundColor() != null ? interval.getBackgroundColor() : (Color)ChartThemesConstants.TRANSPARENT_PAINT;
	float[] components = color.getRGBColorComponents(null);

	float alpha = (float)(interval.getAlphaDouble() == null ? JRMeterInterval.DEFAULT_TRANSPARENCY : interval.getAlphaDouble());
	Color alphaColor = new Color(components[0], components[1], components[2], alpha);

	return new MeterInterval(label, range, alphaColor, null, alphaColor);
}
 
Example #5
Source File: MeterChartTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the chart with a single range.  At one point, this caused a null
 * pointer exception (fixed now).
 */
public void testDrawWithNullInfo() {
    boolean success = false;
    MeterPlot plot = new MeterPlot(new DefaultValueDataset(60.0));
    plot.addInterval(new MeterInterval("Normal", new Range(0.0, 80.0)));
    JFreeChart chart = new JFreeChart(plot);
    try {
        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();
        success = true;
    }
    catch (Exception e) {
        success = false;
    }
    assertTrue(success);
}
 
Example #6
Source File: MeterChartTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the chart with a single range.  At one point, this caused a null
 * pointer exception (fixed now).
 */
public void testDrawWithNullInfo() {
    boolean success = false;
    MeterPlot plot = new MeterPlot(new DefaultValueDataset(60.0));
    plot.addInterval(new MeterInterval("Normal", new Range(0.0, 80.0)));
    JFreeChart chart = new JFreeChart(plot);
    try {
        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();
        success = true;
    }
    catch (Exception e) {
        success = false;   
    }
    assertTrue(success);
}
 
Example #7
Source File: MeterChartTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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
}
 
Example #8
Source File: MeterChartTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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
}
 
Example #9
Source File: MeterChartTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * 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
}
 
Example #10
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private JFreeChart getGaugeChart( BaseChart chart, ValueDataset dataSet )
{
    MeterPlot meterPlot = new MeterPlot( dataSet );

    meterPlot.setUnits( "" );
    meterPlot.setRange( new Range( 0.0d, 100d ) );

    for ( int i = 0; i < 10; i++ )
    {
        double start = i * 10d;
        double end = start + 10d;
        String label = String.valueOf( start );

        meterPlot.addInterval( new MeterInterval( label, new Range( start, end ), COLOR_LIGHT_GRAY, null, COLOR_LIGHT_GRAY ) );
    }

    meterPlot.setMeterAngle( 180 );
    meterPlot.setDialBackgroundPaint( COLOR_LIGHT_GRAY );
    meterPlot.setDialShape( DialShape.CHORD );
    meterPlot.setNeedlePaint( COLORS[0] );
    meterPlot.setTickLabelsVisible( true );
    meterPlot.setTickLabelFont( LABEL_FONT );
    meterPlot.setTickLabelPaint( Color.BLACK );
    meterPlot.setTickPaint( COLOR_LIGHTER_GRAY );
    meterPlot.setValueFont( TITLE_FONT );
    meterPlot.setValuePaint( Color.BLACK );

    JFreeChart meterChart = new JFreeChart( chart.getName(), meterPlot );
    setBasicConfig( meterChart, chart );
    meterChart.removeLegend();

    return meterChart;
}
 
Example #11
Source File: ChartImageGenerator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private JFreeChart getGaugeChart( final Visualization visualization, ValueDataset dataSet )
{
    MeterPlot meterPlot = new MeterPlot( dataSet );

    meterPlot.setUnits( "" );
    meterPlot.setRange( new Range( 0.0d, 100d ) );

    for ( int i = 0; i < 10; i++ )
    {
        double start = i * 10d;
        double end = start + 10d;
        String label = String.valueOf( start );

        meterPlot.addInterval( new MeterInterval( label, new Range( start, end ), COLOR_LIGHT_GRAY, null, COLOR_LIGHT_GRAY ) );
    }

    meterPlot.setMeterAngle( 180 );
    meterPlot.setDialBackgroundPaint( COLOR_LIGHT_GRAY );
    meterPlot.setDialShape( DialShape.CHORD );
    meterPlot.setNeedlePaint( COLORS[0] );
    meterPlot.setTickLabelsVisible( true );
    meterPlot.setTickLabelFont( LABEL_FONT );
    meterPlot.setTickLabelPaint( Color.BLACK );
    meterPlot.setTickPaint( COLOR_LIGHTER_GRAY );
    meterPlot.setValueFont( TITLE_FONT );
    meterPlot.setValuePaint( Color.BLACK );

    JFreeChart meterChart = new JFreeChart( visualization.getName(), meterPlot );
    setBasicConfig( meterChart, visualization );
    meterChart.removeLegend();

    return meterChart;
}
 
Example #12
Source File: MeterChartTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
}
 
Example #13
Source File: MeterChartTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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
}
 
Example #14
Source File: Meter.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Creates the chart .
 * 
 * @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;
}
 
Example #15
Source File: MeterIntervalTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This class is immutable so cloning isn't required.
 */
public void testCloning() {
    MeterInterval m1 = new MeterInterval("X", new Range(1.0, 2.0));
    assertFalse(m1 instanceof Cloneable);
}
 
Example #16
Source File: MeterIntervalTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This class is immutable so cloning isn't required.
 */
public void testCloning() {
    MeterInterval m1 = new MeterInterval("X", new Range(1.0, 2.0));
    assertFalse(m1 instanceof Cloneable);
}