Line Graphs in java

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 the points...
I need to get the values also at the specific point in the chart..
and it should be only xyline graph and the values should be in the chart itself...
Is there any way to solve this..??
can anyone help...


Thanks in advance
View Answers

May 28, 2010 at 11:49 AM

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.createLineChart("Test", "Id", "Score",
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.");
}
}
}

Thanks









Related Tutorials/Questions & Answers:
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
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...;The Above code is good... But i need a line graph with the data values
Advertisements
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
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... String[] args) { final MultiLineChart demo = new MultiLineChart("Multi Line
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
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
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
java - read file line by line in Java
java - read file line by line in Java  Hi, how one can read a text file line by line in Java? What is the benefits of reading a file line by line... file in Java can be read line by line with the help of BufferedReader class
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
Java - How to read a string line per line
Java - How to read a string line per line  Java - How to read... to read the big String line per line? Is there any API available in Java...(System.getProperty("line.separator")); Read more at: Java Read File Line
Java Command Line Input
Java Command Line Input  How to get input from command line in java ?   Hi please Find the code for inputting data from the command line System.out.println("Please Input A Number"); BufferedReader br
java line chart
java line chart  Hi, I want to draw a graphic in java line chart and ? searched the documents ?n the web. I found the example codes ?n your site (http://www.roseindia.net/chartgraphs/xyline-chart.shtml) and tr?ed ?n my
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
Java Read File Line by Line - Java Tutorial
Java Read File Line by Line - Example code of reading the text file in Java one line at a time     ... to write java program to read file line by line. We will use the DataInputStream
How to read big file line by line in java?
Learn how to write a program in java for reading big text file line by line... is very useful in reading big file line by line in Java. In this tutorial we... is complete example of java program that reads big text file line by line
Types of Graphs and Charts
applications charts and graphs are extensively used for visualizing the data. In Java.... Line graphs: A line graph is a way of representing two pieces of information... Types of Graphs and Charts   
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
Read file line by line in Java 8
Java 8 Read file - Reading file line by line in Java 8 Today  we will discuss the new API which is added to Java 8 for reading a file line by line..._TO_REPLACE_4 Examples of reading a file line by line in Java 8 Following is example
Java read file line by line - Java Tutorial
C:\nisha>javac ReadFile.java C:\nisha>java... input line by line with an appropriate BufferedReader.ADS_TO_REPLACE_1...;File Line By Line   while ((strLine = 
How to read a large text file line by line in java?
How to read a large text file line by line in java?  I have been... you kind advice and let's know how to read a large text file line by line in java... of the application and the memory available for the Java program. For Java program max
How to write file by line in Java
How to write file by line in Java  How to write file by line in Java   Hi, For Write to a file by line using java programming language we... in a new line. How to use Write To File By Line in Java programs
How to Read file line by line in Java program
by line in Java. But there are various ways that can help read a larger file... having less amount of memory. In the example of Java Read line by line below... of read file line by line in Java is printed on console.ADS_TO_REPLACE_5
line length in java - Java Beginners
line length in java  Write a program that asks the user to enter two words. The program then prints out both words on one line. The words will be separated by enough dots so that the total line length is 30  Hi friend
What is command line argument in Java
example of command line argument program in Java?? It will be really helpful... visit the following link: http://www.roseindia.net/java/beginners/cmnd-line...://www.roseindia.net/java/beginners/cmnd-line-arguments.shtml
how to read file line by line using filereader in java
how to read file line by line using filereader in java  Hi, how to read file line by line using filereader in java? Thanks   Hi...))) { String line; while ((line = br.readLine()) != null
Multi line graph - Java Beginners
Multi line graph  Hi, I want a multi line graph on a single chart using jfree in java.... Can you please let me know the code... thanks... MultiLineChart("Multi Line Chart"); demo.pack
command line arguments - Java Beginners
command line arguments  how can i findout the minimum and maximum no's at the command prompt if i give some values?????????  hi friend, We are providing you a code that will prompt the user to input some numbers
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
Java read file line by line
Java read file line by line In this section, you will learn how to read a file line by line. Java has provide several classes for file manipulation. Here we are going to read a file line by line. For reading text from a file it's better
Java write to file line by line
Java write to file line by line In this section, you will learn how to write a file line by line. It is better to use Writer class instead of OutputStream... to a byte array. The method newLine() is used for writing a new line character. We
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
Java Read File Line By Line, Video Tutorial of Java Read File Line By Line
a program in Java programming language to read a text file line by line. The "Java Read File Line by line" is most searched topics by the Java developers. This means Java developers are using the Java for reading the file line
Command line argument in java
Command line argument in java. In this section we are going to discuss about command line argument in java. Command line argument allow a user to pass arguments at the time of running the application , after the class name. Java allow
Java Generic program with command line argument
Java Generic program with command line argument  Implement Generic to perform arithmetic evaluation using command line argument by using Java
Draw a line in a JPanel with button click in Java
Draw a line in a JPanel with button click in Java  Draw a line in a JPanel with button click in Java
Command Line Arguments in Java
Command Line Arguments in Java The ongoing Java application can accept any...-line argument is an argument, which passed at the time of running of the Java... /** * How to use command line arguments in java program. */ class CmndLineArguments
How to pass command line arguments in Java?
How to pass command line arguments in Java?  Hi, In a Java program I have to write for reading the command line arguments and use it in a programming. How to pass command line arguments in Java? Share me the sample code
Java memory options from command line
Java memory options from command line  Hi, How to use java memory options from command line? Thanks   Hi, Here is the example code: java -Xms1056m -Xmx1056m MyProgram Thanks
Command Line Standard Output In Java
Command Line Standard Output In Java In this section we will discuss about the Command Line Java IO Standard Output. Standard streams, feature of various O/S, are written through standard output in Java. Standard streams can
How to delete line starting with a letter in java Regex?
How to delete line starting with a letter in java Regex?  Hi, i 'm trying to code with regex and java. i want to know how it's possible to delete lines which starts with a letter like G or g in a text. i tried
Command Line Standard Error In Java
Command Line Standard Error In Java In this section we will discuss about the Command Line Java IO Standard Error. System.out and System.err both... is provided by Java for printing of error messages. System.errADS_TO_REPLACE_1
Line Animation in Java
Line Animation in Java       In this example we are creating an animated line. The color of  line is changing alternatively. We use drawLine() to draw a line

Ads