Reputation: 3147
Greeting,
I was wondering is it possible to add some margin to Jfree charts and align the chart title to left of the chart rather than default center of the chart.
Expected Chart
Need to add a 28 px margin to all directions. TOP , BOTTOM , LEFT and RIGHT
And to make the chart title align to the left rather than center.
Chart which i am able to generate
Upvotes: 0
Views: 2176
Reputation: 2059
Set value to the lowerMargin, upperMargin property of X Axis. This is kotlin code:
val dateAxis = DateAxis("Time")
dateAxis.lowerMargin = 0.05
dateAxis.lowerMargin = 0.05
And this is the result:
[]
Upvotes: 0
Reputation: 3147
To Add margin to Chart we can add Padding
public void addMargin(JFreeChart jChart){
RectangleInsets chartRectangle = new RectangleInsets(28F,30F,30F,30F);
//RectangleInsets chartRectangle = new RectangleInsets(TOP,LEFT,BOTTOM,RIGHT);
jChart.setPadding(chartRectangle);
}
To align the header to Left set horizontal alignment to Chart title
public void alignChartTitle(JFreeChart jChart){
jChart.getTitle().setHorizontalAlignment(HorizontalAlignment.LEFT);
}
Upvotes: 4