jadex.extension.envsupport.evaluation.HistogramDataConsumer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-kernel-extension-envsupport Show documentation
Show all versions of jadex-kernel-extension-envsupport Show documentation
The Jadex kernel extension envsupport allows for using 2D spaces in concert with components.
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?
// }
}
}