Search code examples
jfreechart

jFreeChart: Possible to combine StatisticalBarRenderer and LayeredBarRenderer?


I want to create a chart that consists of couples of two bars. one of them a regular bar, the second one is layered and has a deviation.

This is a snippet of my code:

private static JFreeChart createStatisticalBarChart(DefaultStatisticalCategoryDataset dataset, String chartTitle, String domainAxisLabel, String rangeAxisLabel, List<String> sunndayMap) {

    CategoryAxis xAxis = new CategoryAxis(domainAxisLabel);
    ValueAxis yAxis = new NumberAxis(rangeAxisLabel);
    CategoryItemRenderer renderer = new StatisticalBarRenderer();

    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);


    JFreeChart chart = new JFreeChart(chartTitle,
            new Font("Arial", Font.PLAIN, 10),
            plot,
            true);

My dataset has mean+standarddeviatin records with every second record's deviation being "0", so that no range indicators will be displayed.

How can I accomplish that?


Solution

  • You can use a small negative value in setItemMargin() to achieve an overlap, for example

    renderer.setItemMargin(-0.10f);
    

    It appears that standard deviation lines are not drawn if the getStdDevValue() method returns null. You might try that value instead of "0".