All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.extension.envsupport.evaluation.HistogramDataConsumer Maven / Gradle / Ivy

Go to download

The Jadex kernel extension envsupport allows for using 2D spaces in concert with components.

There is a newer version: 3.0.117
Show newest version
package jadex.extension.envsupport.evaluation;

import java.awt.Image;

import javax.imageio.ImageIO;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.statistics.SimpleHistogramBin;
import org.jfree.data.statistics.SimpleHistogramDataset;

import jadex.commons.ResourceInfo;

/**
 *  Create a category chart consumer, x must be a comparable and y must be double value.
 */
public class HistogramDataConsumer extends AbstractChartDataConsumer
{	
	//-------- constructors --------

	/**
	 *  Create a new chart consumer.
	 */
	public HistogramDataConsumer()
	{
	}
		
	//-------- methods --------

	/**
	 *  Create a chart with the underlying dataset.
	 *  @return The chart.
	 */
	protected JFreeChart createChart()
	{
		String title = (String)getProperty("title");
		String labelx = (String)getProperty("labelx");
		String labely = (String)getProperty("labely");
		boolean legend = getProperty("legend")==null? true: ((Boolean)getProperty("legend")).booleanValue();
		boolean tooltips = getProperty("tooltips")==null? true: ((Boolean)getProperty("tooltips")).booleanValue();
		boolean urls = getProperty("urls")==null? false: ((Boolean)getProperty("urls")).booleanValue();
		boolean autorepaint = getProperty("autorepaint")==null? false: ((Boolean)getProperty("autorepaint")).booleanValue();

		String seriesname = (String)getProperty("seriesname");

		SimpleHistogramDataset dataset = new SimpleHistogramDataset(seriesname);

		Number low = (Number)getProperty("lowvalue");
		Number high = (Number)getProperty("highvalue");
		Number bincnt = (Number)getProperty("bincount");
		if(low!=null && high!=null)
		{
			int cnt = bincnt!=null? bincnt.intValue(): 1;
			double lv = low.doubleValue();
			double hv = high.doubleValue();
			double bsize = (hv-lv)/cnt;
			for(int i=0; i=low.doubleValue() && val<=high.doubleValue())
		{
			SimpleHistogramDataset dataset = (SimpleHistogramDataset)((XYPlot)getChart().getPlot()).getDataset();
			dataset.addObservation(val);
		}
//		else
//		{
//			// print out of range warning?
//		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy