Share on Google+Share on Google+

Dedeepya
Graphs using JFreeChart
1 Answer(s)      7 years ago
Posted in : Java Beginners
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

Ads

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
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
Advertisements
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
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
jfreechart
jfreechart  hi how install jfreechart? and how free download jcommon? plz insert link for this? thanks   Hi Friend, Please visit the following link: Download JFreechart Download jfreechart-1.0.13.zip from the given
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
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
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
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
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
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
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
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
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
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
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
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
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
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... and download the jfreechart api: http://www.brothersoft.com/jfreechart
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/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
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
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
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
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads