Share on Google+Share on Google+

Prajakta S
To display the bar graph
1 Answer(s)      5 years and 3 months ago
Posted in : Java Beginners


I am able to get the output of bar graph. but now i want that to be displayed on my own form. The code which i am having in that the output is displayed in another form, its creating new form but i want to display it in my form only. Means i want it to be displayed on my form that i have created. Can u tell me how to do this???????

Plz help........

I tried to display in label or scroll pane but its giving me error cannot find the method i think its not compatible with this components. Can u plz help????????????


View Answers

December 29, 2011 at 12:43 PM

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.category.*;

public class BarChartExample{
public static void main(String arg[]){
    JButton b=new JButton("Show Graph");
    JFrame f=new JFrame();
    final JLabel l=new JLabel();
    b.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.setValue(72, "Marks", "A");
        dataset.setValue(75, "Marks", "B");
        dataset.setValue(48, "Marks", "C");
        dataset.setValue(98, "Marks", "D");
        dataset.setValue(67, "Marks", "E");
        JFreeChart chart = ChartFactory.createBarChart("BarChart using JFreeChart","Student", "Marks", dataset, 
        PlotOrientation.VERTICAL, false,true, false);
          File f=new File("C:/chart.jpg");
          ChartUtilities.saveChartAsJPEG(f, chart, 400, 300);
          ImageIcon icon=new ImageIcon(f.getPath());
        catch (IOException ex){
          System.out.println("Problem in creating chart.");

Related Tutorials/Questions & Answers:
To display the bar graph
To display the bar graph  hi........ I am able to get the output of bar graph. but now i want that to be displayed on my own form. The code which i... but i want to display it in my form only. Means i want it to be displayed on my
Bar graph
Bar graph  How to include a bar chart in iPhone sdk
Create Bar graph
Create Bar graph  hi............. In my project i want to create a BAR GRAPH to display the result. I HAVE certain values that want to show in graph form. Can u help me plzzzzzzz i require a very simple code in java swings were
datewise/monthwise bar graph
datewise/monthwise bar graph  How to make a datewise/monthwise bar graph using the values from the ms access database? please help its urgent
Read Excel file and generate bar graph
Read Excel file and generate bar graph In this tutorial, you will learn how to read an excel file and generate bar graph. Here is an example that reads... the data of excel file, we have generated a bar chart. The given code uses Apache
Create Bar Graph from reading excel sheet in Java
Create Bar Graph from reading excel sheet in Java  I'm New to Java... and plot a bar graph between browser and test case pass/fail based on the data in the different excel sheets (data can change and based on that graph should also get
Graph  What is the code to generate the following graphs? 1.Simple Bar diagram 2.Sub-divided Bar diagram 3.Pie chart Please Help!!!!   Please visit the following link: Java charts and graphs
Fetching data from excel file on other website and display in interactive graph form
Fetching data from excel file on other website and display in interactive graph form  Hello, I am making a website using HTML and CSS, I am done with the layout, I have to generate ineractive graphs like stock market's, Can you
PHP GD line graph
,'Line Graph by: Roseindia Technologies',$red); imagepng($im); ?> After
, Please visit the following link: Bar Graph in Java Swing Thanks...Graph in JAVA SWING  Hi, How to draw a simple GRAPH in JAVA SWING ?  
Bar Chart
Bar Chart  hi...... Thanks 4 ur help for the bar graph creation i have got what i wanted. But now want to ask that in that bar graph i want multiple bar on one value means I want to create a graph where on my x-axis i have
to show graph
to show graph  by clicking on submit button how to show the graph by fetching data in mysql?   Please visit the following link: JSP graph by fetching data in mysql
line graph
line graph  I have developed an application and in that i have to compare 2 reports using line graph from the data taken from ms access database?please help
Applet Graph
columns-names by using check box and click on graph button, 3..then i have to get a graph between those columns in a applet plz send me the code thank u
about graph - Applet
about graph  How to draw a graph in applet and that should be display in web browser? How to make a running applet in our browser? for example ticker
Autoupdating graph
Autoupdating graph  Hey Anyone who might help me making a XY graph, that autoupdates lets say every 5th minute. All the datasets comes from an mySQL database, and the dataset in the database, comes from a txt file and are being
Create Progress Bar in SWT
Create Progress Bar in SWT   ... Bar. SWT allows to create a Progress bar by providing the class ProgressBar of package org.eclipse.swt.widgets. With the use of this class, you can display
bar chart
bar chart  how to create a bar chart from values of the database and the string value should be the entities of the database??plzz help..needed badly
plot a graph in Java
plot a graph in Java   I need to plot a graph in Java but the samples are not known in advance. The samples keep on coming through callback and I... and the final graph may be quite congested. So please guide me on this. Thanks
Stacked Bar Chart
Stacked Bar Chart  How to display a stacked bar chart using java from the values stored in the ms access database?Plzz help..its urgent
Changing 2D graph using slider.
Changing 2D graph using slider.  Code for changing a 2d graph with help of slider
plotting a graph - Java Beginners
plotting a graph  pls help me out regarding plotting a graph. I have done that through LiveGraph API. but now i required the graph to be displayed on the gui- window. and whatever inputs i will pass it must change the graph
progress bar
progress bar  Hi guys, I'm doing a file upload in spring MVC technology. For file upload i did validation in client side.While uploading how to use an ajax function to show the progress bar
Progress Bar
Progress Bar  Hi friend, I'm interested in knowing how to progress bar in oracle forms 9i for the trigger when-button-pressed.Thankyou. Thanks and Regards, M.SHANKAR
hybrid graph (jfree chart) - Swing AWT
hybrid graph (jfree chart)  hello i have a problem related to jfree chart.I want to display hybrid graph (Stacked Area and Line ).combination.... Thanks.   Hi, Plz what the requirement of hybrid graph
statistical graph in jsp - JSP-Servlet
statistical graph in jsp  how to create a statistical graph to show the highest mark and the lowest mark of a table named test which consist of two... by a graph without hard coding the id's and the scores
Bar chart with J table
tell me how can I make a bar graph that will display the data from my table.I tried using the code from your page ( chart with J table  Hi I'm new in Java and I have a application
radar graph in java
radar graph in java  Hi All I am developing a java application. In this application i need to show a radar grap.when some body assigne rating then each rating should show on x y z axis. please suggest me some good way to do
How to create bar chart using database values
How to create bar chart using database values  How to create bar chart using database values i.e excellent,good,average fields using jsp?It is like... in a graph format
display  please tell me how to display the content from database.. if we click on any image using servlets/jsp...please
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code


Advertisement null