1

I'd like to get stacked area chart with beginning chart in first point and completing in last point like here: enter image description here

But picture is out of point's range like here: enter image description here

How can I make stacked area starting exactly from the first point and completing exactly in the last point? (Different manipulations with dateAxis.setLowerMargin(-0.075D) dateAxis.setUpperMargin(-0.075D) are not helping)

    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()));
  • 1
    the question is way too general. If you'll not be able to clarify what exactly you want to get, and the code will not be provided - it might be considered to be closed. Please, edit your question in correspondence to the [best practices](http://stackoverflow.com/help/how-to-ask) – Farside Aug 04 '16 at 09:37

1 Answers1

1

You can get the effect you want by using the default margins on the chart's CategoryAxis, i.e. don't change them as the demo does.

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

image1

I need stacked area to start for the first point—exactly from C1 in your picture, not earlier, and stop on C8, not later.

You may need to adjust the values to get closer to the desired result.

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

image2

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thank you for the answer, but in this case I'll just get gap between Y-axes and start of stacked area. I need stacked area to star for the first point - exactly from C1 in your picture, not earlier, and stop on C8, not later – user6676850 Aug 04 '16 at 11:56
  • I've elaborated above. – trashgod Aug 04 '16 at 15:32
  • Unfortunately, nothing were changed after adding: categoryaxis.setLowerMargin(-0.075D); categoryaxis.setUpperMargin(-0.075D); categoryaxis.setCategoryMargin(0.0D); – user6676850 Aug 05 '16 at 11:34