Wednesday, November 23, 2011

Changing the line size of a JFreeChart chart

This is an example showing how to change the line size of a Java graph builded with JFreeChart library.

The example is using the version JFreeChart 1.0.13

...
private JFreeChart createChart(XYDataset dataset, ICarteira car) {
// create the chart...
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
car.getNome(), // title
"Tempo", // x axis label
"Valor", // y axis label
dataset, // data
true, // include legend
true, // tooltips
true // urls
);
XYPlot plot = chart.getXYPlot();
// here we change the line size
int seriesCount = plot.getSeriesCount();
for (int i = 0; i < seriesCount; i++) {
plot.getRenderer().setSeriesStroke(i, new BasicStroke(2));
}
// line size changed
return chart;
}
...

No comments:

Post a Comment