maximum axis tick marks, setting colors, etc

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
MonteKristo
Posts: 3
Joined: Fri Mar 14, 2003 11:20 pm

maximum axis tick marks, setting colors, etc

Post by MonteKristo » Fri Mar 14, 2003 11:36 pm

I'm porting code from using the old 0.9.2 version to the newest 0.9.6 and running into the following problems:

1. in the old version, if you wanted a Y-axis tickmark for the highest datapoint in your graph, you'd do just add a new tick unit with the maxValue, but in the new version, I can't get the following snippet of code to display the maxValue on my vertical axis (this is TimeSeries line graph):

TickUnits intTicks = NumberAxis.createIntegerTickUnits();
intTicks.add(new NumberTickUnit(maxValue, new DecimalFormat("0")));
axis.setStandardTickUnits(intTicks);

2. Version 0.9.2 allowed you to get an XYPlot from a TimeSeries graph and do the following:
Paint[] colors = new Paint[10];
// pseudo-code --> define each color
CategoryPlot chartPlot = (CategoryPlot)chart.getPlot();
chartPlot.setSeriesPaint(colors);

The new version doesn't seem to have that method?! The only way I found is to set the Paint on each series individually...is there a better way?!?

3. How do I make the tick marks on the vertical axes be in finer steps - meaning if my range is 0 to 50, i want Ticks and gridmarks every 5, instead of every 10. Same goes for the horizontal axes.

Thanks for any help!

Gary

Matt2000
Posts: 1
Joined: Sun Mar 16, 2003 6:14 am

Post by Matt2000 » Sun Mar 16, 2003 6:15 am

I'm having the same confusion, except I can't even find the way to set the paint for each series. Any suggestion on where to find or accomplish that?

Thanks alot.

Matt

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 Mar 17, 2003 9:54 am

I've started a new thread 'API Changes' where I have added some notes on the API changes between 0.9.4 --> 0.9.6. I'll edit that post as questions come in, to try and keep it up to date.

The methods for setting the series colors have changed with the introduction of secondary datasets, axes and renderers. Now the methods are found in the appropriate renderer class, not in the plot.

Regards,

Dave Gilbert

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

Re: maximum axis tick marks, setting colors, etc

Post by david.gilbert » Mon Mar 17, 2003 10:01 am

MonteKristo wrote:1. in the old version, if you wanted a Y-axis tickmark for the highest datapoint in your graph, you'd do just add a new tick unit with the maxValue, but in the new version, I can't get the following snippet of code to display the maxValue on my vertical axis (this is TimeSeries line graph):

TickUnits intTicks = NumberAxis.createIntegerTickUnits();
intTicks.add(new NumberTickUnit(maxValue, new DecimalFormat("0")));
axis.setStandardTickUnits(intTicks);
I think you are misunderstanding the purpose of the TickUnits collection here. It is just a set of 'standard' tick sizes...the axis will choose the size that allows the greatest number of ticks to be displayed without the lables overlapping. It doesn't have anything to do with the maximum value labelled on the axis (in fact, you can't directly control this).
MonteKristo wrote:2. Version 0.9.2 allowed you to get an XYPlot from a TimeSeries graph and do the following:
Paint[] colors = new Paint[10];
// pseudo-code --> define each color
CategoryPlot chartPlot = (CategoryPlot)chart.getPlot();
chartPlot.setSeriesPaint(colors);

The new version doesn't seem to have that method?! The only way I found is to set the Paint on each series individually...is there a better way?!?
In 0.9.5 and 0.9.6, you can only set the series paints one at a time (via the renderer). It would be trivial to add a method to read an array of Paint objects and set the series colors based on the array. If you add a feature request on SourceForge, I won't forget to do it.
MonteKristo wrote:3. How do I make the tick marks on the vertical axes be in finer steps - meaning if my range is 0 to 50, i want Ticks and gridmarks every 5, instead of every 10. Same goes for the horizontal axes.
Instead of letting the axis 'auto-select' an appropriate tick size, you can set one manually using the setTickUnit(...) method. But now you are responsible for ensuring that the labels don't overlap...so don't set the unit too small.

Regards,

Dave Gilbert

MonteKristo
Posts: 3
Joined: Fri Mar 14, 2003 11:20 pm

Post by MonteKristo » Mon Mar 17, 2003 6:03 pm

Matt2000 wrote:I'm having the same confusion, except I can't even find the way to set the paint for each series. Any suggestion on where to find or accomplish that?

Thanks alot.

Matt
I'm doing this:

JFreeChart chart = ChartFactory.createTimeSeriesChart(......);
XYPlot chartPlot = (XYPlot)chart.getPlot();
StandardXYItemRenderer renderer = (StandardXYItemRenderer)chartPlot.getRenderer();

// uses the colors we defined
Paint[] palette = getColorPalette();
for (int i=0;i<chartPlot.getSeriesCount();i++)
{
renderer.setSeriesPaint(i,palette);
}

Locked