To display the bar graph



Share on Google+Share on Google+

Prajakta S
To display the bar graph
1 Answer(s)      5 years and 10 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
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
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 ?  
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
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
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
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
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
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
Version of commons-graph>commons-graph dependency
List of Version of commons-graph>commons-graph dependency
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
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
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
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
display  please tell me how to display the content from database.. if we click on any image using servlets/jsp...please
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
JFreechart Stacked Bar Chart
. In the following example, each bar of the stacked bar graph is divided into two...JFreechart Stacked Bar Chart JFreechart provides a way to create various charts by just using the methods of different classes. You are well aware of bar
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
hide the url in address bar
hide the url in address bar  how i can hide url in address bar????? i... displayed in the address bar? url not visible to endusers please tell me any... username and i dont want to like that?i want to display the answer
Version of com.daedafusion>graph dependency
List of Version of com.daedafusion>graph dependency
Bar chart implementation in PHP
Bar chart implementation in PHP  How to implements reports in bar graphs by using PHP
Progress Bar in Java
; On Execution of the Program code ,The Progress Bar display as follows... Progress Bar in Java       Progress Bar is a component used to show the status of the application


Advertisement null