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



Home Answers Viewqa Java-Beginners Graphs using JFreeChart
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Dedeepya
Graphs using JFreeChart
1 Answer(s)      4 years and 7 months 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

Advertisement
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
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
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
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
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
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
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
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
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 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
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
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 - 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
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
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
 

 

 

DMCA.com