0

I'm developing a charting application and I'm using jFreeChart. I'm using a LineChart and a CategoryDataset.

I need to display a LineChart where in the Y axis (RangeAxis) there will be displayed number values and on the X axis (CategoryAxis) there will be displayed dates (yyyy/MM/dd hh:mm:ss) although in String format.

My question is if there is a way to display only certain dates on the CategoryAxis (X axis) althoug keeping all the pair (yyyy/MM/dd hh:mm:ss, Y value) in the series.

Example: the X axis only showing the days (yyyy/MM/dd) of my dataset but on mouseover in the series, the tooltip would stil display the pair (yyyy/MM/dd hh:mm:ss, Y value).

In other words, my CategoryAxis would contain only a subset of points of my series although my series would still contain all the values.

So far I'm limited to the restriction of for each (yyyy/MM/dd hh:mm:ss, Y value) pair displayed I need to have a correspondence (yyyy/MM/dd hh:mm:ss) on my X axis, which makes it unreadable as it is full of points and labels.

Don't know if I made myself clear and specific on my question, thanks in advance.

Ivo
  • 450
  • 3
  • 18

1 Answers1

0

Since you have dates on your x axis, I think you should use a DateAxis instead of your CategoryAxis, and use an XYPlot.

As seen in the answer to a similar question, you can use DateAxis#setTickUnit(DateTickUnit unit) to set the unit type to DateTickUnitType.DAY.

Community
  • 1
  • 1
Jan Eglinger
  • 3,995
  • 1
  • 25
  • 51
  • Well, this approach will only display the yyyy/MM/dd Date values, which means that I will lose (as losing I mean being able to tooltip them) the remaining (yyyy/MM/dd hh:mm:ss) values on my chart or am I thinking this wrong? – Ivo Jan 28 '13 at 12:54
  • 1
    I just tested with [this nice example](http://stackoverflow.com/a/12481509/1919049), where I changed the line `JFreeChart chart = ChartFactory.createTimeSeriesChart( "Test", "Day", "Value", dataset, false, **true**, false);` to display tooltips, and I can see the date including time on mouseover. Maybe you can post a small code example with your data to illustrate the issue? – Jan Eglinger Jan 28 '13 at 13:53
  • @Jam Eglinger First thanks for your help. I'm aware that the tooltip displays the time, but it only displays the time acording to the pre set `DateTickUnit`. Example, if I use this: `DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1,new SimpleDateFormat("dd.MMM.yy", Locale.UK)));` and if my dataset only contains 4 different days, I will have only tooltip info for those 4 days. Meaning that for each series, I will only have info for 4 points. – Ivo Jan 28 '13 at 15:40