Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Valli
Graphs in java
2 Answer(s)      4 years and 2 months ago
Posted in : Java Beginners


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

Advertisement
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
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
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
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
Introduction to Graphs and Charts
Introduction to Graphs and Charts       Why Charts and GraphsGraphs... difficult and tedious process. All forms of Graphs and Charts embodies some Visual
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
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
jgraph
; Jgraph is open source software for drawing graphs and structured drawings. Jgraph is written in Java Programming language. Jgraph was started by Gaudenz Alder in 2000 and first released in 2001.   JGraph can be used to create graphs
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
java
java  diff bt core java and java
java
java  what is java
Java
Java   Whether Java is pure object oriented Language
JAVA
JAVA  how the name came for java language as "JAVA
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
java
java  is java open source
java
java  what is java reflection
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
java  write a java program using filenotfoundexception
Java
Java  how to draw class diagrams in java
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
java
java  is java purely object oriented language
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
java
java  how use java method
java
java  send me java interview questions
java
java  write a program in java to acess the email
java
java  Write a java code to print "ABABBABCABABBA
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
Advertisements
 

 

 

DMCA.com