Solved

Embed JFreeChart chart in a JPanel

Posted on 2011-09-23
3
804 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

914 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

18 Experts available now in Live!

Get 1:1 Help Now