Search code examples
colorsjfreecharttime-seriesfilltimeserieschart

fill the area with color in time series jfreechart


I am trying to generate a time series with the area underneath filled with color.

Looking at examples of the jfreechart library there is this method:

ChartFactory.createAreaChart(...)

However the dataset required is a Category dataset, something quite different from the Time Series Dataset that I currently create:

ChartFactory.createTimeSeriesChart(...)

Which methods should I use to fill with color the area underneath the plotted line?

Thank you!


Solution

  • Add the following after you create the a chart (using createTimeSeriesChart)

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new XYAreaRenderer());