Graphs using JFreeChart

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 200

Max power ------400

How can i do this
Any help is appreciated...

Thanks in advance
View Answers

March 22, 2010 at 4:44 PM

Hi Friend,

Try the following code:

import java.awt.*;
import java.text.*;
import javax.swing.*;

import org.jfree.chart.*;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.*;
import org.jfree.data.time.*;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.*;


public class LineChart extends ApplicationFrame {

public LineChart(String title) {
super(title);
TimeSeries s1 = new TimeSeries("Power", Day.class);
s1.add(new Day(15,12, 2009), 150);
s1.add(new Day(16,12, 2009), 200);
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(s1);
dataset.setDomainIsPointsInTime(true);

JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Power consumed by a consumer in specific date",
"Date",
"Power",
dataset,
true,
true,
false
);
ChartPanel chartPanel = new ChartPanel(chart, false);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
chartPanel.setMouseZoomable(true, false);
setContentPane(chartPanel);
XYPlot plot = (XYPlot) chart.getPlot();
XYItemRenderer r = plot.getRenderer();
if (r instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
}

DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy"));
}
public static void main(String[]args){
LineChart chart = new LineChart("Chart");
chart.pack();
chart.setVisible(true);

}

}

For more information, visit the following link:

http://www.roseindia.net/chartgraphs/index.shtml

Thanks









Related Tutorials/Questions & Answers:
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...(); dataset.addSeries(s1); dataset.setDomainIsPointsInTime(true); JFreeChart
Line Graph using JFreeChart
Line Graph using JFreeChart  I need to draw a line graph of the (no. of sales made on y axis) by a shop with (dates on x axis) using data from MySQL database and JFreeChart
Advertisements
Line Graph using JFreeChart
Line Graph using JFreeChart  I need to draw a line graph of the (no. of sales made on y axis) by a shop with (dates on x axis) using data from MySQL database and JFreeChart. DRIVER: com.mysql.jdbc.Driver URL: jdbc:mysql
Line Graph using JFreeChart
Line Graph using JFreeChart  I need to draw a line graph of the (no. of sales made on y axis) by a shop with (dates on x axis) using data from MySQL database and JFreeChart. DRIVER: com.mysql.jdbc.Driver URL: jdbc:mysql
Using JFreeChart to display recent changes in a time series
Using JFreeChart to display recent changes in a time series  Using JFreeChart to display recent changes in a time series
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
JFreeChart Tutorial
for generating dynamic graphs from Java based applications. The JFreeChart... JFreeChart  quickly and fast. We are giving many examples of using JFreeChart... Chart - JFreeChart provides a way to create various charts by just using
Create Histogram using Jfreechart
Create Histogram using Jfreechart In this section, you will learn how to create histogram using jfreechart. To create a Histogram, we have used... of ten randomly generated numbers to the dataset, using the specified number
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
Stacked Bar Chart using JFreeChart
Stacked Bar Chart using JFreeChart   ... bar chart using JFreeChart. In the code given below we have extended class... of ApplicationFrame class by using super keyword that will be name
jfreechart
jfreechart  hi how install jfreechart? and how free download jcommon? plz insert link for this? thanks   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 Download JFreechart Download jfreechart-1.0.13.zip
Create a polar chart using JFreeChart
Create a polar chart using JFreeChart  ... a polar chart using JFreeChart. Code given below creates a simple polar chart... of ApplicationFrame class by using super keyword that will be name of the created frame
graph generation using jfreechart and retrieving values from the database
graph generation using jfreechart and retrieving values from the database ... database using prepared statement and then display the bar graph using jfreechart API .This whole retrieval and display of chart is to be done in a servlet
how to show value and percentage in piechart sections from database using jfreechart
how to show value and percentage in piechart sections from database using jfreechart  Hii Sir, I made a pie chart from database using... Method /** * This method creates a test pie chart using internally
Stacked Bar Chart Example using JFreeChart
Stacked Bar Chart Example using JFreeChart... a Stacked bar chart using JFreeChart. Bar chart will represent scores of two team... class by using super keyword that will be name of the created frame. Some
Chart & Graphs Tutorials in Java
. The Following examples have been created by using JFreeChart API's. Pie...;  Bar Chart Example using JFreeChart This Example shows you how to create a bar chart using JFreeChart.    Horizontal Bar Chart
Category Step Chart Example using JFreeChart
Category Step Chart Example using JFreeChart... a category step chart using JFreeChart. Code of the chart shows you run rate... to the constructor of ApplicationFrame class by using super keyword that will be name
Combined Category Plot Example using JFreeChart
Combined Category Plot Example using JFreeChart... to create a Combined Category Plot chart using JFreeChart. Code for the chart shows... to the constructor of ApplicationFrame class by using super keyword that will be name
Horizontal Bar Chart Example using JFreeChart
Horizontal Bar Chart Example using JFreeChart... a Horizontal bar chart using JFreeChart. This example showing you match... value to the constructor of ApplicationFrame class by using super keyword
Stacked 3d Bar Chart Example using JFreeChart
Stacked 3d Bar Chart Example using JFreeChart... a Stacked 3d bar chart using JFreeChart. Bar chart will represent the score... to the constructor of ApplicationFrame class by using super keyword that will be name
Box And Whisker Chart Example using JFreeChart
Box And Whisker Chart Example using JFreeChart... to create a box and whisker chart using JFreeChart. Code of the chart given below... to the constructor of ApplicationFrame class by using super keyword that will be name
Create a pie chart in jsp page using JFreeChart
Create a pie chart in jsp page using JFreeChart... to create a pie chart in jsp page using JFreeChart. Code given below creates... to the constructor of ApplicationFrame class by using super keyword that will be name
Candle Stick Chart Example using JFreeChart
Candle Stick Chart Example using JFreeChart... a candle stick chart using JFreeChart. Code of the chart given below shows... to the constructor of ApplicationFrame class by using super keyword
Create a dual axis chart using JFreeChart
Create a dual axis chart using JFreeChart  ... a dual axis chart using JFreeChart. Code given below creates a simple dual axis... of ApplicationFrame class by using super keyword that will be name of the created frame
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...); JFreeChart chart = ChartFactory.createBarChart
Version of jfreechart>jfreechart dependency
List of Version of jfreechart>jfreechart dependency
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
Create a bar chart in JSP page using JFreeChart
Create a bar chart in JSP page using JFreeChart... to create a bar chart in JSP page using JFreeChart. Code given below creates a bar chart... to the constructor of ApplicationFrame class by using super keyword
graphs/charts - JSP-Servlet
graphs/charts  hi frens, How to create a bar graph by reading... used jfreechart library to create a bar graph. And the chart displays...: http://www.roseindia.net/chartgraphs/jfreechart-introduction.shtml Here
Create area chart in JSP page using JFreeChart
Create area chart in JSP page using JFreeChart... to create a area chart in JSP page using JFreeChart. Code given below creates a area... value to the constructor of ApplicationFrame class by using super keyword
Create multiple pie chart in single frame using JFreeChart
Create multiple pie chart in single frame using JFreeChart... you how to create a multiple pie charts in a single frame in jsp page using JFreeChart. Code given below creates a simple pie charts for given values
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...", "root"); dataset.executeQuery(query); JFreeChart chart
how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)
how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)  I have created a servlet.In this,i...-axis and marks1,marks2,marks3,marks4 on y-axis) using JFREECHART.how can i do
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..."); dataset.executeQuery( query); JFreeChart chart = ChartFactory .createBarChart3D( "Test", "Id
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 - Struts
Graphs  Hi,I have an application developed using struts framework.Now the requirement is for displaying graph in it.Can anyone help me with some code or any suggestion ASAP?  If your looking for freeware and quick
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
Error in JfreeChart
Error in JfreeChart  I am getting an error when i am using jfreechart... the following link and download the jfreechart api:ADS_TO_REPLACE_2 http://www.brothersoft.com/jfreechart-download-15712.html Then extract the api and put
Create a 3D bar chart in JSP page using JFreeChart
Create a 3D bar chart in JSP page using JFreeChart... to create a 3D bar chart in jsp page using JFreeChart. Code given below creates a bar... value to the constructor of ApplicationFrame class by using super keyword
Bar Chart Example using JFreeChart
Bar Chart Example using JFreeChart   ... chart using JFreeChart. Code given below creates a bar chart of scores of two teams... to the constructor of ApplicationFrame class by using super keyword that will be name
Introduction to Graphs and Charts
Introduction to Graphs and Charts       Why Charts and GraphsGraphs.... Using this form of representation helps it's viewers to understand and interpret
Multiline graphs in java - Java Beginners
Multiline graphs in java  How to draw a multiline graph in java, One... JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new...); return dataset; } private JFreeChart createChart(final
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
Error in JfreeChart
Error in JfreeChart  I am getting an error when i am using jfreechart for graph generation, that is: D:\my\linechart.java:5: package org.jfree.chart does not exist import org.jfree.chart.*;ADS_TO_REPLACE_1 what is the reason
JFreechart & JCommon
JFreechart & JCommon   hi........... thanks a lot. The code is running successfully and able to get the output. Thanks once again
Artifacts of jfreechart
List of Artifacts of jfreechart maven depenency
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
Jfreechart zoomin and zoomout - Framework
Jfreechart zoomin and zoomout  how to zoomin and zoom out chart using button plus and minus or slide bar in jFree chart

Ads