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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Frank Kofoed Myhre
Making XY line chart with string and double axis
2 Answer(s)      2 years and 9 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


Advertisement
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Message Context in AXIS
Message Context in AXIS  Is there any method in Axis classes to het the size of IN and OUT Message Conetext
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
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
Web Services - Apache Axis
Web Services - Apache Axis           Axis stands for Apache's EXtensible Interaction System. Axis is one of the most popular SOAP engine that is used to construct SOAP
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
Jfree chart problem - Swing AWT
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 to display hybrid graph (Stacked Area and Line ).combination of stacked area chart and Line chart in one
How To Read String From Command Line In Java
How To Read String From Command Line In Java In this section we will discuss about how string can be read through the command line. In Java command line argument is entered when an application is invoking. This command line argument
Advertisements
 

 

 

DMCA.com