【问题标题】:JFree: Stacked area chart continue painting after last point and before firstJFree:堆叠面积图在最后一个点之后和第一个点之前继续绘制
【发布时间】:2016-08-04 07:56:01
【问题描述】:

我想得到堆叠面积图,开始图表在第一点,在最后一点完成,如下所示:

但是图片超出了这里的范围:

如何使堆叠区域从第一点开始精确到最后一点? (使用 dateAxis.setLowerMargin(-0.075D) dateAxis.setUpperMargin(-0.075D) 的不同操作没有帮助)

    JFreeChart stackedAreaChart = ChartFactory.createStackedAreaChart(name, X_AXIS_TITLE, Y_AXIS_TITLE, dataset,
            PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot plot = stackedAreaChart.getCategoryPlot();
    CategoryAxis dateAxis = plot.getDomainAxis();
    dateAxis.setLowerMargin(-0.075D);
    dateAxis.setUpperMargin(-0.075D);
    dateAxis.setCategoryMargin(0.0D);
    StackArea renderer = new StackArea();

    dateAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    ...

    plot.setRenderer(renderer);
    renderer.setBaseItemLabelGenerator(new LabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    ...
    plot.setRenderer(renderer);
    plot.setAxisOffset(new RectangleInsets(5.0, 1.0, 5.0, 1.0));        

    ValueAxis rangeAxis = plot.getRangeAxis();
    NumberAxis axis2 = new NumberAxis(Y_AXIS_TITLE);    
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelFont(rangeAxis.getLabelFont());
    axis2.setTickLabelFont(rangeAxis.getTickLabelFont());
    ...
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT);
    plot.mapDatasetToRangeAxes(0, Arrays.asList(0, 1));

    setAxisColor(rangeAxis, axisColor);
         rangeAxis.setTickLabelPaint(ColorUtils.VaadinAWTColor(params.getColorParams().getFontSlideColor()));
    rangeAxis.setLabelPaint(ColorUtils.VaadinAWTColor(params.getColorParams().getFontSlideColor()));

【问题讨论】:

  • 这个问题太笼统了。如果您无法明确您想要获得什么,并且不会提供代码 - 它可能会被视为已关闭。请编辑您的问题,发送至best practices

标签: jfreechart stacked-area-chart


【解决方案1】:

您可以通过使用图表CategoryAxis 上的默认边距来获得您想要的效果,即不要像演示那样更改它们。

CategoryAxis categoryaxis = categoryplot.getDomainAxis();
//categoryaxis.setLowerMargin(0.0D);
//categoryaxis.setUpperMargin(0.0D);
//categoryaxis.setCategoryMargin(0.0D);

我需要堆叠区域从第一个点开始 — 正好从您图片中的C1 开始,而不是更早,并在C8 停止,而不是更晚。

您可能需要调整这些值以更接近所需的结果。

categoryaxis.setLowerMargin(-0.075D);
categoryaxis.setUpperMargin(-0.075D);
categoryaxis.setCategoryMargin(0.0D);

【讨论】:

  • 谢谢你的回答,但在这种情况下,我只会得到 Y 轴和堆叠区域开始之间的间隙。我需要堆叠区域为第一点加注星标 - 恰好从您图片中的 C1 开始,而不是更早,并在 C8 上停止,而不是稍后
  • 我已经在上面详细说明了。
  • 不幸的是,添加后没有任何改变:categoryaxis.setLowerMargin(-0.075D); categoryaxis.setUpperMargin(-0.075D); categoryaxis.setCategoryMargin(0.0D);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-08
相关资源
最近更新 更多