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?









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
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
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
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
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
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
Convert String To Double
Convert String To Double       In this section, we are going to convert a numeric type string value into a double. The double supports big-integer value.  Code Description:ADS
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
Convert Double To String
Convert Double To String      ...; This section learns you the conversion of double into string. The following program... The program  takes a variable of double type and convert it into the string form
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
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
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
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
display combination of a stacked area chart and line chart in one iframe using jfree - JSP-Servlet
display combination of a stacked area chart and line chart in one iframe using jfree  hello i have a problem related to jfree chart, i want to display combination of a stacked area chart and line chart in one iframe
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
java.lang.String.valueOf(double dnum)
The valueof(double dnum), is the Java String Class method, which creats and holds the double value in String. And the "dnum" converts the double value to String. See the example below... a simple example of valueOf(double dnum) method
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
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
ModuleNotFoundError: No module named 'XY'
ModuleNotFoundError: No module named 'XY'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'XY' How to remove the ModuleNotFoundError: No module named 'XY' error
surface chart - Java3D
surface chart  i have to make a surface chart of a piece of land with data given for each point in the xy plane....the chart should be such that the areas with different data range should show up in different colour. seriously
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
Candle Stick Chart Example using JFreeChart
to create box and whisker chart for given values. It takes title, domain axis label... Candle Stick Chart Example using JFreeChart... a candle stick chart using JFreeChart. Code of the chart given below shows
Version of axis>axis dependency
List of Version of axis>axis 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
i want to show timeline chart for three year in chart..
i want to show timeline chart for three year in chart..  I am using Jfree chart library to display chart in web pages. i want to show three year data in chart in 3 lines for three year in same chart. i am able to show
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
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
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
Double To Int Without TypeCasting
void main(String[] args) { double d=25.5; int num=new Double(d).intValue(); System.out.println(num...Double To Int Without TypeCasting  How to convert Double to Int
ModuleNotFoundError: No module named 'dataset-xy'
ModuleNotFoundError: No module named 'dataset-xy'  Hi, My Python... 'dataset-xy' How to remove the ModuleNotFoundError: No module named 'dataset-xy' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'trainer-xy'
ModuleNotFoundError: No module named 'trainer-xy'  Hi, My Python... 'trainer-xy' How to remove the ModuleNotFoundError: No module named 'trainer-xy' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'xy-art'
ModuleNotFoundError: No module named 'xy-art'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'xy-art' How to remove the ModuleNotFoundError: No module named 'xy-art'
ModuleNotFoundError: No module named 'xy-bot'
ModuleNotFoundError: No module named 'xy-bot'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'xy-bot' How to remove the ModuleNotFoundError: No module named 'xy-bot'
ModuleNotFoundError: No module named 'xy-box'
ModuleNotFoundError: No module named 'xy-box'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'xy-box' How to remove the ModuleNotFoundError: No module named 'xy-box'
ModuleNotFoundError: No module named 'xy-brain'
ModuleNotFoundError: No module named 'xy-brain'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'xy-brain' How to remove the ModuleNotFoundError: No module named 'xy-brain
ModuleNotFoundError: No module named 'xy-carbrand'
ModuleNotFoundError: No module named 'xy-carbrand'  Hi, My Python... 'xy-carbrand' How to remove the ModuleNotFoundError: No module named 'xy... you have to install padas library. You can install xy-carbrand python
ModuleNotFoundError: No module named 'xy-carlimit'
ModuleNotFoundError: No module named 'xy-carlimit'  Hi, My Python... 'xy-carlimit' How to remove the ModuleNotFoundError: No module named 'xy... you have to install padas library. You can install xy-carlimit python
ModuleNotFoundError: No module named 'xy-cidian'
ModuleNotFoundError: No module named 'xy-cidian'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'xy-cidian' How to remove the ModuleNotFoundError: No module named 'xy
ModuleNotFoundError: No module named 'xy-cities'
ModuleNotFoundError: No module named 'xy-cities'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'xy-cities' How to remove the ModuleNotFoundError: No module named 'xy
ModuleNotFoundError: No module named 'xy-citys'
ModuleNotFoundError: No module named 'xy-citys'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'xy-citys' How to remove the ModuleNotFoundError: No module named 'xy-citys
ModuleNotFoundError: No module named 'xy-art'
ModuleNotFoundError: No module named 'xy-art'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'xy-art' How to remove the ModuleNotFoundError: No module named 'xy-art'
ModuleNotFoundError: No module named 'xy-bot'
ModuleNotFoundError: No module named 'xy-bot'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'xy-bot' How to remove the ModuleNotFoundError: No module named 'xy-bot'

Ads