Unabl to put all my dates on X-axis for Time Series Demo3.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
chowdary
Posts: 2
Joined: Thu Oct 13, 2005 2:42 pm
Contact:

Unabl to put all my dates on X-axis for Time Series Demo3.

Post by chowdary » Thu Oct 13, 2005 2:53 pm

Hi All,
I am new to this JFreeChart,i am facing a problem with Timeseries.Itried to Modify TimeSeries Demo3.
TimeSeries timeseries = new TimeSeries("Series 1", org.jfree.data.time.Day.class);
timeseries.add(new Day(1,1, 2002), 99.68D);
timeseries.add(new Day(2,1, 2002), 97.89D);
timeseries.add(new Day(3,1, 2002), 99.99D);
timeseries.add(new Day(4,1, 2002), 88.00D);
timeseries.add(new Day(5,1, 2002), 98.00D);
but i am not getting all the 5 dates on X-axis,i am getting only first date.And i am not going to use the regular date intervals .plz help me
thanks in advance
chowdary

Code: Select all

package demo;

import java.awt.Dimension;
import java.text.SimpleDateFormat;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.DateTickUnit;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.data.time.*;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class TimeSeriesDemo3 extends ApplicationFrame
{

    public TimeSeriesDemo3(String s)
    {
        super(s);
        XYDataset xydataset = createDataset();
        JFreeChart jfreechart = createChart(xydataset);
        ChartPanel chartpanel = new ChartPanel(jfreechart);
        chartpanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(chartpanel);
    }

    private static XYDataset createDataset()
    {
        TimeSeries timeseries = new TimeSeries("Series 1", org.jfree.data.time.Day.class);
        timeseries.add(new Day(1,1, 2002), 99.68D);
        timeseries.add(new Day(2,1, 2002), 97.89D);
        timeseries.add(new Day(3,1, 2002), 99.99D);
        timeseries.add(new Day(4,1, 2002), 88.00D);
        timeseries.add(new Day(5,1, 2002), 98.00D);
		TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
        timeseriescollection.addSeries(timeseries);
        return timeseriescollection;
    }

    private static JFreeChart createChart(XYDataset xydataset)
    {
        JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Time Series Demo 3", "Time", "Value", xydataset, true, true, false);
        XYPlot xyplot = jfreechart.getXYPlot();
        DateAxis dateaxis = (DateAxis)xyplot.getDomainAxis();
        dateaxis.setTickUnit(new DateTickUnit(1, 1, new SimpleDateFormat("MMM-yyyy")));
        dateaxis.setVerticalTickLabels(true);
        StandardXYItemRenderer standardxyitemrenderer = (StandardXYItemRenderer)xyplot.getRenderer();
        standardxyitemrenderer.setPlotShapes(true);
        standardxyitemrenderer.setSeriesShapesFilled(0, Boolean.TRUE);
        standardxyitemrenderer.setSeriesShapesFilled(1, Boolean.FALSE);
        return jfreechart;
    }

    public static JPanel createDemoPanel()
    {
        JFreeChart jfreechart = createChart(createDataset());
        return new ChartPanel(jfreechart);
    }

    public static String getDemoDescription()
    {
        return "A simple time series chart.";
    }

    public static void main(String args[])
    {
        TimeSeriesDemo3 timeseriesdemo3 = new TimeSeriesDemo3("Time Series Demo 3");
        timeseriesdemo3.pack();
        RefineryUtilities.centerFrameOnScreen(timeseriesdemo3);
        timeseriesdemo3.setVisible(true);
    }
}

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Oct 14, 2005 9:40 am

Check the parameters you are passing to DateTickUnit:

Code: Select all

dateaxis.setTickUnit(new DateTickUnit(1, 1, new SimpleDateFormat("MMM-yyyy")));
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

chowdary
Posts: 2
Joined: Thu Oct 13, 2005 2:42 pm
Contact:

Post by chowdary » Fri Oct 14, 2005 12:13 pm

david ,
i am using the same code.you can see it in my code

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Oct 14, 2005 1:39 pm

Maybe I'll spell it out for you. The code I quoted above sets the tick unit for the axis. You are passing in a new DateTickUnit, initialised with the arguments (1, 1, new SimpleDateFormat("MMM-yyyy")). The first argument is an integer constant that designates the date units, the second is the number of units. Here are the available constants for argument 1:

Code: Select all

    /** A constant for years. */
    public static final int YEAR = 0;

    /** A constant for months. */
    public static final int MONTH = 1;

    /** A constant for days. */
    public static final int DAY = 2;

    /** A constant for hours. */
    public static final int HOUR = 3;

    /** A constant for minutes. */
    public static final int MINUTE = 4;

    /** A constant for seconds. */
    public static final int SECOND = 5;

    /** A constant for milliseconds. */
    public static final int MILLISECOND = 6;
With that information, can you see the problem? Please don't say no.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

ponic
Posts: 28
Joined: Thu Aug 04, 2005 7:32 pm

Post by ponic » Wed Oct 19, 2005 12:22 pm

Is it possbile to change the size of the X-axis values, because the values I am getting from database is little lengthy than the normal, so everything is not getting displayed. I do not want to change the size of the graph.

Thanks

Locked