How to customize BarChart ?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ji
Posts: 7
Joined: Fri Aug 11, 2006 10:27 am

How to customize BarChart ?

Post by ji » Mon Aug 14, 2006 10:07 am

Hi !

Simple question, as in the topic.

How can I cusotmize my BarChart ?

My JFreeChart object doesn't have any method, for example getPlot() e.t.c.

Please help

oacis
Posts: 101
Joined: Fri Jan 07, 2005 5:57 am
Location: Australia, Sydney

Post by oacis » Mon Aug 14, 2006 11:38 pm

I think you will have to be a little more specific about what part of the JFreeChart you need to customise, i.e. Colours, Datasets, tick marks, scaling etc.

The simplest way to start using a chart is to use the ChartFactory static methods

Code: Select all

JFreeChart jFreeChart = ChartFactory.createBarChart("Chart title", "categoryAxisLabel", "ValueAxisLabel", categoryDataset, PlotOrientation.VERTICAL, true, false, false);
You can then get the plot by using

Code: Select all

jFreeChart.getCategoryPlot()

ji
Posts: 7
Joined: Fri Aug 11, 2006 10:27 am

Post by ji » Tue Aug 15, 2006 8:51 am

Yeah , if I use ChartFactory i can't use method getPlot(). Why ? My JFreeChart object doesn't have any methods ? :shock:

oacis
Posts: 101
Joined: Fri Jan 07, 2005 5:57 am
Location: Australia, Sydney

Post by oacis » Tue Aug 15, 2006 9:43 am

What version of JFreeChart are you using?

Could you also post the code that you are trying to get the plot from?

ji
Posts: 7
Joined: Fri Aug 11, 2006 10:27 am

Post by ji » Tue Aug 15, 2006 12:20 pm

jfreechart-1.0.1

Code: Select all

JFreeChart chart = ChartFactory.createBarChart3D(her goes all params);
and then there are no methods for chart object.

i hit ctrl+space and no completions available !

oacis
Posts: 101
Joined: Fri Jan 07, 2005 5:57 am
Location: Australia, Sydney

Post by oacis » Tue Aug 15, 2006 12:28 pm

What IDE are you using?

ji
Posts: 7
Joined: Fri Aug 11, 2006 10:27 am

Post by ji » Tue Aug 15, 2006 12:29 pm

Eclipse 3.0

oacis
Posts: 101
Joined: Fri Jan 07, 2005 5:57 am
Location: Australia, Sydney

Post by oacis » Tue Aug 15, 2006 12:42 pm

I use eclipse 3.1 and 3.2 at the moment - you will need to attach the source code to the jar file for code completion.

This works in eclipse 3.1.0 so YMMV

Right click on the project and select
Build Path -> Configure Build Path...

Select the Libraries tab

Open up the tree on the jfreechart.jar entry (i.e. click the '+')

Click on the Source attachment: (None) entry

Click the Edit... button

Select the source folder for JFreeChart

ji
Posts: 7
Joined: Fri Aug 11, 2006 10:27 am

Post by ji » Tue Aug 15, 2006 1:00 pm

it's not working :(

oacis
Posts: 101
Joined: Fri Jan 07, 2005 5:57 am
Location: Australia, Sydney

Post by oacis » Tue Aug 15, 2006 1:13 pm

Try this:

Highlight ChartFactory in the code
Press the F3 button
when the page opens there should be a button to attach source at the top...

ji
Posts: 7
Joined: Fri Aug 11, 2006 10:27 am

Post by ji » Wed Aug 16, 2006 8:14 am

ok, it's working now !
thanks !
now I need to change values presented on the X and Y axis to ints. How can I do it ?

Locked