1

JFreeChart seems to be working, except for all the text. It just doesn't show up at all, and I've no idea why. I attached a picture of a window with a pie graph that I got from a tutorial site. As you can see, the text isn't visible. (sorry my twitter feed was really long)

ThanksJFreeChart

Edit:

Here is the code that generates the above graph:

package analyzer_main;

import java.awt.Font;

public class FloatChart extends Composite implements Screen {

    JFreeChart floatChart;

    public FloatChart(Composite parent, int style){
        super(parent,style);
        createContents();
    }

    private void createContents(){
        this.setLayout(new FormLayout());
        floatChart = createChart(createDataset());
        ChartComposite chartComposite = new ChartComposite(this,SWT.NONE,floatChart, true);
        FormData fd_chartComposite = new FormData();
        fd_chartComposite.left  = new FormAttachment(0);
        fd_chartComposite.right = new FormAttachment(100,0);
        fd_chartComposite.top   = new FormAttachment(0);
        fd_chartComposite.bottom= new FormAttachment(100,0);
        chartComposite.setLayoutData(fd_chartComposite);
    }

/** * Creates the Dataset for the Pie chart */

    private PieDataset createDataset() {
        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("One", new Double(43.2));
        dataset.setValue("Two", new Double(10.0));
        dataset.setValue("Three", new Double(27.5));
        dataset.setValue("Four", new Double(17.5));
        dataset.setValue("Five", new Double(11.0));
        dataset.setValue("Six", new Double(19.4));
        return dataset;
    }

    private JFreeChart createChart(PieDataset dataset) {

        JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart
                // title
                dataset, // data
                true, // include legend
                true, false);

        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setSectionOutlinesVisible(false);
        plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
        plot.setNoDataMessage("No data available");
        plot.setCircular(false);
        plot.setLabelGap(0.02);
        return chart;
    }

    @Override
    public void Load() {
    }

}

As you can see, it's pretty much the same as from the tutorial.

  • 2
    We're to diagnose your use of JFreeChart from... an image? – Dave Newton Dec 20 '11 at 15:25
  • Well, I could post the code, but I got it right from a tutorial site. –  Dec 20 '11 at 15:26
  • This site http://www.vogella.de/articles/EclipseJFreeChart/article.html –  Dec 20 '11 at 15:27
  • I don't understand why you are pointing to that article. That's being lazy. Also, that's not where the problem lies, it's in your code. – Bhesh Gurung Dec 20 '11 at 16:02
  • Even if you followed this tutorial, you should post the code you used. Otherwise, we couldn't help you very well to understand where the problem is and to solve it. – Alberto Solano Dec 20 '11 at 16:04
  • Okay, I added the code. But, honestly, I don't think it's the code, since it's copy-pasted, and behaves exactly the same way as on the site (except the text). I was hoping someone else had a similar problem. –  Dec 20 '11 at 17:20
  • Might not be an issue, but what JDK are you running with? Is it OpenJDK? – KevinS Dec 20 '11 at 21:25
  • Consider `Font.SANS_SERIF` or another [font family constant](http://docs.oracle.com/javase/6/docs/api/java/awt/Font.html) in the `Font` constructor. – trashgod Dec 20 '11 at 22:03
  • Kevin Stembridge: Sorry, I'm not sure how to check. I'm using Ubuntu, so probably whatever comes with that. –  Dec 21 '11 at 19:41
  • trashgod: Thanks for the suggestion. I tried that, the text is still not visible. –  Dec 21 '11 at 19:42

2 Answers2

3

I was having the same problem using Linux Mint 11, Eclipse, and JFreeChart 1.0.14. I found that backing up to 1.0.13 resolved the problem.

  • I ended up doing the same - downgrading....I'm on Windows. I also posted something on the jfreechart forums since it seems to be broken since .14 was released. – ssnyder Jan 24 '12 at 15:57
  • 2
    Just ran into the same problem. It appears you can use the jfreechart-1.0.14 jars and simply replace jcommon-1.0.17 with jcommon-1.0.16. At least that solves the issue for my simple test cases. – Helmuth M. Apr 21 '12 at 18:31
  • Helmuth's fix also worked for me. New JFreeChart with previous version of JCommon (Indigo SR2, osx Mountain Lion) – ianmayo Oct 06 '12 at 04:52
  • I believe the issue here was that we switched some text rendering to use AttributedStrings and the SWTGraphics2D implementation didn't handle those correctly. This is fixed in later versions of JFreeChart. – David Gilbert Dec 06 '13 at 08:04
1

First of all, like Kevin Stembridge said, check your JDK. You are using Ubuntu, then try this command in a terminal:

sudo update-alternatives --config java

You can see the JDKs installed on your system and the JDK (is selected at left with a *) you are using for this project.

If you have the Oracle JDK (from package java-6-sun) and OpenJDK (the openjdk-6-jdk package), try to select the Oracle JDK, because the OpenJDK has some graphical differences from the Oracle JDK and maybe these are the reason of this strange behavior on your JFreeChart. Select the Oracle JDK, recompile the Java project, and see if something in your JFreeChart is changed.

Check this Ubuntu Help page for details about Java, or read this old question of SO, or this page if you want to install the latest Oracle JDK.

About the code, it's very similar as from the tutorial, like you said. I have tested your code on Ubuntu, using Eclipse and Oracle JDK 6. The result is this:

screenshot

adding the chart to a panel, editing only the createContents method (and commenting the ChartComposite parts, because I don't know what is ChartComposite), with this code:

private void createContents(){
        //this.setLayout(new FormLayout());
        floatChart = createChart(createDataset());
        ChartPanel chartPanel = new ChartPanel(floatChart);
        // default size
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        // add it to our application
        setContentPane(chartPanel);
        /*ChartComposite chartComposite = new ChartComposite(this,SWT.NONE,floatChart, true);
        FormData fd_chartComposite = new FormData();
        fd_chartComposite.left  = new FormAttachment(0);
        fd_chartComposite.right = new FormAttachment(100,0);
        fd_chartComposite.top   = new FormAttachment(0);
        fd_chartComposite.bottom= new FormAttachment(100,0);
        chartComposite.setLayoutData(fd_chartComposite);*/
    }

Then, my advice is to review all your code used for the GUI I saw in your screenshot, and you should solve the problem.

Comment this answer if you have questions or problems.

Community
  • 1
  • 1
Alberto Solano
  • 7,972
  • 3
  • 38
  • 61