Plot data ordering

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
d_rambabu
Posts: 8
Joined: Mon Apr 14, 2008 8:36 am
Location: Hyderabad, India
Contact:

Plot data ordering

Post by d_rambabu » Mon Apr 14, 2008 8:56 am

Hi..
In my application of showing quote averages, the plot data comes in, will have random timestamps, and is not ordered.
i.e. plotdata[0] is a quote for 2-JAN-2008 09:35:00
whereas plotdata[1] corresponds to a quote at 2-JAN-2008 09:20:00

If I use the plot data to draw a graph, the graph comes in zig zag fashion. Is there a property I can set for the graph, to show the plot data in an ordered fashion?
The graph shows properly if plotdata is in increasing order of timestamps. But is there a property in the chart renderer to plot the points properly even when the plot data is not in increasing order?

-Rambabu

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Mon Apr 14, 2008 1:30 pm

All the renderers just process the data in the order that it comes from the dataset.

Some of the dataset classes in JFreeChart have an option to "auto-sort" data (e.g. XYSeries/XYSeriesCollection), so maybe that can help you.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

1337rooster
Posts: 6
Joined: Mon Apr 14, 2008 3:06 pm

Post by 1337rooster » Mon Apr 14, 2008 3:10 pm

If your using CategoryPlot, it sorts the labels alphabetically, maybe use a more numerical date format which can be sorted alphabetically.

I.E. yyyy/mm/dd

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Mon Apr 14, 2008 10:23 pm

1337rooster wrote:If your using CategoryPlot, it sorts the labels alphabetically
Not true. The CategoryPlot or, more specifically, the CategoryAxis will display the categories in the order that they were added to the dataset.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

1337rooster
Posts: 6
Joined: Mon Apr 14, 2008 3:06 pm

Post by 1337rooster » Tue Apr 15, 2008 3:49 pm

Oh, it didn't seem to work that way for me. I was trying to figure out how to get the labels to display in the order I provided. I noticed that they were going in alphabetical order so I looked at the api for CategoryPlot and found:

setColumnRenderingOrder(org.jfree.util.SortOrder order)
Sets the column order in which the items in each dataset should be rendered and sends a PlotChangeEvent to all registered listeners.

which only had SortOrder.Ascending and SortOrder.Descending as options. Any idea as to why it would have been in Ascending order for me? Does it depend on the dataset? I used the charfactory to get a bar chart and these were the only changes I made:


CategoryPlot plot = (CategoryPlot)chart.getPlot();
NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());//displays ony integers for now
yAxis.setLabelFont(HISTOGRAM_AXIS_FONT);

//set the x axis, set its font, set vertical Labels
CategoryAxis xAxis = (CategoryAxis)plot.getDomainAxis();
xAxis.setLabelFont(HISTOGRAM_AXIS_FONT);
xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
xAxis.setLowerMargin(0.00);
xAxis.setCategoryMargin(0.05);
xAxis.setUpperMargin(0.00);

Dataset was a CategoryDataset
Jfreechart version: 1.0.1

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Apr 16, 2008 4:24 pm

The columnRenderingOrder doesn't change the position of the categories (columns), just the order in which they are drawn. It is a hack to make the 3D effect work for bar charts, where sometimes the 3D effect overlaps so you need to draw the bars from right-to-left instead of left-to-right.

It is still the dataset that controls the position of the categories along the axis.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked