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

Ads









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
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
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
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
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
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
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
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
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
Version of jfreechart>jfreechart dependency
List of Version of jfreechart>jfreechart dependency
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
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
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
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
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

Ads