如何制作Stacked Bar类型图形的边缘?

时间:2012-09-10 20:45:41

标签: charts jfreechart stacked-area-chart

使系列的边缘很简单,但是如何使图2所示的图形我没有找到任何例子。接下来的代码生成如图1所示的图。我想找到一种方法来获得图2所示的图。

有些人曾经遇到过这种需求吗?有没有简单的方法来获得结果?

非常感谢。

    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

1 个答案:

答案 0 :(得分:1)

您可以使用setDrawBarOutline(true),如图here所示。使用轮廓描边和绘画来改变厚度和颜色。