Text get cut

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jfreeuser2006
Posts: 59
Joined: Mon Nov 20, 2006 1:00 pm

Text get cut

Post by jfreeuser2006 » Thu May 03, 2007 10:55 am

Hi,

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?

Image


Thanks in advance. :-)

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 » Thu May 03, 2007 11:25 am

Please post a small self-contained demo app that reproduces the problem.
David Gilbert
JFreeChart Project Leader

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

jfreeuser2006
Posts: 59
Joined: Mon Nov 20, 2006 1:00 pm

Post by jfreeuser2006 » Thu May 10, 2007 2:05 am

Hi Dave,

Sorry wasn't able to get back to you at once.

Here is the code that i have come up.

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);

    }

}
Here is the image of the chart that is produced:

Image

The annotation at the top right and the value marker at the bottom right
are not shown completely.

jfreeuser2006
Posts: 59
Joined: Mon Nov 20, 2006 1:00 pm

Post by jfreeuser2006 » Wed May 16, 2007 12:40 am

Any clues?

rmadani
Posts: 6
Joined: Wed Aug 22, 2007 12:00 am

Text get cut

Post by rmadani » Thu Aug 23, 2007 6:08 am

Did you guys find a work around? My labels are cut just like yours to the right of the graph (horizontally label). Any suggestions are greatly appreciated.

thx,
Reza

dreamit
Posts: 2
Joined: Thu Aug 23, 2007 12:35 pm

Post by dreamit » Thu Aug 23, 2007 12:39 pm

jfreeuser2006 i know you posted this a long time ago, but even so i risk to ask how did you do the vertical dates in the x-axis????

thanks for your atention

callisto
Posts: 5
Joined: Tue Jul 10, 2007 4:29 pm

Post by callisto » Thu Aug 23, 2007 1:52 pm

To rotate the tick labels on a ValueAxis : axis.setVerticalTickLabels(true)

dreamit
Posts: 2
Joined: Thu Aug 23, 2007 12:35 pm

Post by dreamit » Thu Aug 23, 2007 4:37 pm

thanks

but this only aplies to dateAxis am i right?

If i wanted to put the x-axis tick label vertically in a simple line chart would this be possible?

callisto
Posts: 5
Joined: Tue Jul 10, 2007 4:29 pm

Post by callisto » Thu Aug 23, 2007 5:15 pm

It applies to all ValueAxis subclasses (DateAxis, NumberAxis, ...)

If you're using a CategoryAxis then you can use axis.setCategoryLabelPositions(CategoryLabelPostions.UP_90)

chiewboon
Posts: 3
Joined: Thu Jan 04, 2007 5:13 am

Post by chiewboon » Fri Sep 28, 2007 7:41 am

Hi,

So does anyone has the solution to the label text being cut at the edges of the plot?


Thank you

doudou
Posts: 27
Joined: Tue Mar 14, 2006 6:05 pm

Post by doudou » Fri Sep 28, 2007 11:39 am

Why don't you just change the place of the marker?
You force the chart window to be 0 to 8 vertically, and then you place markers at 0 (so centered on 0 axis) and on 8 (so centered on 8 axis)

2 solutions: change axis range or move markers...

Locked