Time Series Chart - Date Axis Question

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
Psyala
Posts: 1
Joined: Tue Mar 10, 2020 12:35 pm
antibot: No, of course not.

Time Series Chart - Date Axis Question

Post by Psyala » Fri Mar 13, 2020 11:59 am

Hi there!

I have created a TimeSeriesChart which display 2 days worth of data at 30 minute granularity.

I would like the X-Axis to tick interval every 1 hour (which works).

However, because the data spans multiple days you can potentially see repeating times.
Would it be possible that when the time is "00:00" - also display the date ie "13-MAR 00:00".

My current code:

Code: Select all

        //Chart Settings
        jFreeChart = ChartFactory.createTimeSeriesChart("", "", "Value", dataSet, false, true, false);
        jFreeChart.setBackgroundPaint(Color.WHITe);

        //Plot Settings
        plot = jFreeChart.getXYPlot();
        plot.setOrientation(PlotOrientation.VERTICAL);
        plot.setBackgroundPaint(Color.BLUE);
        plot.setDomainGridlinePaint(Color.BLACK);
        plot.setRangeGridlinePaint(Color.BLACK);
        plot.setAxisOffset(new RectangleInsets(5, 0, 0, 5));
        renderer = new XYLineAndShapeRenderer(true, true);
        plot.setRenderer(renderer);

        //Date Axis Settings
        domainAxis = (DateAxis) plot.getDomainAxis();
        plot.setDomainAxis(domainAxis);
        domainAxis.setLowerMargin(0.01);
        domainAxis.setUpperMargin(0.01);
        domainAxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1, new SimpleDateFormat("HH:00")), true, true);
        domainAxis.setTickMarkPosition(DateTickMarkPosition.START);
Example of desired output:
https://imgur.com/a/QHnPR2z

Thanks in advance!

John Matthews
Posts: 488
Joined: Wed Sep 12, 2007 3:18 pm

Re: Time Series Chart - Date Axis Question

Post by John Matthews » Wed Mar 18, 2020 12:15 am

One alternative: add a second domain axis with a different date format.

Post Reply