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

  • SEARCH
  • Home
  • 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 8353185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:11:02+00:00 2026-06-09T09:11:02+00:00

I have a problem displaying a line on a chart. I have a JFreeChart

  • 0

I have a problem displaying a line on a chart. I have a JFreeChart and if I use paintComponent() as below, I see the line but not the chart. Thanks in advance for any help.

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.data.general.SeriesException;
import org.jfree.data.time.*;
import org.jfree.data.xy.XYDataset;

public class TestChartPanel extends JPanel {

    private static XYDataset createDataset() {

        final TimeSeries series = new TimeSeries("Random Data");
        Day current = new Day(1, 1, 1990);
        double value = 100.0;
        for (int i = 0; i < 4000; i++) {
            try {
                value = value + Math.random() - 0.5;
                series.add(current, new Double(value));
                current = (Day) current.next();
            } catch (SeriesException e) {
                System.err.println("Error adding to series");
            }
        }
        return new TimeSeriesCollection(series);
    }

    private static JFreeChart createChart(final XYDataset dataset) {
        JFreeChart chart = ChartFactory.createTimeSeriesChart(
            "Test",
            "Day",
            "Value",
            dataset,
            false,
            false,
            false);
        return chart;
    }

    /**
    * @param args
    */
    public static void main(String[] args) {

        JFrame f = new JFrame();
        XYDataset xyd = createDataset();
        JFreeChart jfc = createChart(xyd);
        ChartPanel cPanel = new ChartPanel(jfc) {

            /**
            *
            */
            private static final long serialVersionUID = 1L;

            public void paintComponent(Graphics g) {
                super.paintComponents(g);

                System.out.println("paooooooooooooooooooooooo");
                g.setColor(Color.RED);

                g.drawLine(100, 100, 200, 200);
            }
        };
        JPanel jp = new JPanel();
        jp.add(cPanel);
        f.getContentPane().add(jp);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.pack();
        f.setVisible(true);
    }
}

**I think I do smthg wrong with the JFrame and JPanel but can’t figure my mistake; full code posted.

  • 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-09T09:11:03+00:00Added an answer on June 9, 2026 at 9:11 am

    Your override of paintComponent() should invoke

    super.paintComponent(g);
    

    not

    super.paintComponents(g);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem in displaying drop-down menu. Please, see the example on: http://staging.gwynconsulting.com/rif/hello-world-2/ When
I have a problem with propertygrid not displaying the parent value of an expandable
I have problem with displaying adsense ads in ie7 google adsense adds an iframe
I have a problem displaying non- ASCII characters in Matplotlib, these characters are rendered
I have a problem displaying zebra list after filtering results. I have a zebra
I'm generating dynamic HTML inside Delphi. I have no problem displaying UTF-8 strings inside
I have some problem with displaying emoji icon in Android TextView First, I found
I have a problem consistently displaying Facebook Comments on my AJAX driven website. Each
I have a WPF chart currently displaying an Area series. I need to allow
I have a line chart that sometimes contains a number of data points. I

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.