Timeseries chart and date display

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
axel
Posts: 21
Joined: Fri Aug 10, 2007 12:37 pm

Timeseries chart and date display

Post by axel » Sun Aug 26, 2007 8:32 pm

Hi,

I have a small point that I cannot solve even if it seems very simple..

In a timeseries plot (XYplot), I would like to display just the year of dates: for example : 2005 - 2006 - 2007
But what I get is the following format : mmm-yyyy : for example janv.-2005

The code I wrote is the following

- I fill in my dataset as follows

Code: Select all

dataSeries.add(new Year(data.getInt(1)),data.getInt(2));
- then I create the chart like this:

Code: Select all

SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, sdf, NumberFormat.getInstance());
TimeSeriesURLGenerator urlg = new TimeSeriesURLGenerator(sdf, "drilldowntochart", "series", "variableSql");

ValueAxis timeAxis = new DateAxis("");
NumberAxis valueAxis = new NumberAxis("");
StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES,ttg, urlg);
renderer.setShapesFilled(true);
XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, renderer);
Where could be the mistake ?

Many thanks in advance for your help !

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Sun Aug 26, 2007 9:02 pm

Code: Select all

timeaxis.setTickUnit(new DateTickUnit(DateTickUnit.YEAR, 1, DateTickUnit.MONTH, 1, sdf));

axel
Posts: 21
Joined: Fri Aug 10, 2007 12:37 pm

Post by axel » Mon Aug 27, 2007 1:40 pm

Thank you so much !
This is indeed the solution !

sutcha
Posts: 3
Joined: Thu Sep 13, 2007 11:28 am

Post by sutcha » Thu Sep 13, 2007 11:38 am

Code: Select all

JFreeChart chart = ChartFactory.createXYStepChart(
                title,
                xAxisLabel, yAxisLabel,
                dataset,
                PlotOrientation.VERTICAL,
                true,   // legend
                true,   // tooltips
                false   // urls
            );

           
            chart.setBackgroundPaint(null);
            final XYPlot plot = chart.getXYPlot();
            plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.5f));
            plot.getRenderer().setSeriesStroke(1, new BasicStroke(1.5f));
            plot.getRenderer().setSeriesPaint(0, Color.RED);
            plot.getRenderer().setSeriesPaint(1, Color.GREEN);
This is my code of a TimeSeries Chart.
To add items to the series I need to choose the period. So my problem is: If the period is long enough (3 years) I get "MM-YYYY". But if I choose a short period of a few days I get the time only (eg. 12:53:44). So I can't see which day is mentioned.
I may have values for some days, but not for every day. If I chose a period of 3 days and only 2 values I can only see the time of these values but not the day.

how can I solve this problem? I hope you understand my problem ;) it's pretty hard to explain with my bad english.

Locked