Multiline graphs in java

Multiline graphs in java

How to draw a multiline graph in java, One will b constant straight line and the other is changing
View Answers

March 10, 2010 at 4:01 PM

Hi Friend,

Try the following code:

import java.awt.*;
import org.jfree.ui.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.data.xy.*;
import org.jfree.chart.axis.NumberAxis;

public class MultiLineChart extends ApplicationFrame {
public MultiLineChart(final String title) {
super(title);
final XYDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
}
private XYDataset createDataset() {
final XYSeries series1 = new XYSeries("Test");
series1.add(1.0, 60.0);
series1.add(2.0, 80.0);
series1.add(3.0, 35.0);
series1.add(4.0, 100.0);
series1.add(5.0, 95.0);
series1.add(6.0, 85.0);
series1.add(7.0, 70.0);
series1.add(8.0, 30.0);
series1.add(9.0, 45.0);
series1.add(10.0, 50.0);

final XYSeries series2 = new XYSeries("Max marks to pass the test");
series2.add(1.0, 40.0);
series2.add(2.0, 40.0);
series2.add(3.0, 40.0);
series2.add(4.0, 40.0);
series2.add(5.0, 40.0);
series2.add(6.0, 40.0);
series2.add(7.0, 40.0);
series2.add(8.0, 40.0);
series2.add(9.0, 40.0);
series2.add(10.0, 40.0);

final XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series1);
dataset.addSeries(series2);

return dataset;
}
private JFreeChart createChart(final XYDataset dataset) {
final JFreeChart chart = ChartFactory.createXYLineChart(
"Marks obtained by students in tests",
"Roll No of the students",
"Marks",
dataset,
PlotOrientation.VERTICAL,
true,
true,
false
);
chart.setBackgroundPaint(Color.white);
final XYPlot plot1 = chart.getXYPlot();
plot1.setBackgroundPaint(Color.lightGray);
plot1.setDomainGridlinePaint(Color.white);
plot1.setRangeGridlinePaint(Color.white);

final XYPlot plot2 = chart.getXYPlot();
plot2.setBackgroundPaint(Color.lightGray);
plot2.setDomainGridlinePaint(Color.white);
plot2.setRangeGridlinePaint(Color.white);

final XYPlot plot3 = chart.getXYPlot();
plot3.setBackgroundPaint(Color.lightGray);
plot3.setDomainGridlinePaint(Color.white);
plot3.setRangeGridlinePaint(Color.white);

return chart;
}
public static void main(final String[] args) {
final MultiLineChart demo = new MultiLineChart("Multi Line Chart");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}

Thanks









Related Tutorials/Questions & Answers:
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
Difference between documentation comment and multiline comment in java?
Difference between documentation comment and multiline comment in java?  Difference between documentation comment and multiline comment in java
Advertisements
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
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 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 'multiline-log-formatter'
ModuleNotFoundError: No module named 'multiline-log-formatter'  Hi...: No module named 'multiline-log-formatter' How to remove the ModuleNotFoundError: No module named 'multiline-log-formatter' error? Thanks   
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
java
java  Does java allows multiline comments
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
TextArea Frame in Java
TextArea Frame in Java      ..., we are going to create  TextArea object. TextArea object is a multiline..._TO_REPLACE_1 Description of this program: This java program displays the text area 
Java Comments - Java Tutorials
.style1 { text-decoration: underline; } Comments in Java Comments in Java holds the description or hint about the code or explanations... ignore these comments and do not compile it. Types of comment Java supports
Compiling a Pattern with Multiple Flags
with multiple flags like multiline, case insensitivity of the characters... of the Pattern class which denotes for the multiline characters in the given... with the multiline character which breaks the string after a specific part. Pattern.CASE
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
Java AWT Package Example
Java AWT Package Example       In this section you will learn about the AWT package of the Java... A class library is provided by the Java programming language which is known
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

Ads