Skip to content

Instantly share code, notes, and snippets.

@mcarrolle
Last active August 29, 2015 14:10
Show Gist options
  • Save mcarrolle/3c50ddac5ac508000121 to your computer and use it in GitHub Desktop.
Save mcarrolle/3c50ddac5ac508000121 to your computer and use it in GitHub Desktop.
public class ZoomWithMinMaxOptions extends Options {
private static final long serialVersionUID = 1L;
@SuppressWarnings("serial")
public ZoomWithMinMaxOptions() {
ChartOptions chartOptions = new ChartOptions();
chartOptions.setType(SeriesType.LINE);
chartOptions.setMarginRight(130);
chartOptions.setMarginBottom(25);
chartOptions.setZoomType(ZoomType.XY);
setChartOptions(chartOptions);
Title title = new Title("Monthly Average Temperature");
title.setX(-20);
setTitle(title);
Title subTitle = new Title("Source: WorldClimate.com");
subTitle.setX(-20);
setSubtitle(subTitle);
Axis xAxis = new Axis();
xAxis.setCategories(Arrays.asList(new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }));
setxAxis(xAxis);
PlotLine plotLines = new PlotLine();
plotLines.setValue(0f);
plotLines.setWidth(1);
plotLines.setColor(new HexColor("#999999"));
Axis yAxis = new Axis();
yAxis.setTitle(new Title("Temperature (°C)"));
yAxis.setPlotLines(Collections.singletonList(plotLines));
// Set min max
yAxis.setMax(85);
yAxis.setMin(-40);
setyAxis(yAxis);
Legend legend = new Legend();
legend.setLayout(LegendLayout.VERTICAL);
legend.setAlign(HorizontalAlignment.RIGHT);
legend.setVerticalAlign(VerticalAlignment.TOP);
legend.setX(-10);
legend.setY(100);
legend.setBorderWidth(0);
setLegend(legend);
Series<Number> series2 = new SimpleSeries();
series2.setName("Serie1");
series2.setData(Arrays.asList(new Number[] { 20.5, 22.2, 20.1, 20.1, 20.1, 20.2, 20.3 }));
addSeries(series2);
Series<Number> series3 = new SimpleSeries();
series3.setName("Serie2");
series3.setData(Arrays.asList(new Number[] { 20.3, 20.1, 20.1, 20.1, 20.1, 20.1, 20.2 }));
addSeries(series3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment