I have created a chart like so:
Main code used for adding and/or updating information:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd H:mm:ss");
Date date = simpleDateFormat.parse(dateAsStringToParse);
Second second = new Second(date);
myInfo.getSeries().addOrUpdate(second, maxValue); // maxValue is an Integer
And for creation of actual chart:
final XYDataset dataset = new TimeSeriesCollection(myInfo.getSeries());
JFreeChart timechart = ChartFactory.createTimeSeriesChart(myInfo.getName()
+ " HPS", "", "HPS", dataset, false, false, false);
I would like to simply add an horizontal line (parallel to X (time) axis) at a constant value, let's say 10,000. So the graph will look something like so:
What would be the easiest (most correct) way to achieve this with my code?
It looks like you want an
XYLineAnnotation
, but the coordinates for aTimeSeries
may be troublesome. Starting fromTimeSeriesChartDemo1
, I made the following changes to get the chart shown.First, we need the
x
value for the first and lastRegularTimePeriod
in theTimeSeries
.Then, the constant
y
value is easy; I chose 140.Alternatively, you can derive a value from your
TimeSeries
, for example.Finally, we construct the annotation and add it to the plot.