Search code examples
javagraphchartsjfreechart

JFreechart, Line Chart with filled Areas


I am trying to create chart like below:

Sample Chart - Requirement

While I've almost achieved everything by simply creating a line chart and customizing shape/paint for Renderer, I can't seem to find a way to fill the areas under the series line.

Any clues, how can I do this?


Solution

  • You could create your chart with a StackedXYAreaRenderer. Specify AREA_AND_SHAPES in the constructor and enable outlines. See the ChartFactory code for createStackedXYAreaChart() as an example.

    StackedXYAreaRenderer r = new StackedXYAreaRenderer(XYAreaRenderer.AREA_AND_SHAPES);
    r.setOutline(true);
    

    Given a renderer, you can set the outline paint and stroke as desired.