'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 1:[1]

From Jfreechart 1.5.0 and Line Chart created with ChartFactory.createLineChart(...)

    JFreeChart lineChart = ChartFactory.createLineChart(...);

    LineAndShapeRenderer renderer = (LineAndShapeRenderer) lineChart.getCategoryPlot().getRenderer();
    renderer.setAutoPopulateSeriesStroke(false);
    renderer.setDefaultStroke(new BasicStroke(3.0f));

Solution 2:[2]

For Jfreechart 1.5.0:

XYItemRenderer renderer = lineChart.getXYPlot().getRenderer();
renderer.setDefaultStroke(new BasicStroke(2.0f));
((AbstractRenderer) renderer).setAutoPopulateSeriesStroke(false);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rumman0786
Solution 2 Achmad Fathoni