Solved

Embed JFreeChart chart in a JPanel

Posted on 2011-09-23
3
799 Views
Last Modified: 2012-05-12
Please let me know how I can embed a JFreeChart in a JPanel. If possible, please provide some sample code.

Thanks!
0
Comment
Question by:dshrenik
  • 3
3 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 36590405


You can use ChartPanel which extends JPanel, like that:

    ApplicationFrame af = new ApplicationFrame("Chart");
  JFreeChart chart = af.createChart(dataset);
         ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(600, 350));
       af. setContentPane(chartPanel);
     af.setVisible(true);

Open in new window


There are lots of examples there
on http://www.java2s.com/Code/Java/Chart/JFreeChartLineChartDemo6.htm
What kind of more code do you want?


0
 
LVL 47

Expert Comment

by:for_yan
ID: 36590419

Download JFreeChart
from here:


http://sourceforge.net/projects/jfreechart/files/1.%20JFreeChart/1.0.13/jfreechart-1.0.13.zip/download

JCommon from here:

http://sourceforge.net/projects/jfreechart/files/3.%20JCommon/1.0.16/jcommon-1.0.16.zip/download

Put them in the classpath of your project

Select the best example you like from that www.java2s.com
site and see how it works.

From that point in many cases it is easy to understand
how to modify it to get your stuff working
 
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36590446
And yes, there may be discrepancy - the examples may use a litytle bit older version is some unlucky cases,
but then wlooking at API and dealing with the particular case it is in most cases possible to figure out
how to change

Look ath the right side picttures in the examples and select something which
is most close to your task at hand
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now