Problems with Axis and ItemLabels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
mad
Posts: 3
Joined: Wed Apr 28, 2010 9:03 am
antibot: No, of course not.

Problems with Axis and ItemLabels

Post by mad » Sun May 02, 2010 2:09 am

Graph Type: XYPlot, XYLineAndShapeRenderer, NumberAxis Range, NumberAxis Domain
Problem1: I want to Increase The Distance between TickMarks. Simply calling setTickUnit(10) or something number larger than 1 makes the axis increment by that amount. I want to set the spacing between ticks without changing increment.

Code: Select all

Paint tickMarkPaint = new Color(0x00,0x00,0xff);
Paint axisLinePaint = new Color(0x00,0x00, 0xff);
Font tickLabelFont = new Font(NumberAxis.DEFAULT_TICK_LABEL_FONT.getName(), 
    Font.BOLD, 12);
Font labelFont = new Font("Eras Medium ITC", 0, 16);
Stroke axisLineStroke = new BasicStroke(1.8f, 
    BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER);
Stroke tickMarkLineStroke = new BasicStroke(1.4f, 
    BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER);
float tickMarkInsideLength = 2.8f;
float tickMarkOutsideLength = 2.8f;

NumberAxis yAxis = new NumberAxis(Y_AXIS_LABEL);
yAxis.setAutoRangeIncludesZero(true);
yAxis.setTickUnit(new NumberTickUnit(1));
yAxis.setLabelAngle(Math.PI / 2D);
yAxis.setTickLabelFont(tickLabelFont);
yAxis.setAxisLineStroke(axisLineStroke);
yAxis.setTickMarkStroke(tickMarkLineStroke);
yAxis.setTickMarkInsideLength(tickMarkInsideLength);
yAxis.setTickMarkOutsideLength(tickMarkOutsideLength);
yAxis.setTickMarkPaint(tickMarkPaint);
yAxis.setLabelFont(labelFont);
yAxis.setAxisLinePaint(axisLinePaint);
yAxis.setMinorTickCount(1);
yAxis.setMinorTickMarkInsideLength(0.00f);
yAxis.setMinorTickMarkOutsideLength(0.00f);
yAxis.setMinorTickMarksVisible(true);

NumberAxis xAxis = new NumberAxis(X_AXIS_LABEL);
xAxis.setAutoRangeIncludesZero(true);
xAxis.setTickUnit(new NumberTickUnit(1));
xAxis.setRangeWithMargins(1, 24);
xAxis.setRangeType(org.jfree.data.RangeType.POSITIVE);
DomainAxisFormatter nf = new DomainAxisFormatter();
xAxis.setNumberFormatOverride(nf);
xAxis.setTickLabelFont(tickLabelFont);
xAxis.setAxisLineStroke(axisLineStroke);
xAxis.setTickMarkStroke(tickMarkLineStroke);
xAxis.setTickMarkInsideLength(tickMarkInsideLength);
xAxis.setTickMarkOutsideLength(tickMarkOutsideLength);
xAxis.setTickMarkPaint(tickMarkPaint);
xAxis.setLabelFont(labelFont);
xAxis.setAxisLinePaint(axisLinePaint);

plot = jfreechart.getXYPlot();
plot.setDataset(new XYSeriesCollection());
plot.setDomainAxis(xAxis);
plot.setRangeAxis(yAxis);
plot.setOrientation(PlotOrientation.VERTICAL);
Problem: Renderer Item Label are obscured by line plot; I tried fixing by using XYTextAnnotation but that had same problems;

Code: Select all

NumberFormat format = NumberFormat.getIntegerInstance(Locale.US);
XYItemLabelGenerator generator = new StandardXYItemLabelGenerator(
    StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, 
    format, format);
renderer.setBaseItemLabelFont(itemLabelFont, true);
renderer.setBaseItemLabelPaint(Color.GRAY, true);
renderer.setBaseItemLabelGenerator(generator);
renderer.setBaseItemLabelsVisible(true);

Locked