String values in X axis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
devangel
Posts: 9
Joined: Mon Jun 09, 2008 10:16 am
Location: India

String values in X axis

Post by devangel » Mon Jun 09, 2008 6:47 pm

Hi all,

I would like to have a XYLineChart in which I need String values in X axis and numeric values in Y axis. ( Like the one we get while inserting a chart in MS Excel )

I got the line chart, but not able to find how to customize it for my requirement.

Experts, guide me.. :roll:
Thanks,
devangel.
To Learn is to Unlearn!

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Mon Jun 09, 2008 7:06 pm

You want a CategoryPlot, not and XYPlot.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

devangel
Posts: 9
Joined: Mon Jun 09, 2008 10:16 am
Location: India

Post by devangel » Tue Jun 10, 2008 7:14 am

Hi Richard,

Thanks for your quick reply. I got the Category plot. But it is a bar chart.

My equirement is : In a line graph, is it possible to have fixed string values in the X axis... ( Again I am saying, like the one we get while inserting a line chart in MS Excel )

Any idea... :roll:
Thanks,
devangel.
To Learn is to Unlearn!

ndhai
Posts: 10
Joined: Thu Jun 05, 2008 2:00 pm

Post by ndhai » Tue Jun 10, 2008 8:59 am

can you show the Excel chart , please ?

devangel
Posts: 9
Joined: Mon Jun 09, 2008 10:16 am
Location: India

Post by devangel » Tue Jun 10, 2008 12:51 pm

Hi ndhai,

I am not able to post image.. :oops: please try creating a line chart in MS Excel..

In need of help..

Thanks.
Thanks,
devangel.
To Learn is to Unlearn!

devangel
Posts: 9
Joined: Mon Jun 09, 2008 10:16 am
Location: India

Post by devangel » Tue Jun 10, 2008 2:05 pm

Just you can imagine the XYLineChart. It is very same. The only difference between the XYLineChart and line chart in MS Excel is that, you can give fixed string constants in X axis in MS Excel Line chart.

But in XYLineChart, the series.add() method doesnt support any string arguments..

Just imagine this scenario : student names and their marks in a subject. Student names in X axis and Marks in Y axis. This is what I want.

Got any idea??
Thanks,
devangel.
To Learn is to Unlearn!

Filoche
Posts: 26
Joined: Sat Jul 28, 2007 7:23 pm

Post by Filoche » Tue Jun 10, 2008 2:17 pm

As David said look at CategoryPlot.

There's many examples aviable for you (ex.: linechartdemo7.java) in the demo jar coming with JFree.

Good luck.

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Tue Jun 10, 2008 4:18 pm

Code: Select all

org.jfree.chart.axis.SymbolAxis
provided your unique values can be cast as ints

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Tue Jun 10, 2008 5:17 pm

Code: Select all

ChartFactory.createLineChart(...)
The method uses a CategoryPlot to create a line chart where the domain axis has strings for values. This would be like the MS Excel chart that you are describing. Every chart you can create with ChartFactory comes in an XYPlot and a CategoryPlot version.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

devangel
Posts: 9
Joined: Mon Jun 09, 2008 10:16 am
Location: India

Post by devangel » Wed Jun 11, 2008 11:21 am

Hi Richard,

I got my requirement fulfilled.

Thanks a lot to ALL who helped. :D
Thanks,
devangel.
To Learn is to Unlearn!

samaeinder
Posts: 10
Joined: Thu Jun 12, 2008 6:34 am

facing same problem

Post by samaeinder » Thu Jun 12, 2008 6:37 am

Hi m also facing the exactly same problem.........
exactly as u r facing that strings value at y axis

plz help me out in solving the problem

Edit by RichardWest: removing personal email address to prevent possible spamming

devangel
Posts: 9
Joined: Mon Jun 09, 2008 10:16 am
Location: India

Post by devangel » Thu Jun 12, 2008 7:01 am

Hi Samarinder,

As Richard said, use

Code: Select all

ChartFactory.createLineChart(...)
Still you need more info, let me know.
Thanks,
devangel.
To Learn is to Unlearn!

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: facing same problem

Post by RichardWest » Thu Jun 12, 2008 7:28 am

samaeinder wrote:Hi m also facing the exactly same problem.........
exactly as u r facing that strings value at y axis

plz help me out in solving the problem
When discussing plots, it is more accurate to refer to the axes as the domain axis and the range axis and not x-axis and y-axis as we typically learn in elementary math. The domain axis is the axis for the independent variable, and the range axis is the axis for the dependent variable. In the equation y = 2x + 4, x is the independent variable and would be plotted on the domain axis, and y is the dependent variable (it depends on x) and would be plotted on the range axis.

Do you mean you want to have the plot rotated by 90 degrees so the domain axis is on the vertical axis? If so, simply set the orientation to PlotOrientation.HORIZONTAL. If you want strings on both the domain and range axis, I fail to understand what you are trying to plot and a picture would be very enlightening.

One another note, please do not solicit responses via personal email. The primary reason is that it prevents other forum users from benefiting from responses. Another reason is that it provides an avenue to facilitate spamming. I have removed your email address from your post.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

samaeinder
Posts: 10
Joined: Thu Jun 12, 2008 6:34 am

Thanks

Post by samaeinder » Fri Jun 13, 2008 5:53 am

Thanks all...i m getting the things right now......
And Richard i will take care from next time.
Thanks
Sam

RedSoxFan620
Posts: 2
Joined: Fri May 30, 2008 9:43 pm

Post by RedSoxFan620 » Wed Jun 18, 2008 4:09 pm

I'm trying to do this too, but I can't figure out where to put the strings. I need a category dataset, so I guess I use DefaultCategoryDataset, and the addValue for that uses a double ... where do the Strings go?

Locked