0

我用 GroupedStackedBarRenderer 创建了一个 StackedBarChart 来解决问题https://stackoverflow.com/questions/18349933/how-to-create-a-stacked-bar-chart-with-multiple-rows-inside-one-row

我可以有任意数量的列键和行键,组。下面,我附上了我的程序的一些截图。问题是我无法获得标准视图(条之间的空间,如果输入较少,条太大,条太细,没有显示其中写入的文本)。在实现这个用例之前,我会使用 setMaxbarWidth 但现在它不起作用。

这是我用来排列条形的代码。

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    chart.setBackgroundPaint(new Color(238, 238, 238));
    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    //Some insertion here
    KeyToGroupMap map = new KeyToGroupMap("A");
    renderer.setSeriesToGroupMap(map);
    renderer.setItemMargin(0.0);
    /** causes to show bar width half of available space. */
    renderer.setMaximumBarWidth(.5);
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);
    plot.setRenderer(renderer);
    /** get number axis in plot.Number related axis .x axis in this graph. */
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    renderer.setBaseToolTipGenerator(new CustomToolTipGenerator(getGraphData()));
    renderer.setBarPainter(new StandardBarPainter());
    /** do not show thick in number axis label */
    rangeAxis.setTickLabelsVisible(false);
    rangeAxis.setTickMarksVisible(false);
    rangeAxis.setAxisLineVisible(false);
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setCategoryMargin(0.05);
    // categoryAxis.setLowerMargin(0.05);
    // categoryAxis.setUpperMargin(0.05);
    categoryAxis.setTickLabelsVisible(false);
    categoryAxis.setTickMarksVisible(false);
    categoryAxis.setAxisLineVisible(false);

我知道 CategoryDomain 有一些方法(setlowerMargin、setCategoryMargin、setUpperMargin)。我对这些方法进行了一些尝试。但没有成功。我不明白为什么酒吧之间的空间这么宽。请帮帮我

带 3 列键和 6 组的图片

在此处输入图像描述 带有 2 列键和 4 组的图片

在此处输入图像描述

带有一列键和 2 组的图片

在此处输入图像描述

4

2 回答 2

1

您可能想要探索更多的负范围setItemMargin(),如下所示。您可以调整滑块以找到数据集的最佳值。在下图中,初始设置为SLIDER_INITIAL_VALUE * INCREMENT,即–4.2

图片

于 2013-08-22T15:19:13.347 回答
0

我明白代码有什么问题。我有一个错误的 KeyToGroup 映射。我没有在同一个 groupKey 中分组任何行键。所以我没有得到我想要的视图。

于 2013-08-26T14:57:03.863 回答