Solved

Embed JFreeChart chart in a JPanel

Posted on 2011-09-23
3
816 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

695 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