Home Answers Viewqa Java-Beginners Making XY line chart with string and double axis

 
 


Frank Kofoed Myhre
Making XY line chart with string and double axis
2 Answer(s)      a year and 2 months ago
Posted in : Java Beginners

Good evening everybody

So i'm trying to make a XYLine chart with JFreechart. The data comes from 2 arraylist, so a for-loop should do the trick parsing the values into the dataset. The horizontal axis are going to be represented by a string (showing day and time) and the vertical indicates temperature (double)

Now my question is what do i do now, i've searched for several examples, i've tried different kind of dataset (different kind of XY collections) and I can't get any thing to work!

Does anybody know a way to make this work?

Frank

View Answers

March 1, 2012 at 5:37 PM


import java.io.File;
import java.io.IOException;
import java.util.Date;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

public class XYJfreechart {

   public static void main(String args []){

        TimeSeries series = new TimeSeries( "", Day.class );
        series.add(new Day(new Date("2012/03/01")), 50);
        series.add(new Day(new Date("2012/03/02")), 40);
        series.add(new Day(new Date("2012/03/03")), 30);
        series.add(new Day(new Date("2012/03/04")), 35);
        series.add(new Day(new Date("2012/03/05")), 20);
        series.add(new Day(new Date("2012/03/06")), 25);
        series.add(new Day(new Date("2012/03/07")), 32);

        TimeSeriesCollection dataset=new TimeSeriesCollection();
        dataset.addSeries(series);

        JFreeChart chart = ChartFactory.createTimeSeriesChart
        ("User Participation Chart",    
         "Day",                    
         "Temperature",            
         dataset,               
         true,                     
         true,              
         false              
        );

      try {
            ChartUtilities.saveChartAsJPEG(new File("c:/chart.jpg"), chart, 800, 600);
            System.out.println("Chart is created successfully.");
           } catch (IOException e) {
            e.printStackTrace();
            System.err.println("Problem occurred creating chart.");
        }
    }
}

March 1, 2012 at 7:18 PM


Okay, I tried to make it work, but it just leaves me with a bunch of error messages. The JPanel looks like this:

    print("private JPanel createGraphArea() throws ClassNotFoundException, FileNotFoundException, IOException, ParseException {

        JPanel graph = new JPanel();
        graph.setLayout(new java.awt.BorderLayout());

        ArrayList<Double> graphtemperature = new ArrayList<Double>();
        ArrayList<Date> clockset = new ArrayList<Date>();
        SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        for (int i = 0; i < data.size(); i++) {
            String sp = data.get(i);
            String[] tokens = sp.split("\t");
            if (tokens.length == 2) {
                Date date = dt.parse(tokens[0]);
                clockset.add(date);
                graphtemperature.add(Double.parseDouble(tokens[1]));
            }

        }
        TimeSeries series = new TimeSeries("",Day.class);
        for(int i = 0; i < data.size(); i++){
            series.add(new Day(clockset.get(i)), graphtemperature.get(i));
        }

        TimeSeriesCollection dataset = new TimeSeriesCollection();
        dataset.addSeries(series);

        JFreeChart chart = ChartFactory.createTimeSeriesChart(null, 
                "Time", 
                "Temperature", 
                dataset, 
                true, 
                true,
                false);

        ChartPanel CP = new ChartPanel(chart);
        graph.add(CP, BorderLayout.CENTER);
        graph.validate();*/

        return graph;
    }");

