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

Ads









Related Tutorials/Questions & Answers:
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
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
Advertisements
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
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
how to convert string to double in java
how to convert string to double in java  Hi, I have String variable with double value in it. how to convert string to double in java? Thanks  ... to convert a String into double. Here is full example code: package net.roseindia
how to convert string to double in java
how to convert string to double in java  Hi, I have String variable with double value in it. how to convert string to double in java? Thanks  ... to convert a String into double. Here is full example code: package net.roseindia
how to convert string to double in java
how to convert string to double in java  Hi, I have String variable with double value in it. how to convert string to double in java? Thanks  ... to convert a String into double. Here is full example code: package net.roseindia
how to convert string to double in java
how to convert string to double in java  Hi, I have String variable with double value in it. how to convert string to double in java? Thanks  ... to convert a String into double. Here is full example code: package net.roseindia
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
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
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
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
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
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
Convert Double To String
Convert Double To String      ...; This section learns you the conversion of double into string. The following program... a variable of double type and convert it into the string form by using toString
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
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
line number in a file of entered string
line number in a file of entered string  when i entered string from console , it should show line number in a file of that string
Determining Potential Line Breaks in a Unicode String
Determining Potential Line Breaks in a Unicode String This section illustrates you how to use the BreakIterator to parse a string on a line break. Parsing... iterators. Here we are going to break a text string  on the basis of line. You
Version of axis>axis dependency
List of Version of axis>axis dependency
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
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
x-axis and y-axis
x-axis and y-axis  hi,, i want to to write a program that display a graph of x-axis and y-xais when i entered the parameters of the function
Version of axis>axis-ant dependency
List of Version of axis>axis-ant dependency
Version of axis>axis-jaxrpc dependency
List of Version of axis>axis-jaxrpc dependency
Version of axis>axis-saaj dependency
List of Version of axis>axis-saaj dependency
Version of axis>axis-schema dependency
List of Version of axis>axis-schema dependency
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
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
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

Ads