I struggle to change the date format displayed on a category axis on a serial chart. They are printed as YYYY-MM-DD MM:SS, and I would like them to be DD-MMM (e.g “02-Sep”)
I’ve tried the following in the screen controller with no effect.
Currently, your chart doesn’t know that the category axis values are dates. You need to provide the following fixes:
Set type for an item property: <chart:property name="date" value="2017-09-01 00:00" type="date"/>
Sort items by dates, as charts don’t do it by themselves (currently 09-02 goes before 09-01).
Make a chart date based by adding byDate="true" to a chart root element: <chart:serialChart byDate="true" ...
Additionally, you can define periods date formats either programmatically (as you tried before) or in XML using the nested dateFormats element of categoryAxis.
Note: Steps 1 and 3 are necessary only for manual data adding. While using a datasource they added automatically.
The problem is incorrect data date format you set (chart.setDataDateFormat("D-MMM");), which is used for dates parsing. By default dates are serialized as yyyy-MM-dd HH:mm:ss:S, so you don’t need to change this setting.
The number in the format string is there to help me understand which format the chart is selecting. No warning, no error, which makes difficult to understand what’s wrong.
Would you mind edit attached project and make it display ‘01-09-18’ on the category axis ?
Because you don’t define a datasource you need to make a chart date based by adding byDate="true" to a chart root element: <chart:serialChart byDate="true" .... So, after definig the byDate="true" attribute, your demo project wors as expected.
Thanks Gleb, it works. As my plan is to generate graphs, I used the programmatic version CategoryAxis.setParseDates(true)
Interesting thing is that this demo project reveals that for first day of month, the date format is not the DAYS (number 7) one but the MONTHS (number 8) one. Same for 1/1 of the year, YEARS format (number 9) will be used. Something to know.