Skip to content

Instantly share code, notes, and snippets.

@johannest
Last active August 29, 2015 14:17
Show Gist options
  • Save johannest/30bce9ad37bb48e2ac56 to your computer and use it in GitHub Desktop.
Save johannest/30bce9ad37bb48e2ac56 to your computer and use it in GitHub Desktop.
public Component getColumnRangeChart() throws ParseException {
Chart chart = new Chart(ChartType.COLUMNRANGE);
Configuration conf = chart.getConfiguration();
conf.getChart().setInverted(true);
YAxis yAxis = conf.getyAxis();
yAxis.setTitle(new Title("Time"));
yAxis.setType(AxisType.DATETIME);
conf.getTooltip().setFormatter("return '<b>' + this.x + '</b> started at <b>' + Highcharts.dateFormat('%H:%M', this.point.low) + '</b> and ended at <b>' + Highcharts.dateFormat('%H:%M', this.point.high) + '</b>';");
DataSeries data = new DataSeries();
data.setName("Ranges");
for (Date[] startEndPair : getRawData()) {
DataSeriesItem item = new DataSeriesItem();
item.setLow(startEndPair[0].getTime());
item.setHigh(startEndPair[1].getTime());
data.add(item);
}
conf.setSeries(data);
return chart;
}
private List<Date[]> getRawData() throws ParseException {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
List<Date[]> dates = new ArrayList<Date[]>();
Date start1 = df.parse("2015-19-03 09:00:00");
Date end1 = df.parse("2015-19-03 09:30:00");
Date start2 = df.parse("2015-19-03 08:15:00");
Date end2 = df.parse("2015-19-03 11:30:00");
dates.add(new Date[]{start1,end1});
dates.add(new Date[]{start2,end2});
return dates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment