Search code examples
javachartsjfreechart

How to set line thickness for multiple series in JFreeChart?


I create a lot of charts. In each of them I need to call

renderer.setSeriesStroke( i, new BasicStroke( 2.0f ) );

for each series. (renderer is chart.getXYPlot().getRenderer()).

I wonder if there is any way to set the thickness globally.


Solution

  • Call the renderer's setBaseStroke() setDefaultStroke() method, like they say here, and change the autoPopulateSeriesStroke flag, like they say here.

    //renderer.setBaseStroke(new BasicStroke(2.0f));
    renderer. setDefaultStroke(new BasicStroke(2.0f));
    renderer.setAutoPopulateSeriesStroke(false);
    

    The answers here and here show the new method name when migrating to v1.5.