Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 803
Line Avatar asked Oct 19 '18 10:10

Line


3 Answers

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.

like image 197
Catalina Island Avatar answered Nov 14 '22 23:11

Catalina Island


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));
like image 34
rumman0786 Avatar answered Nov 14 '22 23:11

rumman0786


For Jfreechart 1.5.0:

XYItemRenderer renderer = lineChart.getXYPlot().getRenderer();
renderer.setDefaultStroke(new BasicStroke(2.0f));
((AbstractRenderer) renderer).setAutoPopulateSeriesStroke(false);
like image 45
Achmad Fathoni Avatar answered Nov 14 '22 22:11

Achmad Fathoni