Text that exceed the plot area get cut in v1.0.5. This is not the case with
v1.0.0.
How can I show the complete text that label the lines in the graph?

Thanks in advance. :-)
Code: Select all
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.annotations.CategoryTextAnnotation;
import org.jfree.chart.axis.CategoryAnchor;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.Marker;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleAnchor;
import org.jfree.ui.RefineryUtilities;
import org.jfree.ui.TextAnchor;
public class LineChartDemo extends ApplicationFrame {
public LineChartDemo(final String title) {
super(title);
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(700, 500));
setContentPane(chartPanel);
}
private CategoryDataset createDataset() {
final String type1 = "Type 1";
final String type2 = "Type 2";
final String type3 = "Type 3";
final String type4 = "Type 4";
final String type5 = "Type 5";
final String type6 = "Type 6";
final String type7 = "Type 7";
final String type8 = "Type 8";
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(1.0, "First", type1);
dataset.addValue(4.0, "First", type2);
dataset.addValue(3.0, "First", type3);
dataset.addValue(5.0, "First", type4);
dataset.addValue(5.0, "First", type5);
dataset.addValue(7.0, "First", type6);
dataset.addValue(7.0, "First", type7);
dataset.addValue(8.0, "First", type8);
return dataset;
}
private JFreeChart createChart(final CategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createLineChart(
"Line Chart Demo", // chart title
"Type", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.white);
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.white);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setAutoRangeIncludesZero(true);
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setStroke(new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {10.0f, 6.0f}, 0.0f
)
);
plot.getRangeAxis().setUpperBound(8.0);
plot.getDomainAxis().setUpperMargin(0.0);
Font font = new Font("Courier New", Font.BOLD, 12);
Marker marker = new ValueMarker(0.0);
marker.setStroke(new BasicStroke());
marker.setPaint(Color.BLUE);
marker.setLabelFont(font);
marker.setLabel("Marker Test");
marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
marker.setLabelTextAnchor(TextAnchor.BASELINE_RIGHT);
plot.addRangeMarker(marker);
int categorysize = plot.getCategories().size();
String categoryName = (String)plot.getCategories().get(categorysize-1);plot.getCategories().get(categorysize-2);
CategoryTextAnnotation annotation = new CategoryTextAnnotation("Annotation", categoryName, 8.0);
annotation.setFont(font);
annotation.setTextAnchor(TextAnchor.CENTER_LEFT);
annotation.setCategoryAnchor(CategoryAnchor.START);
plot.addAnnotation(annotation);
return chart;
}
public static void main(final String[] args) {
final LineChartDemo demo = new LineChartDemo("Line Chart Demo");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}