Setting the chart "title" to the axis title

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
aram535
Posts: 25
Joined: Thu Apr 24, 2008 11:59 pm

Setting the chart "title" to the axis title

Post by aram535 » Tue Jan 11, 2011 6:13 pm

Hi,

I'm trying to create a bunch of graphs dynamically from a database so I need to set the title of the graph from the dataset. The dataset contains the axis name, which I can display easily.

Code: Select all

		final CategoryAxis domainAxis = plot.getDomainAxis();
		domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
No problem there, the label shows up. However, both of these produce a 'null'

Code: Select all

		System.out.println(domainAxis.getLabel());

		for(int i=0; i<=plot.getRangeAxisCount(); i++){
			System.out.println("Axis("+i+") : "+plot.getRangeAxisForDataset(i).getLabel());
		}
The dataset is very simple:

Management , G = 1.5
Management , P = 1.25
Management , R = 1.75
Management , T = 1.8

I want the Title of the chart to be "Management" in this case.

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Re: Setting the chart "title" to the axis title

Post by matinh » Wed Jan 12, 2011 12:54 pm

I'm afraid I don't really get your problem. Just do a

Code: Select all

chart.setTitle("Management")
to set the chart's title accordingly.

- martin

aram535
Posts: 25
Joined: Thu Apr 24, 2008 11:59 pm

Re: Setting the chart "title" to the axis title

Post by aram535 » Wed Jan 12, 2011 1:50 pm

No problem, I must have not properly described the problem.

The class that is in question is fully dynamic. So It's 'management' this time, but it'll be something else the next time it runs. How do I extract back out the axis label dynamically?

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Re: Setting the chart "title" to the axis title

Post by matinh » Wed Jan 12, 2011 1:55 pm

Just as you wrote before:

Code: Select all

plot.getRangeAxisForDataset(i).getLabel()
- martin

aram535
Posts: 25
Joined: Thu Apr 24, 2008 11:59 pm

Re: Setting the chart "title" to the axis title

Post by aram535 » Wed Jan 12, 2011 2:14 pm

See original post, it's returning a 'null'

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Re: Setting the chart "title" to the axis title

Post by matinh » Wed Jan 12, 2011 2:21 pm

You asked
How do I extract back out the axis label dynamically?
And that's what I answered. If the given call returns null, your axis label is not set at all.

So what do you actually want the title to be?

I assume you want it to be some key from the dataset. So ask the dataset for it. The exact code depends on the type of dataset you are using!

hth,
- martin

aram535
Posts: 25
Joined: Thu Apr 24, 2008 11:59 pm

Re: Setting the chart "title" to the axis title

Post by aram535 » Wed Jan 12, 2011 2:38 pm

The label shows up on the graph axis, so obviously it isn't set to null. For some reason I cannot read it back.
I want the title to be label that is on the Y axis.

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Re: Setting the chart "title" to the axis title

Post by matinh » Wed Jan 12, 2011 3:13 pm

What you are talking about is not the label of the axis but the categories from the dataset, which are of course also printed on the axis. So as I suggested earlier: try to obtain the keys/categories/values from the dataset itself and not from the axis.

- martin

Locked