-3
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

public class JfreeChartPie {

    System.out.println("piechart");

    public static void main(String[] args) {

        System.out.println("piechart");
        // TODO Auto-generated method stub
        // create a dataset...
        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("Category 1", 43.2);
        dataset.setValue("Category 2", 27.9);
        dataset.setValue("Category 3", 79.5);
        // create a chart...
        JFreeChart chart = ChartFactory.createPieChart(
        "Sample Pie Chart",
        dataset,
        true,
        // legend?
        true,
        // tooltips?
        false
        // URLs?
        );
        // create and display a frame...
        ChartFrame frame = new ChartFrame("First", chart);
        //frame.pack();
        frame.setSize(300, 300);
        frame.setVisible(true);
    }
}

I run debian 9 gnu linux and eclipse 2018-09 I get from console just the text about jfreechart license, and it seems that it doesen't exute the code.I have got no problems.

  • 2
    That code doesn't even compile. Please [edit] your question to provide a [mcve] that demonstrates your issue. – Joe C Jan 06 '19 at 08:56
  • @Joe C this is the complete code, and I compiled it.I don't know what do u want,I read your suggestion but I think my post is ok.THanks –  Jan 06 '19 at 09:48
  • 1
    Except for the first (misplaced) call to `println()`, your example runs on my platform. See also [*Initial Threads*](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html), which may be critical on your platform. – trashgod Jan 06 '19 at 10:24

1 Answers1

1

To avoid such anomalies, verify that you construct and manipulate Swing GUI objects only on the event dispatch thread. As noted here, "A program may appear to work correctly, only to fail mysteriously in a different environment." For reference, I've modified your example accordingly.

pie chart

$ javac -cp .:$JFC JFreeChartPie.java && "$JRE" -cp .:$JFC JFreeChartPie
import java.awt.EventQueue;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

public class JFreeChartPie {

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                System.out.println("piechart");
                DefaultPieDataset dataset = new DefaultPieDataset();
                dataset.setValue("Category 1", 43.2);
                dataset.setValue("Category 2", 27.9);
                dataset.setValue("Category 3", 79.5);
                JFreeChart chart = ChartFactory.createPieChart(
                    "Sample Pie Chart", dataset, true, true, false);
                ChartFrame frame = new ChartFrame("Title", chart);
                frame.pack();
                frame.setSize(400, 400);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }
}
trashgod
  • 203,806
  • 29
  • 246
  • 1,045