Java Code Examples for org.jfree.chart.renderer.category.BoxAndWhiskerRenderer#setFillBox()

The following examples show how to use org.jfree.chart.renderer.category.BoxAndWhiskerRenderer#setFillBox() . 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: BoxAndWhiskerRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test that the equals() method distinguishes all fields.
 */
public void testEquals() {
    BoxAndWhiskerRenderer r1 = new BoxAndWhiskerRenderer();
    BoxAndWhiskerRenderer r2 = new BoxAndWhiskerRenderer();
    assertEquals(r1, r2);
    
    r1.setArtifactPaint(new GradientPaint(1.0f, 2.0f, Color.yellow, 
            3.0f, 4.0f, Color.blue));
    assertFalse(r1.equals(r2));
    r2.setArtifactPaint(new GradientPaint(1.0f, 2.0f, Color.yellow, 
            3.0f, 4.0f, Color.blue));
    assertEquals(r1, r2);
    
    r1.setFillBox(!r1.getFillBox());
    assertFalse(r1.equals(r2));
    r2.setFillBox(!r2.getFillBox());
    assertEquals(r1, r2);
    
    r1.setItemMargin(0.11);
    assertFalse(r1.equals(r2));
    r2.setItemMargin(0.11);
    assertEquals(r1, r2);
    
}
 
Example 2
Source File: SimpleBox.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
public JFreeChart createChart(DatasetMap datasetMap) {

		BoxAndWhiskerCategoryDataset dataset=(BoxAndWhiskerCategoryDataset)datasetMap.getDatasets().get("1"); 

		JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(
				name, categoryLabel, valueLabel, dataset, 
				false);

		TextTitle title =setStyleTitle(name, styleTitle);
		chart.setTitle(title);
		if(subName!= null && !subName.equals("")){
			TextTitle subTitle =setStyleTitle(subName, styleSubTitle);
			chart.addSubtitle(subTitle);
		}
		
		CategoryPlot plot = (CategoryPlot) chart.getPlot();
		BoxAndWhiskerRenderer renderer=(BoxAndWhiskerRenderer)plot.getRenderer();
		chart.setBackgroundPaint(Color.white);

		plot.setBackgroundPaint(new Color(Integer.decode("#c0c0c0").intValue()));
		plot.setDomainGridlinePaint(Color.WHITE);
		plot.setDomainGridlinesVisible(true);
		plot.setRangeGridlinePaint(Color.white);
		renderer.setFillBox(true);
		renderer.setArtifactPaint(Color.BLACK);
		renderer.setSeriesPaint(0,new Color(Integer.decode("#0000FF").intValue()));

		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
		rangeAxis.setRange(min, max);

		return chart;
	}
 
Example 3
Source File: BoxAndWhiskerRendererTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that the equals() method distinguishes all fields.
 */
public void testEquals() {
    BoxAndWhiskerRenderer r1 = new BoxAndWhiskerRenderer();
    BoxAndWhiskerRenderer r2 = new BoxAndWhiskerRenderer();
    assertEquals(r1, r2);

    r1.setArtifactPaint(new GradientPaint(1.0f, 2.0f, Color.yellow,
            3.0f, 4.0f, Color.blue));
    assertFalse(r1.equals(r2));
    r2.setArtifactPaint(new GradientPaint(1.0f, 2.0f, Color.yellow,
            3.0f, 4.0f, Color.blue));
    assertEquals(r1, r2);

    r1.setFillBox(!r1.getFillBox());
    assertFalse(r1.equals(r2));
    r2.setFillBox(!r2.getFillBox());
    assertEquals(r1, r2);

    r1.setItemMargin(0.11);
    assertFalse(r1.equals(r2));
    r2.setItemMargin(0.11);
    assertEquals(r1, r2);

    r1.setMaximumBarWidth(0.99);
    assertFalse(r1.equals(r2));
    r2.setMaximumBarWidth(0.99);
    assertTrue(r1.equals(r2));

    // the default for meanVisible is false in 1.2.x
    r1.setMeanVisible(true);
    assertFalse(r1.equals(r2));
    r2.setMeanVisible(true);
    assertTrue(r1.equals(r2));

    r1.setMedianVisible(false);
    assertFalse(r1.equals(r2));
    r2.setMedianVisible(false);
    assertTrue(r1.equals(r2));
}
 
Example 4
Source File: CategoryBoxplot.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public JFreeChart getChart() {
    if (chart == null) {
        createDataset();
        chart = ChartFactory.createBarChart(getTitle(),
                // chart title
                "Category",
                // domain axis label
                "Value",
                // range axis label
                dataset,
                // data
                PlotOrientation.VERTICAL,
                // orientation
                false,
                // include legend
                true,
                // tooltips?
                false
        // URLs?
        );
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryAxis rangeAxis = plot.getDomainAxis();
        rangeAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
        renderer.setFillBox(true);
        renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
        // TODO reactivate if newer jfree is used
        // renderer.setMeanVisible(isMeanVisible);
        plot.setRenderer(renderer);
    }

    return chart;
}
 
Example 5
Source File: ResultsProccessor.java    From KEEL with GNU General Public License v3.0 4 votes vote down vote up
public void writeToFile(String outName) throws FileNotFoundException, UnsupportedEncodingException, IOException
{
    //calcMeans();
    
    // Create JFreeChart Dataset
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset( );
    
    
    HashMap<String, ArrayList<Double> > measuresFirst = algorithmMeasures.entrySet().iterator().next().getValue();
    for (Map.Entry<String, ArrayList<Double> > measure : measuresFirst.entrySet())
    {
        String measureName = measure.getKey();
        //Double measureValue = measure.getValue();
        dataset.clear();
        
        for (Map.Entry<String, HashMap<String, ArrayList<Double> >> entry : algorithmMeasures.entrySet())
        {
            String alg = entry.getKey();
            ArrayList<Double> measureValues = entry.getValue().get(measureName);
            
            // Parse algorithm name to show it correctly
            String aName = alg.substring(0, alg.length()-1);
            int startAlgName = aName.lastIndexOf("/");
            aName = aName.substring(startAlgName + 1);
            
            dataset.add(measureValues, aName, measureName);
        }
        
        // Tutorial: http://www.java2s.com/Code/Java/Chart/JFreeChartBoxAndWhiskerDemo.htm
        final CategoryAxis xAxis = new CategoryAxis("Algorithm");
        final NumberAxis yAxis = new NumberAxis("Value");
        yAxis.setAutoRangeIncludesZero(false);
        final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
        
        // Black and White
        int numItems = algorithmMeasures.size();
        for(int i=0;i<numItems;i++)
        {
            Color color = Color.DARK_GRAY;
            if(i%2 == 1)
            {
                color = Color.LIGHT_GRAY;
            }
            renderer.setSeriesPaint(i, color);
            renderer.setSeriesOutlinePaint(i, Color.BLACK);
        }
        
        renderer.setMeanVisible(false);
        renderer.setFillBox(false);
        renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
        final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

        Font font = new Font("SansSerif", Font.BOLD, 10);
        //ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
        JFreeChart jchart = new JFreeChart("Assotiation Rules Measures - BoxPlot", font, plot, true);
        //StandardChartTheme.createLegacyTheme().apply(jchart);
     
        int width = 640 * 2; /* Width of the image */
        int height = 480 * 2; /* Height of the image */ 

        // JPEG
        File chart = new File( outName + "_" + measureName + "_boxplot.jpg" );
        ChartUtilities.saveChartAsJPEG( chart , jchart , width , height );

        // SVG
        SVGGraphics2D g2 = new SVGGraphics2D(width, height);
        Rectangle r = new Rectangle(0, 0, width, height);
        jchart.draw(g2, r);
        File BarChartSVG = new File( outName + "_" + measureName + "_boxplot.svg" );
        SVGUtils.writeToSVG(BarChartSVG, g2.getSVGElement());
    }
    
}