Suppose you have the following code to display grid lines and inside tic marks on the same plot:
Code: Select all
package hep.aida.jfree;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Stroke;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
public class TicAndGrid
{
public static class ChartTheme extends StandardChartTheme
{
public ChartTheme() {
super("Legacy");
}
public void apply(JFreeChart chart)
{
super.apply(chart);
}
}
public static void main(String[] args)
{
ChartFactory.setChartTheme(new ChartTheme());
JFreeChart chart = ChartFactory.createXYBarChart("Test", "X Axis", false, "Y Axis", null, PlotOrientation.HORIZONTAL, false, false, false);
XYPlot plot = chart.getXYPlot();
plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinesVisible(true);
plot.setDomainGridlinePaint(Color.red);
plot.setRangeGridlinePaint(Color.red);
Stroke stroke = new BasicStroke(2.0f);
plot.setDomainGridlineStroke(stroke);
plot.setRangeGridlineStroke(stroke);
plot.getDomainAxis().setAutoRange(true);
plot.getRangeAxis().setAutoRange(true);
plot.getDomainAxis().setMinorTickMarksVisible(true);
plot.getRangeAxis().setMinorTickMarksVisible(true);
plot.getDomainAxis().setTickMarkInsideLength(20.0f);
plot.getDomainAxis().setTickMarkOutsideLength(0.0f);
plot.getDomainAxis().setMinorTickMarkInsideLength(10.0f);
plot.getDomainAxis().setMinorTickMarkOutsideLength(0.0f);
plot.getDomainAxis().setTickMarkPaint(Color.black);
plot.getRangeAxis().setTickMarkInsideLength(20.0f);
plot.getRangeAxis().setTickMarkOutsideLength(0.0f);
plot.getRangeAxis().setMinorTickMarkInsideLength(8.0f);
plot.getRangeAxis().setMinorTickMarkOutsideLength(0.0f);
plot.getRangeAxis().setTickMarkPaint(Color.black);
plot.setBackgroundPaint(Color.white);
JFrame frame = new JFrame();
frame.setContentPane(new ChartPanel(chart));
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
BUT, suppose that you remove these lines from the above code and rerun it:
Code: Select all
plot.setDomainGridlineStroke(stroke);
plot.setRangeGridlineStroke(stroke);
So I was just wondering if this is a bug or intended behavior. I've worked around this in my plots by displaying outside tic marks, because I think this is a cleaner way to go and looks better. But if I did want to use inside tic marks on my plots, this bug means that they can be partially covered up when a custom stroke is set on the grid.
I think to be consistent it should be one way or another, and I think the proper way to go is always displaying tic marks on top of the grid, regardless of whether a custom Stroke object was set for the grid. At least, that behavior would make the most sense to me.
--Jeremy