And the error messages:

    print("Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/date/MonthConstants
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Caused by: java.lang.ClassNotFoundException: org.jfree.date.MonthConstants
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 12 more
Java Result: 1");

Somehow I think the error is at Day.class?









Related Pages:
Making XY line chart with string and double axis
Making XY line chart with string and double axis  Good evening everybody So i'm trying to make a XYLine chart with JFreechart. The data comes from 2... into the dataset. The horizontal axis are going to be represented by a string (showing day
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 chart for a match. In the code given below we have extended class
Line Drawing - Swing AWT
Line Drawing  How to Draw Line using Java Swings in Graph chart,by giving x & Y axis values  Hi friend, i am sending code of draw line...; public class DrowLine { public static void main(String[] args
Chart Axis Class in Flex4
Chart Axis Class in Flex4: The Axis class is used for set of values... types of axes. 1. CategoryAxis: Category axis is used for a set of values state name, month name etc to the axis. The tag of Category Axis is <mx
JFreechart multi line chart help in JSP
JFreechart multi line chart help in JSP  Hi, I am am looking for and help in getting multi line chart with Jfree chart, i had manage to write a singe line chart but i need multy line can you please help. <%@page
Conversion from String to double
Conversion from String to double: In this tutorial we will learn how to convert a string type data to double type data. Description: This program will take a String value from mystring variable. The line double mydouble
string to double
string to double   So I have an assignment where we have to convert..., parseDouble() method takes a String as input and converts it into a double when possible and returns it. If the string cannot be converted into a positive double
Conversion from double to String
the double type value from console. The line String mystring = Double.toString...Conversion from double to String: In this tutorial we will learn how to convert a double type value to String type value. Description: This program
java line chart
java line chart  Hi, I want to draw a graphic in java line chart and ? searched the documents ?n the web. I found the example codes ?n your site (http://www.roseindia.net/chartgraphs/xyline-chart.shtml) and tr?ed ?n my
line chart from database in jsp
line chart from database in jsp  how can i create line chart from database in jsp code
flow chart
java.util.*; public class StudentMarks{ double totalMarks; String grade; public void setTotalMarks(double totalMarks){ this.totalMarks=totalMarks; } public double getTotalMarks(){ return totalMarks; } public void setGrade
flow chart
java.util.*; public class StudentMarks{ double totalMarks; String grade; public void setTotalMarks(double totalMarks){ this.totalMarks=totalMarks; } public double getTotalMarks(){ return totalMarks; } public void setGrade
converting string to double in java
converting string to double in java  Please post an example to converting string to double in java. Thanks!   Convert String to Double Tutorial
Stacked Bar Chart Example using JFreeChart
to create stacked bar chart for given values. It  takes title, domain axis... Stacked Bar Chart Example using JFreeChart... a Stacked bar chart using JFreeChart. Bar chart will represent scores of two team
How to convert String double quotos to String double double quotes(
How to convert String double quotos to String double double quotes(  Hi How to convert String double quotos to String double double quotes("----->"") By replace? Problem is: String column is "Age is 60" now . whenver
how to show x axis values of timeline chart in jfreechart with particular month.
how to show x axis values of timeline chart in jfreechart with particular month.  my x-axix timeline having day of 1 month and days shows me only differently and 1 month. I want month attached with days
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... extended class ApplicationFrame to create a frame and also pass a string value
hybrid chart(Stacked Area and Line ) - Swing AWT
hybrid chart(Stacked Area and Line )  hello i have a problem... different chart stacked area chart and line chart both in a single frame. That is hybrid combination of stacked areachart and line chart in one frame. I want
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... class ApplicationFrame to create a frame and also pass a string value
Create a pie chart in jsp page using JFreeChart
is used to create bar chart for given values. It takes title, category axis label... Create a pie chart in jsp page using JFreeChart... to create a pie chart in jsp page using JFreeChart. Code given below creates
Bar Chart in Java
chart in Java. To draw a bar chart, the variables minvalue, maxvalue of double type... of bar chart: double scale = (clientHeight - top - bottom) / (maxValue...;{   private double[] value;   private String
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... extended class ApplicationFrame to create a frame and also pass a string value
Pie Chart - Java Beginners
ChartPanel extends JPanel { private double[] values; private String[] names; private String title; public ChartPanel(double[] v, String[] n, String t... = new double[6]; String[] names = new String[6]; values[0] = 1
Removing Line Termination Characters from a String
Removing Line Termination Characters from a String... is mentioned by the user and replacing all the new line character by the double quote... the string as output in the console, you will understand where the new line
Bar chart with J table
Bar chart with J table  Hi I'm new in Java and I have a application... { Vector data; Vector columns; public InsertFileDataToJTable() { String line; data = new Vector(); columns = new Vector(); columns.addElement
Chart Series Class in Flex4
Chart Series Class in Flex4: The chart series classes are used for render a data in a chart control. The series classes are used... chart type has a its own series class. for example, Bubble chart has
WEBSERVICE USING APACHE AXIS - TUTORIAL-2 AXIS FOR EJB-WEBSERVICE (part-5)
WEBSERVICE USING APACHE AXIS - TUTORIAL-2 AXIS FOR EJB-WEBSERVICE ... on exposing an EJB as XML-Webservice using Axis. This is a 7 part article.  ...-in-deployment in Axis  part-4 : deloyment using wsdd for javabean. 
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 chart of runs of two teams in different matches. In the code given below we
AXIS ATTACHMENT MISSING - WebSevices
AXIS ATTACHMENT MISSING  Hi, i have a method which takes a filename...: public String getFile(String fname) throws java.rmi.RemoteException { String ret = "GET FILE CALLED"; try
Conversion from short to double
a short type value from console and provides a conversion to double type. The line... data from console. The line double mydouble = myshort; is used to convert...Conversion from short to double: In this tutorial we will learn how to convert
Horizontal Bar Chart Example using JFreeChart
Horizontal Bar Chart Example using JFreeChart... a Horizontal bar chart using JFreeChart. This example showing you match... have extended class ApplicationFrame to create a frame and also pass a string
Chart & Graphs Tutorials in Java
chart for the given values.   Create a dual axis chart using JFreeChart This Example shows you how to create a dual axis chart using JFreeChart. Code given below creates a simple dual axis chart for a match
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... class ApplicationFrame to create a frame and also pass a string value
Conversion from int to double
to double type data. The line int a = Integer.parseInt(buffreader.readLine()); is used to read the int value from console and stored in a variable. The line double...Conversion from int to double: In this tutorial we will learn how to convert
Conversion from double to int
Conversion from double to int: In this tutorial we will learn how to convert a double type value to int type value. Description: This program will take a double value from console and provide the conversion to int type. The line
Conversion from double to short
. The line double mydouble = Double.parseDouble(buffreader.readLine()); reads the double type value from console. The line short myshort = (short)(mydouble...Conversion from double to short: In this tutorial we will learn how to convert
Conversion from double to long
Conversion from double to long: In this tutorial we will learn how to convert a double type value to long type value. Description: This program will take a double value from console and provide the conversion to long type. The line
Conversion from double to float
. The line double mydouble = Double.parseDouble(buffreader.readLine()); reads the double type value from console. The line float myfloat = (float)(mydouble...Conversion from double to float: In this tutorial we will learn how to convert
Conversion from double to byte
Conversion from double to byte: In this tutorial we will learn how to convert a double type value to byte type value. Description: This program will take a double value from console and provide the conversion to byte type. The line
Conversion from double to char
Conversion from double to char: In this tutorial we will learn how to convert a double type value to char type value. Description: This program will take a double value from console and provide the conversion to char type. The line
Line Graphs in java - Java Beginners
Chart { public static void main(String[] args) throws Exception { String...Line Graphs in java  Hi... I need to generate a graph by using... that...I'm unable to display the values in the chart. I'm just getting
Conversion from float to double
the float type data from console. The line double mydouble = (double)(myfloat...Conversion from float to double: In this tutorial we will learn how to convert a float type value to double type value. Description: This program
Conversion from double to boolean
. The line double mydouble = Double.parseDouble(buffreader.readLine()); reads the double type value from console. The line boolean myboolean = (mydouble!=0...Conversion from double to boolean: In this tutorial we will learn how
Conversion from byte to double
data from console. The line double mydouble = (double)(mybyte); converts...Conversion from byte to double: In this tutorial we will learn how to convert a byte type value to double type value. Description: This program will take
Conversion from long to double
value from console. The line double mydouble = (double)(mylong); converts...Conversion from long to double: In this tutorial we will learn how to convert a long type value to double type value. Description: This program will take
Convert String To Double
Convert String To Double      ... numeric type string value:" message and it converts into a double... StringToDouble Enter string value: 23 double d = 23.0
How to read big file line by line in java?
. It returns string line. Following is complete example of java program that reads big... BufferedReader(fileReader); String oneLine; //Read file line by line while...Learn how to write a program in java for reading big text file line by line
MultipleAxes in Chart in Flex4
Multiple Axes in Chart in Flex4: When we use different(Unmatched) data in single chart so it will not be possible to represent multiple series in a single chart. For solving this problem we use multiple axes in a single chart
bar chart
bar chart  how to create a bar chart from values of the database and the string value should be the entities of the database??plzz help..needed badly
Java - How to read a string line per line
Java - How to read a string line per line  Java - How to read a string line per line I am trying to find the tutorial for reading the String line per line. I have a String data, which contains many lines. What is the best way

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.