目标是建立一个区间条形图,指示每个类别的可接受值范围(0 - 100% 之间)。
对于每个类别,我想指出 2 个间隔(即一个绿色的中心间隔和一个灰色的周围间隔),我认为使用 IntervalBarRenderer 是不可行的,因此我一直在使用 StackedBarRenderer(透明每个栏的最左侧和最右侧的图层)。
这是正确的方法吗?
此外,如果这是正确的方法,似乎透明的条间隔(在每个条的最左边和最右边)不显示它们的轮廓:他们有什么方法可以为透明涂料提供轮廓?
请参阅下面的主要代码和当前结果的屏幕截图。
非常感谢您的帮助或提示!
托马斯
private JFreeChart createChart(LeaksChartSeriesVO data){
JFreeChart chart = ChartFactory.createStackedBarChart(
"Leak meters", //Title
"Leaks", //Domain axis (X) label
"%", //Range axis (Y) label
data.bars,
PlotOrientation.HORIZONTAL,
true, //Legend?
true, //Tooltip?
false); //Urls?
CategoryPlot plot = (CategoryPlot) chart.getPlot();
//Sets X axis sub-legends
SubCategoryAxis subCat = new SubCategoryAxis("Leak meters");
//Adds second dataset
plot.setDataset(1, data.dots);
//Defines level renderer
LevelRenderer renderer1 = new LevelRenderer();
renderer1.setSeriesPaint(0, Color.black);
plot.setRenderer(1, renderer1);
//Sets Y axis as %
((StackedBarRenderer) plot.getRenderer()).setRenderAsPercentages(true);
//Sets colors
((StackedBarRenderer) plot.getRenderer()).setSeriesPaint(0, new Color(0, 0, 0, 0)); //Transparent for start
((StackedBarRenderer) plot.getRenderer()).setSeriesPaint(1, Color.gray); //Grey low
((StackedBarRenderer) plot.getRenderer()).setSeriesPaint(2, Color.green); //Green
((StackedBarRenderer) plot.getRenderer()).setSeriesPaint(3, Color.gray); //Grey high
((StackedBarRenderer) plot.getRenderer()).setSeriesPaint(4, new Color(0, 0, 0, 0)); //Transparent for end
((StackedBarRenderer) plot.getRenderer()).setDrawBarOutline(true);
((StackedBarRenderer) plot.getRenderer()).setBaseOutlinePaint(Color.black);
//Setup which items not to see in legend
((StackedBarRenderer) plot.getRenderer()).setSeriesVisibleInLegend(0, false);
((StackedBarRenderer) plot.getRenderer()).setSeriesVisibleInLegend(3, false);
((StackedBarRenderer) plot.getRenderer()).setSeriesVisibleInLegend(4, false);
//Sets renderer & axis
plot.setDomainAxis(subCat);
//Changes plot render sequence so that bars are in the background and shapes in front
chart.getCategoryPlot().setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
//Sets margins between bars
chart.getCategoryPlot().getDomainAxis().setCategoryMargin(0.5f);
return chart;
}