Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8309609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:10:31+00:00 2026-06-08T19:10:31+00:00

I am facing some problems with JFreeChart with Java. I am retriving data from

  • 0

I am facing some problems with JFreeChart with Java.
I am retriving data from remote database to make them display in a Panel from my application.

  1. The problem: when I get the data, it does not display directly on the panel. I have to minimize and maximize the form to make the data being loaded.

  2. I need this data to be refreshing every minute. I was thinking about a Timer but I don’t really know how to integrate it.

Here is part of the code:

import java.io.BufferedReader;
import java.net.Socket;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;
import javax.swing.JPanel;

public class GetRequest implements Runnable{

    public BufferedReader _input = null;
    public Socket clientSocket = null;
    public DrawChart draw;
    public List<Double> values_1, values_2, values_3, values_4;
    public JPanel _panel;

    public GetRequest(Socket socket, JPanel panel){
        clientSocket = socket;
        draw = new DrawChart();
        _panel = panel;
        values_1 = new ArrayList<Double>();
        values_2 = new ArrayList<Double>();
        values_3 = new ArrayList<Double>();
    }

    @Override
    public void run(){
        while(true){

            try{
                _input = new BufferedReader(
                    new InputStreamReader(clientSocket.getInputStream ()));
                String line = _input.readLine ();

                String[] clineComat = line.split (",");
                for(int i = 0 ;i<clineComat.length;i++){

                    String[] clineSemiComa_ = clineComat[i].split (";");
                    System.out.println(">"+clineComat[i]);
                    values_1.add (Double.parseDouble (clineSemiComa_[0])+1);
                    values_2.add (Double.parseDouble (clineSemiComa_[1])+1);
                    values_3.add (Double.parseDouble (clineSemiComa_[2]));
                }

                EventQueue.invokeLater (new Runnable(){
                public void run(){
                    draw.displayPie (_panel, values_1, values_2, values_3);
                }
            });
            }
            catch(IOException e){e.printStackTrace ();}
        }
    }}

and this is the code of the DrawChart.java

import  org.jfree.chart.ChartFactory;
import  org.jfree.chart.ChartPanel;
import  org.jfree.chart.JFreeChart;
import  org.jfree.data.general.DefaultPieDataset;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import org.jfree.chart.plot.PlotOrientation;
import java.awt.Dimension;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.category.CategoryDataset;
import java.util.List;
import java.lang.Float;
import java.util.Timer;
import java.util.TimerTask;

public class DrawChart {

    public void displayPie(JPanel jpanel, List<Double> values_1, List<Double> values_2, List<Double> values_3) {

        CategoryDataset data = createDataset(values_1, values_2, values_3);
        //create a chart...
        JFreeChart chart=ChartFactory.createBarChart ("", null, null, data, PlotOrientation.VERTICAL, true, true, false);
        chart = ChartFactory.createLineChart ("", null, null, data, PlotOrientation.VERTICAL, true, true, false);

        //create and display a frame...
        ChartPanel panel=new ChartPanel(chart);
        panel.setPreferredSize (new Dimension(700,300));
        jpanel.setLayout(new java.awt.BorderLayout());
        jpanel.add (panel, BorderLayout.CENTER);
        jpanel.setVisible(true);
        }

    public static CategoryDataset createDataset(List<Double> a, List<Double> b, List<Double> c) {

        String series1 = "Series1";
        String series2 = "Series2";
        String series3 = "Series3";

        final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        if(a.size () != 0 && b.size () != 0 && c.size () != 0 ) {

            for(int i=0;i<a.size ();i++) {
                dataset.addValue(a.get (i), series1, i+1+"");
            }

            for(int i=0;i<b.size ();i++) {
                dataset.addValue(b.get (i), series2, i+1+"");
            }

            for(int i=0;i<c.size ();i++) {
                dataset.addValue(c.get (i), series3, i+1+"");
            }

        }

        return dataset;
    }
}

How can I solve this ? Does anyone has done a similar ?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:10:33+00:00Added an answer on June 8, 2026 at 7:10 pm

    I may be overlooking a JFreeChart problem, but drawing in Swing must occur on the event dispatch thread. In contrast, your call to displayPie() occurs from an anonymous Runnable in GetRequest. Common remedies include these:

    • EventQueue.invokeLater, illustrated here.

    • SwingWorker, illustrated here.

    • javax.swing.Timer for periodic updates, illustrated here and here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm facing some problems with my silverlight application. My application looks like an image
I'm creating a application using entity framework code-first and i'm facing some problems with
I'm facing some problems with java classes. Here is a class I defined public
We have an WCF application which uses NHibernate to query data from the database.
I am facing some problems, that is, In my application the gamecenter works fine
I am developing android push notification application using C2DM,I am facing some problems in
I'm developing an IM application using Smack library, and I'm facing some problems. I'd
I am facing some weird problems. Whenever I scroll my table view, my data
I've moved from iOS applications development to android so I'm facing some problems finding
I am facing some unusual problems migrating my application to work in IPv6 environments.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.