Chart X axis date format

Is it possible to set a date format for X axis, if I use java.util.Date as a source item for X axis data?

I have a code:

        BeanItemContainer<ChartDataRow> cnt = new BeanItemContainer<ChartDataRow>(ChartDataRow.class);

        ContainerDataSeries cds = new ContainerDataSeries(cnt);

After adding the datasource to chart, the chart shows X axis categories as numeric value of Date, not as dates.

In documentation I’ve found that you can set X axis categories manually by defining custom values for the axis. But in this case setting axis min/max values is not working.

What is a possible solution to show dates on X axis as dates, e.g. ‘22 Jul 2014’ and be able to set X axis min and max values?

What I’ve found is settings xaxis type:


But how can I change the format of date showing on axis? Is it possible to display the date in tooltip as well?

Hi Mark,

Did you get a solution for this issue ? I am also facing the same.

Unfortunately, no solution was found.

Hello, I think this should work for 22 Jul 2014 format configuration.getxAxis().getDateTimeLabelFormats().setDay("%e %b %Y"); The format is based on PHP strftime function, the info about it you can get

If you want to change a format not for labels, but for a tooltip you should do the following:

configuration.getTooltip().setXDateFormat("%d.%m. %Y %H:%M");

The example can be seen in

Thank You Dmitrii,
I tried the code you have shared. The following helped me to address my issue in a better way.

    tooltip.setFormatter("function()  { var d = new Date(this.x);"
                                + "return " +
                            "'<strong>Repeat Visits :</strong> '+ this.y +'<br/>" +
                            "<strong>Last Visit :</strong> '+ d.toDateString(); " +

[/code]X Axis

You are welcome. Using formatter, is also an option, especially if you want a bit more customisation.