0

I write a code that can show pie chart by a new frame, but i want to show that chart into a label

My code is

DefaultPieDataset pieDataset = new DefaultPieDataset();
        pieDataset.setValue("Bangla 1st",new Integer(txt_Bangla1st.getText()));
        pieDataset.setValue("Bangla 2nd",new Integer(txt_Bangla2nd.getText()));
        pieDataset.setValue("English 1st",new Integer(txt_English1st.getText()));
        pieDataset.setValue("English 2nd",new Integer(txt_English2nd.getText()));
        pieDataset.setValue("Math",new Integer(txt_Math.getText()));
        pieDataset.setValue("Social Science",new Integer(txt_Social.getText()));
        pieDataset.setValue("Science",new Integer(txt_Science.getText()));
        pieDataset.setValue("Religion",new Integer(txt_Religion.getText()));

        JFreeChart chart = ChartFactory.createPieChart("Pie Chart", pieDataset, true, true, true);
        PiePlot p = (PiePlot) chart.getPlot();
        ChartFrame frame = new ChartFrame("Pie Chart", chart);
        frame.setVisible(true); 
        frame.setSize(400, 500); //show frame size

Set the chart into a label which variable name is lblPichartAndBarchart.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • What is your question? – Hovercraft Full Of Eels Oct 02 '15 at 18:48
  • set the pie chart into a jLabel @HovercraftFullOfEels – MD Sijad Faisal Oct 02 '15 at 18:49
  • 2
    `"set the pie chart into a jLabel"` -- That's not a question; that's a requirement. You're not showing any ChartFrame code, you're not telling us what problems you're having. – Hovercraft Full Of Eels Oct 02 '15 at 18:50
  • I already mention it the chart is showing by a new frame,,but i want to show that into a jLabel – MD Sijad Faisal Oct 02 '15 at 18:51
  • @HovercraftFullOfEels sir, Did you get my question ? – MD Sijad Faisal Oct 02 '15 at 19:03
  • 1
    *"Did you get my question ?"* That is the first question I've seen. As mentioned by @HovercraftFullOfEels, the earlier comments were simply (restating) the requirement. For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). If there is a solution to be found to a question like *"How to display the pie chart in a label in the **existing** GUI?"* (which is what I **guess** the question might be) it will be suggested in the current code (but make it an MCVE we can work with). – Andrew Thompson Oct 02 '15 at 19:17

1 Answers1

2

It seems in this case that the functionality can be provided by using a ChartPanel instead of the ChartFrame.

  • Create a ChartPanel and add it somewhere in the main top level container (usually a JFrame).
  • When it comes time to update the chart, call ChartPanel.setChart(JFreeChart).
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433