0

Make the edges on the series is simple, but on how to make the graph shown in Figure 2 I did not find any example. The code shown to follow generates the graph shown in Figure 1. I would like to find a way to get the one shown in Figure 2.

Some of you has ever happened to this need? Is there an easy way to get the result?

Thank you very much.

    private static CategoryDataset createDataset()
{
    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    defaultcategorydataset.addValue(10D, "Series 1", "Jan");
    defaultcategorydataset.addValue(12D, "Series 1", "Feb");
    defaultcategorydataset.addValue(13D, "Series 1", "Mar");
    defaultcategorydataset.addValue(4D, "Series 2", "Jan");
    defaultcategorydataset.addValue(3D, "Series 2", "Feb");
    defaultcategorydataset.addValue(2D, "Series 2", "Mar");
    defaultcategorydataset.addValue(2D, "Series 3", "Jan");
    defaultcategorydataset.addValue(3D, "Series 3", "Feb");
    defaultcategorydataset.addValue(2D, "Series 3", "Mar");
    defaultcategorydataset.addValue(2D, "Series 4", "Jan");
    defaultcategorydataset.addValue(3D, "Series 4", "Feb");
    defaultcategorydataset.addValue(4D, "Series 4", "Mar");
    return defaultcategorydataset;
}

private static JFreeChart createChart(CategoryDataset categorydataset)
{
    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 3", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot();
    ExtendedStackedBarRenderer extendedstackedbarrenderer = new ExtendedStackedBarRenderer();
    extendedstackedbarrenderer.setBaseItemLabelsVisible(true);
    extendedstackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    extendedstackedbarrenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    categoryplot.setRenderer(extendedstackedbarrenderer);
    NumberAxis numberaxis = (NumberAxis)categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setLowerMargin(0.14999999999999999D);
    numberaxis.setUpperMargin(0.14999999999999999D);
    numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

Figure 1 - Stacked Bar Chart Demo dorderless.

Figure 2 - Stacked Bar Chart Demo with border

Antonio Musarra
  • 370
  • 1
  • 14

1 Answers1

1

You can use setDrawBarOutline(true), as shown here. Use the outline stoke and paint to vary the thickness and color.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Already done so. But I would like the edges of a different color for each bar and set specific, just as shown in the example. Thx for your response. – Antonio Musarra Sep 11 '12 at 08:30
  • Please edit your question to include this fact; also add an [sscce](http://sscce.org/) that shows your current approach, including sample data, chosen renderer and paint/stroke override. – trashgod Sep 11 '12 at 09:10
  • I edited the question. I hope it is clear that the result indendo reach. Thx. – Antonio Musarra Sep 11 '12 at 11:11
  • Your example is incomplete; please read the [article](http://sscce.org/) cited in my first comment. In particular, `ExtendedStackedBarRenderer` is not shown, and it's not clear how you're overriding `getItemOutlinePaint()` and `getItemOutlineStroke()`, as suggested in the API. – trashgod Sep 11 '12 at 12:27
  • Hi Trashgod,The example is from the demo package JFreeChart. It does not seem appropriate to include also the class ExtendedStackedBarRenderer, which extends the class StackedBarRenderer. It seems to me that my goal is clear, you have understood what is my goal? If you could also enter the class code ExtendedStackedBarRenderer but I think it would only create confusion. Do you agree? – Antonio Musarra Sep 11 '12 at 13:15
  • Oh, you mean `demo.ExtendedStackedBarRenderer`? Yes, it would be inappropriate to post that; you can cite it by reference. Also consider cross-posting to the [forum](http://www.jfree.org/forum/viewforum.php?f=3), where readers are more likely to have the current version. The critical thing is how you override `getItemOutlinePaint()` and `getItemOutlineStroke()`. – trashgod Sep 11 '12 at 13:37