8

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.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Line
  • 1,529
  • 3
  • 18
  • 42

3 Answers3

7

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.

Catalina Island
  • 7,027
  • 2
  • 23
  • 42
  • 1
    My renderer was `XYItemRenderer`, so I needed to use `((AbstractRenderer) this.renderer).setAutoPopulateSeriesStroke(false);` like in referenced link ;) – Line Oct 22 '18 at 10:46
3

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));
rumman0786
  • 1,150
  • 10
  • 20
  • is it actually different from the accepted answer? doesn't look like that – Line Jan 08 '21 at 19:34
  • 2
    Yes, From JFreechart 1.5.0 the accepted answer won't work as the method used is now deprecated. my answer will work for those who are using the newer version. – rumman0786 Jan 09 '21 at 01:40
1

For Jfreechart 1.5.0:

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