Graphs in java

Graphs in java

Hi...

I need to generate a graph by using the database values using java
I know about the JFreeChart class...
But by using that...I'm unable to display the values in the chart.
I'm just getting the points...
I need to get the values also at the specific point in the chart..
can anyone help...


Thanks in advance
View Answers

May 27, 2010 at 5:59 PM

Hi Friend,

Try the following code:

import java.sql.*;
import java.io.*;
import org.jfree.ui.*;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.*;
import org.jfree.data.jdbc.JDBCCategoryDataset;

public class Chart {
public static void main(String[] args) throws Exception {

String query = "SELECT * from chart";
JDBCCategoryDataset dataset = new JDBCCategoryDataset(
"jdbc:mysql://localhost:3306/test";,
"com.mysql.jdbc.Driver","root", "root");
dataset.executeQuery(query);
JFreeChart chart =
ChartFactory.createBarChart("Test", "Id", "Marks",
dataset, PlotOrientation.VERTICAL, true, true, false);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
ApplicationFrame f=new ApplicationFrame("Chart");
f.setContentPane(chartPanel);
f.pack();
f.setVisible(true);
try {
ChartUtilities.saveChartAsJPEG(new File("C:/chart.jpg"),
chart,400, 300);
} catch (IOException e) {
System.out.println("Problem in creating chart.");
}
}
}

For the above code, we have created following database table:

CREATE TABLE `chart` (
`id` bigint(40) NOT NULL auto_increment,
`marks` int(40) default NULL,
PRIMARY KEY (`id`)
)
Thanks

May 28, 2010 at 11:18 AM

The Above code is good...

But i need a line graph with the data values in the chart itself..









