Left justified title

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
rajan
Posts: 4
Joined: Sun Feb 19, 2012 4:38 pm
antibot: No, of course not.

Left justified title

Post by rajan » Sun Feb 19, 2012 4:47 pm

Hi

I create a chart like this:

final JFreeChart chart = ChartFactory.createBarChart3D("MyDFS", "DFK", "DFX",defaultcategorydataset, PlotOrientation.VERTICAL, true, true,true);

When the chart is displayed the title MYDFS is at the top and center.
I want the title at the top however to the left.

Can you please let me know how to do it.

I tried:
chart.getTitle.setMargin(0,0,0,0)
but the title still shows at center.

Thanks
Rajan

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Left justified title

Post by John Matthews » Sun Feb 19, 2012 8:43 pm

TextTitle has parameters that let you change position, alignment and padding. You can experiment with differrent effects using setTitle().

rajan
Posts: 4
Joined: Sun Feb 19, 2012 4:38 pm
antibot: No, of course not.

Re: Left justified title

Post by rajan » Mon Feb 20, 2012 5:38 am

I tried :(
Looks like I may need to use layouts which I am reading now.

It should be simple, instead of displaying title in center, I want to display to left. Looking from other API's in JFreeChart I am sure there is some way to do this in a simple way.

Any other suggestions.

Thanks
Rajan

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Left justified title

Post by paradoxoff » Mon Feb 20, 2012 8:06 am

Code: Select all

chart.getTitle().setHorizontalAlignment(HorizontalAlignment.LEFT);

rajan
Posts: 4
Joined: Sun Feb 19, 2012 4:38 pm
antibot: No, of course not.

Re: Left justified title

Post by rajan » Mon Feb 20, 2012 4:34 pm

This will bring the title to the left side of the chart.
I want title to remain on top but instead of being displayed in the center, I want it left on left side.

Ex: It show like this right now
|----------------------------------------------- MYDFS ------------------------------------------|

I want it like:
|MYDFS-------------------------------------------------------------------------------------------|

Thanks
Rajan

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Left justified title

Post by John Matthews » Mon Feb 20, 2012 6:09 pm

HorizontalAlignment.LEFT, suggested by @paradoxoff, does exactly what you show. Using addSubtitle() is another convenient way to experiment with the myriad settings.

rajan
Posts: 4
Joined: Sun Feb 19, 2012 4:38 pm
antibot: No, of course not.

Re: Left justified title

Post by rajan » Mon Feb 20, 2012 9:32 pm

Sorry my mistake.
It works. (My build did not contain changes)

Thanks
Rajan

Locked