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 8367239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:06:35+00:00 2026-06-09T13:06:35+00:00

I’m currently working with time-series data and I’m using JFreeCharts XYLineChart to display my

  • 0

I’m currently working with time-series data and I’m using JFreeCharts XYLineChart to display my data. For my user interface I want to create click-able thumbnails of these charts (which then show the real big Chart).

I tried this method to create a thumbnail of the chart, but I don’t know how I can use this BufferedImage to display the thumbnail.

XYSeriesCollection coll = new XYSeriesCollection();
coll.addSeries(rw.getT1().getCurMktCapSeries());
coll.addSeries(rw.getT2().getCurMktCapSeries());            
JFreeChart chart = ChartFactory.createXYLineChart(rw.getT1().getName() + " - " + rw.getT2().getName(),
                                            "Position",
                                            "Course",
                                            coll,
                                            PlotOrientation.VERTICAL,
                                            true,
                                            true,
                                            false);
    
BufferedImage bi = chart.createBufferedImage(1000, 1000, 100, 100, null);

I tried searching online, but the only thing I found was the method above to create a thumbnail, not how to display it.

So my question are:

  • Is this the right way to create a thumbnail?
  • How can I display this thumbnail on my GUI?

Solution

I just created my own custom JPanel

public class ImagePanel extends JPanel

and then I added the following paintComponent method to draw the thumbnail

protected void paintComponent(Graphics g) {
    super.paintComponents(g);
    //Create Image
    BufferedImage bi = this.createBufferedImage(this.rw);
    //Draw Background
    Graphics2D g2d = (Graphics2D)g;
    g2d.setColor(this.backgroundColor);
    g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
    //Draw Image
    g2d.drawImage(bi.getScaledInstance(this.getWidth()-10, this.getHeight()-10, 0), 5, 5, this.backgroundColor, null);
}

To create the BufferedImage I used the following method

private BufferedImage createBufferedImage(ResultWrapper rw2) {
    //Create JFreeChart
    XYSeriesCollection coll = new XYSeriesCollection();
    coll.addSeries(rw.getT1().getCurMktCapSeries());
    coll.addSeries(rw.getT2().getCurMktCapSeries());            
    JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, coll, PlotOrientation.VERTICAL, false, true, false);
    
    //Hide Axis
    XYPlot plot = chart.getXYPlot();
    plot.getRangeAxis().setVisible(false);
    plot.getDomainAxis().setVisible(false);
    
    return chart.createBufferedImage(500, 500, 100, 100, null);
}

With that I got exactly what I wanted, little thumbnails of a JFreeChart. To make it clickable, just add a MouseListener.

Thanks @MadProgrammer for using a custom component and the paintComponent method

  • 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-09T13:06:36+00:00Added an answer on June 9, 2026 at 1:06 pm

    Ontop of AndrewThompon’s suggestions, you could provide a custom Component that has the ability to paint the chart.

    Take a look at

    • Performing Custom Painting in Swing
    • Java Graphcs2D

    This is by far more involved then has already been suggested, but does provide you with the greatest of flexibility

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I want to construct a data frame in an Rcpp function, but when I
i want to parse a xhtml file and display in UITableView. what is the
I am using jsonparser to parse data and images obtained from json response. When
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to understand how to use SyndicationItem to display feed which is
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.