Related Tutorials/Questions & Answers:
Graphs in java - Java Beginners
Graphs in java  Hi... I need to generate a graph by using the database values using java I know about the JFreeChart class... But by using that...I'm unable to display the values in the chart. I'm just getting the points
Good Looking Java Charts and Graphs
Good Looking Java Charts and Graphs  Is there a java chart library that will generate charts and graphs with the quality of visifire or fusion charts? The JFreeChart graph quality is not professional looking. Unless it can
Advertisements
Line Graphs in java - Java Beginners
Line Graphs in java  Hi... I need to generate a graph by using the database values using java I know about the JFreeChart class... But by using that...I'm unable to display the values in the chart. I'm just getting
Multiline graphs in java - Java Beginners
Multiline graphs in java  How to draw a multiline graph in java, One will b constant straight line and the other is changing  Hi Friend, Try the following code: import java.awt.*; import org.jfree.ui.*; import
Graphs using JFreeChart - Java Beginners
Graphs using JFreeChart  Hi Friend, I need to draw a graph of the powerconsumed by a consumer in specific dates with a const line showing the max power can be consumed. Now My data is like this 15-12-2009 150 16-12-2009
Chart & Graphs Tutorials in Java
Chart & Graphs Tutorials in Java  ... in Java. Our Chart and Graphs tutorials will help learn everything you need to learn about chart and graphs programming in Java. We have provided many examples
thanks deepak for guiding me to draw graphs using org.jfree - Java Beginners
thanks deepak for guiding me to draw graphs using org.jfree  Hi deepak, thanks deepak....... i got the graphs using org.jfree.......... as u said, i set the class path............ thanks mate
ModuleNotFoundError: No module named 'graphs'
ModuleNotFoundError: No module named 'graphs'  Hi, My Python... 'graphs' How to remove the ModuleNotFoundError: No module named 'graphs'... to install padas library. You can install graphs python with following command
graphs in jsp - Java3D
graphs in jsp  i want to present my data from database in graphs how can i present in jsp and servlet.please guide me.thanz in advance
graphs/charts - JSP-Servlet
graphs/charts  hi, How to create a graph/chart in java by reading values from my sql database.   Hi Friend, Try the following code: import java.sql.* ; import java.io.* ; import org.jfree.chart.ChartFactory
Drawing Graphs - Java3D
Drawing Graphs  how to draw graphs using certain parameters  Hi Friend, To draw a graph using JfreeChart library, please visit the following link: http://www.roseindia.net/chartgraphs/index.shtml Here you
ModuleNotFoundError: No module named 'ngram_graphs'
ModuleNotFoundError: No module named 'ngram_graphs'  Hi, My Python... 'ngram_graphs' How to remove the ModuleNotFoundError: No module named 'ngram_graphs' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'tinc-graphs'
ModuleNotFoundError: No module named 'tinc-graphs'  Hi, My Python... 'tinc-graphs' How to remove the ModuleNotFoundError: No module named 'tinc-graphs' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'useful-graphs'
ModuleNotFoundError: No module named 'useful-graphs'  Hi, My... 'useful-graphs' How to remove the ModuleNotFoundError: No module named 'useful-graphs' error? Thanks   Hi, In your python
graphs/charts - JSP-Servlet
graphs/charts  hi frens, How to create a bar graph by reading values from mysql database. Please help me out...   Hi Friend, We have used jfreechart library to create a bar graph. And the chart displays
gremlin query list all graphs
gremlin query list all graphs  Hi, I am trying Gremlin graph query. How to get all the graphs in one query? Thanks   Hi, on the gremlin console run following query: gremlin> g.V() This will list all the graphs
Types of Graphs and Charts
applications charts and graphs are extensively used for visualizing the data. In Java... Types of Graphs and Charts   ... the data and call the few methods to generate the charts or graphs of your
Drawing Graphs - Swing AWT
Drawing Graphs  hi i am doing a small project in java swings . there is a database table having two columns A,B i want to plot a graph to that values in database the graph must be interactive graph
ModuleNotFoundError: No module named 'boolean-cayley-graphs'
ModuleNotFoundError: No module named 'boolean-cayley-graphs'  Hi...: No module named 'boolean-cayley-graphs' How to remove the ModuleNotFoundError: No module named 'boolean-cayley-graphs' error? Thanks   Hi
ModuleNotFoundError: No module named 'Django-Model-Query-Graphs'
ModuleNotFoundError: No module named 'Django-Model-Query-Graphs'  Hi...: No module named 'Django-Model-Query-Graphs' How to remove the ModuleNotFoundError: No module named 'Django-Model-Query-Graphs' error? Thanks  
Introduction to Graphs and Charts
Introduction to Graphs and Charts       Why Charts and GraphsGraphs... difficult and tedious process.ADS_TO_REPLACE_1 All forms of Graphs and Charts
Graphs - Struts
ispace - a scalable dependency visualization system for Java
ispace - a scalable dependency visualization system for Java...-based tool for visualizing, analyzing, and experimentally reorganizing Java dependency graphs. The tool provides a set of simple but flexible means
importing excel file and drawing multiple graphs from one excel file
importing excel file and drawing multiple graphs from one excel file  thanks a lot sir for replying with code for importing excel file and then plotting grph:) it really helped me:):) If you can please help me with one more thing
jgraph
to create graphs for both desktop and server-side Java applications. Technical...; Jgraph is open source software for drawing graphs and structured drawings. Jgraph is written in Java Programming language. Jgraph was started by Gaudenz Alder
How to create charts in Java?
How to create charts in Java?  Is there any example of creating charts and graphs in Java? thanks   Hi, check the tutorial: Chart & Graphs Tutorials in Java Thanks
JFreeChart Tutorial
JFreeChart Tutorials, examples and articles The JFreeChart is Java based library which is used for generating charts and graphs in Java application... for generating dynamic graphs from Java based applications. The JFreeChart
R Tutorial
, generation of visual graphs and scientific research. In the field of data science... and graphs formats R Programming language is popular because:ADS_TO_REPLACE_1... graphs R Programming Online Training Join our online programming training
data structures - Java Beginners
data structures  I have got a project of the subject 'data structures and C++' and the topic is 'types of graphs'. please guide me on this topic and help me finding material of this topic
how to run org.jfree programss - Java Beginners
how to run org.jfree programss  Hi frends, I was trying to run java programs to draw graphs from the link as my frend deepak has given... the above link java programs........ Thanks  Hi Friend, To run
Open Source Charting and Reporting Tools in Java
Open Source Charting and Reporting Tools in Java... of them are given below : JfreeChart: This is a free java library for creating different types of charts and graphs including:    pie charts (2D
Graph
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
Java I/O Object Streams
is used to write the primitive data types and graphs of Java objects...Java I/O Object Streams In this section we will discuss the Java IO Object Streams. To work with the I/O of objects Java provided the support of Object
Which is best Java Spring training institute in Delhi?
Which is best Java Spring training institute in Delhi?  Hello, I.... Which is best Java Spring training institute in Delhi? Thanks   Hi... Java Spring framework training classes. We offer private and group training
combobox updation - Java Beginners
combobox updation  hi, i am using java swing to develop a gui-there are 4 components in the gui: menus,3 comboboxes,buttons and graphs... for more information. http://www.roseindia.net/java/example/java/swing
Value Stack / OGNL
Value Stack / OGNL Object Graph Navigational Language (OGNL) is a open source framework used to get properties from Java Beans. In Struts 2 framework, OGNL... to handle requests.ADS_TO_REPLACE_1 OGNL uses dot notation to navigate object graphs
Doubt Regarding Charts
Doubt Regarding Charts  Hi, Can you please help me out by answering "hoe to include charts in core java code and struts code" thanks in advance... charts and graphs
Including applet in JSF (XHTML)
Including applet in JSF (XHTML)  Hi I want to generate graphs in facelets project. We are using JSF 2.0. We have Perspective for Java to generate graphs. in this project. So, Perspective for Java is providing an applet which i
Fetching data from excel file on other website and display in interactive graph form
with the layout, I have to generate ineractive graphs like stock market's, Can you tell me how will it be possible? Do I need java script? I have a website... pull data data from those and generate graphs out of it? I really need it urgently
Generate RDF file in Java
of "Jena". Jena is a java API to create and manipulate RDF graphs... Generate RDF file in Java       In this example we are going to generate our first RDF
Java store objects in File
Java store objects in File In this section, you will learn how to use the ObjectOutputStream and ObjectInputStream to write and read serialized object... for graphs of objects when used with a FileOutputStream and FileInputStream
Java ObjectOutputStream
the primitive data types and the graphs of Java objects to the output stream. It writes...Java ObjectOutputStream In this tutorial we will discuss about the Java class... the object to the output stream. In this example at first I have created a Java
Java I/O Data Streams
is used to write the primitive data types and graphs of Java objects...Java I/O Data Streams In this tutorial we will discuss the Java I/O Data... as the String values Java provided the support of Data stream. DataInput
Choosing the best programming framework
graphs. i am confused to choose a programming language. ruby, .net (ASP), java
Bar chart implementation in PHP
Bar chart implementation in PHP  How to implements reports in bar graphs by using PHP
Raj Ghat Gandhi Memorial of Delhi
JPA 2.1 Tutorial
of Entity Graphs Using Second-Level Cache with Java Persistence API... of JPA 2.1 The Java Persistence API Version 2.1 or simply JPA 2.1 is part of JEE... for using the data from relational database in Java based applications. The JPA allows
Bar Chart
for same year with parameters) similarly i want bar for 2006 which again has 9 graphs............ java swing code
Plotting equations on a cartesian Plane
of java, and i at the moment of working on a program that takes the input...; import javax.swing.JPanel; import javax.swing.JTextField; public class Graphs...(); JComboBox Topics = new JComboBox(); public Graphs
java
java  diff bt core java and java

Ads