Search code examples
javajfreechartcategoriesbar-chart

JFreeChart with time range axis


Have set with data, where object represent service with min time, max time, avg time and name of service. Need to show this set by category bar chart, where category is name of service. But main problem in: How to make range axis in this chart to show time like (... hourse ... min)?


Solution

  • You can't mix DateAxis (a specialization of ValueAxis) with CategoryAxis. If you want to do something like

    enter image description here

    Your only choice is to define your parent category with the name of the category and then add subcategories with customized labels in order to show formatted dates or whatever you want.

    If you want to write dates use this ( http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) to format the string

    See the example here:

    https://code.google.com/p/swing-ui-hxzon/source/browse/trunk/jfreechart/org/jfree/chart/demo/SubCategoryAxisDemo1.java?spec=svn67&r=67