制作系列的边很简单,但是关于如何制作图 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;
}