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.
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.
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));
For Jfreechart 1.5.0:
XYItemRenderer renderer = lineChart.getXYPlot().getRenderer();
renderer.setDefaultStroke(new BasicStroke(2.0f));
((AbstractRenderer) renderer).setAutoPopulateSeriesStroke(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With