1

CombinedRangeCategoryPlotを介して結合される複数の積み上げ棒グラフ(サブプロット)を作成しています。

サブプロットのデータセットには同じ数のアイテムがなく、JFreeChartが各サブプロットに同じスペースを割り当てることを決定したため、バーの幅が異なります。

それらの幅を揃える方法はありますか(サブプロットの幅が異なることを意味する場合でも)?

私がこれまでに持っている結果とコードについては、以下を参照してください。

どうもありがとう、トーマス

ここに画像の説明を入力してください

//Builds commong range axis
NumberAxis rangeAxis = new NumberAxis("%");
rangeAxis.setRange(0, 1.0);
rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());

//Builds common data set
CombinedRangeCategoryPlot combinedPlots = new CombinedRangeCategoryPlot(rangeAxis);
for (int groupIndex=0; groupIndex<LeakGroups.values().length; ++groupIndex){
    //Builds category axis
    CategoryAxis categoryAxis = new CategoryAxis(GuiConstants.LEAK_GROUPS_LABELS[groupIndex]);
    //Sets margins between bars
    categoryAxis.setCategoryMargin(0.5f);

    //Builds bar renderer
    StackedBarRenderer barRenderer = new StackedBarRenderer();
    barRenderer.setRenderAsPercentages(true);


    //Builds dot/level renderer
    LineAndShapeRenderer dotRenderer = new LineAndShapeRenderer();
    //dotRenderer.setSeriesLinesVisible(0, false);
    //dotRenderer.setSeriesShapesVisible(0, false);
    //dotRenderer.setSeriesLinesVisible(1, false);
    //Defines level shape height (depends on chart size): nominal values are for a height of 1000px 
    int shapeHeightPx = (int) Math.round(20 * (this.getHeight() / 1000.0));
    dotRenderer.setSeriesShape(1, new Rectangle(-1, -shapeHeightPx/2, 2, shapeHeightPx));

    //Builds plot
    CategoryPlot plot = new CategoryPlot();
    plot.setDomainAxis(categoryAxis);
    plot.setDataset(0, data[groupIndex].bars);
    plot.setRenderer(0, barRenderer);
    plot.setDataset(1, data[groupIndex].dots);
    plot.setRenderer(1, dotRenderer);

    //Adds to combined
    combinedPlots.add(plot);
}
combinedPlots.setOrientation(PlotOrientation.HORIZONTAL);
//Puts range axis at the bottom
combinedPlots.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
//Changes plot render sequence so that bars are in the background and shapes in front
combinedPlots.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
//Shows gridlines for categories and not for values
combinedPlots.setDomainGridlinesVisible(true);
combinedPlots.setRangeGridlinesVisible(false);

//Creates chart
JFreeChart chart = new JFreeChart("Leaks", combinedPlots);

//Sets a margin right to allow space for last catergory label ("100%")
chart.setPadding(new RectangleInsets(0, 0, 0, 20));

return chart;

4

2 に答える 2

1

数時間の検索の後、解決策が見つかりました: use plot.setWeight().

何らかの理由で、プロットを に追加すると重みが値 1 にリセットされるため、CombinedRangeCategoryPlot後で設定する必要があります。

お役に立てれば。

于 2013-03-02T19:47:15.170 に答える
1

何らかの理由で、1プロットを追加すると重みが値にリセットされます。

説明として、

于 2013-03-03T03:23:36.380 に答える